Corrected format templates. fixed #20

master
Иванов Денис 3 years ago
parent 76a49228f0
commit d130e476aa

@ -324,9 +324,10 @@ class Format:
рендеринга документа.'''
file_loader = PackageLoader('calculate.templates.format',
self.TEMPLATES_DIRECTORY)
formats_environment = Environment(loader=file_loader,
trim_blocks=True,
lstrip_blocks=True)
# formats_environment = Environment(loader=file_loader,
# trim_blocks=True,
# lstrip_blocks=True)
formats_environment = Environment(loader=file_loader)
formats_environment.globals.update(zip=zip)
formats_environment.add_extension('jinja2.ext.do')
template = formats_environment.get_template(self.FORMAT)
@ -368,8 +369,6 @@ class Format:
shebang_regex = re.compile(self.SHEBANG_PATTERN)
shebang_result = shebang_regex.search(input_text)
if shebang_result is not None:
print("string:", shebang_result.string)
print("groupdict:", shebang_result.groupdict())
shebang = shebang_result.groupdict()['shebang']
input_text = shebang_regex.sub("", input_text)
else:

@ -1,27 +1,25 @@
{% for item_name, item_value in document_dictionary.items() recursive %}
{% if item_name != '#' %}
{% if item_value is mapping %}
{% if not loop.first %}
{% endif %}
{% if '#' in item_value %}
{% for comment in item_value['#'] %}
{% for item_name, item_value in document_dictionary.items() recursive -%}
{% if item_name != '#' -%}
{% if item_value is mapping -%}
{{ '' if loop.first else '\n' -}}
{% if '#' in item_value -%}
{% for comment in item_value['#'] -%}
{{ comment }}
{% endfor %}
{% endif %}
{% if item_name[1] == 'inet' %}
{% endfor -%}
{% endif -%}
{% if item_name[1] == 'inet' -%}
{{ item_name[0] + item_name[1:] | join(' ') }}
{%- for keyword in item_value %}
{%- if keyword != '#' %} {{ keyword[1] }} { {{ item_value[keyword] | join('; ')}}; }{% endif %}{% endfor %};
{% else %}
{%- for keyword in item_value -%}
{%- if keyword != '#' %} {{ keyword[1] }} { {{ item_value[keyword] | join('; ')}}; }{% endif %}{% endfor -%};
{% else -%}
{{ item_name[0] + item_name[1:] | join(' ') }} {
{{ loop(item_value.items()) | indent}}};
{% endif %}
{% else %}
{% for comment in item_value[:-1] %}
{% endif -%}
{% else -%}
{% for comment in item_value[:-1] -%}
{{ comment }}
{% endfor %}
{% endfor -%}
{{ item_name[0] + item_name[1:] | join(' ') }}{% if not item_value[-1] == '' %} {{ item_value[-1] }}{% endif%};
{% endif %}
{% endif %}
{% endfor %}
{% endif -%}
{% endif -%}
{% endfor -%}

@ -1,17 +1,17 @@
{% for section_name in document_dictionary.keys() %}
{% if '#' in document_dictionary[section_name].keys() %}
{% for comment in document_dictionary[section_name]['#'] %}
{% for section_name in document_dictionary.keys() -%}
{{ '' if loop.first else '\n' -}}
{% if '#' in document_dictionary[section_name].keys() -%}
{% for comment in document_dictionary[section_name]['#'] -%}
{{ comment }}
{% endfor %}
{% endif %}
{% endfor -%}
{% endif -%}
[{{ section_name | join('') }}]
{% for parameter_name in document_dictionary[section_name].keys() %}
{% if parameter_name != '#' %}
{% for comment in document_dictionary[section_name][parameter_name][:-1]%}
{% for parameter_name in document_dictionary[section_name].keys() -%}
{% if parameter_name != '#' -%}
{% for comment in document_dictionary[section_name][parameter_name][:-1] -%}
{{ comment }}
{% endfor %}
{% endfor -%}
{{ parameter_name | join('') }}={{ document_dictionary[section_name][parameter_name][-1] }}
{% endif %}
{% endfor %}
{% endfor %}
{% endif -%}
{% endfor -%}
{% endfor -%}

@ -1,34 +1,28 @@
{% for item_name, item_value in document_dictionary.items() recursive %}
{% if item_name != '#' and item_name[1] != '!include' %}
{% if item_value is mapping %}
{% if '#' in item_value %}
{% for comment in item_value['#'] %}
{% for item_name, item_value in document_dictionary.items() recursive -%}
{% if item_name != '#' and item_name[1] != '!include' -%}
{% if item_value is mapping -%}
{% if '#' in item_value -%}
{% for comment in item_value['#'] -%}
{{ comment }}
{% endfor %}
{% endif %}
{% endfor -%}
{% endif -%}
{{ item_name[0] + item_name[1:] | join(' ') }} {
{{ loop(item_value.items()) | indent}}}
{% else %}
{% for comment in item_value[:-1] %}
{% else -%}
{% for comment in item_value[:-1] -%}
{{ comment }}
{% endfor %}
{% endfor -%}
{{ item_name[0] + item_name[1:] | join(' ') }}{%- if not item_value[-1] == '' %} = {{ item_value[-1] }}
{% else %}
{%- if not loop.last%}
{% endif %}
{% endif %}
{% endif %}
{% if not loop.last%}
{% endif %}
{% endif %}
{% endfor %}
{% for item_name in document_dictionary.keys() %}
{% if item_name[1] == '!include' %}
{% else -%}
{{ '' if loop.last else '\n' -}}
{% endif -%}
{% endif -%}
{{ '' if loop.last else '\n' -}}
{% endif -%}
{% endfor -%}
{% for item_name in document_dictionary.keys() -%}
{% if item_name[1] == '!include' -%}
{{ item_name[0] + item_name[1:] | join(' ') }}
{% if not loop.last%}
{% endif %}
{% endif %}
{% endfor %}
{{ '' if loop.last else '\n' -}}
{% endif -%}
{% endfor -%}

@ -1,17 +1,17 @@
{% for section_name in document_dictionary.keys() %}
{% if '#' in document_dictionary[section_name].keys() %}
{% for comment in document_dictionary[section_name]['#'] %}
{% for section_name, section in document_dictionary.items() -%}
{{ '' if loop.first else '\n' -}}
{% if '#' in section.keys() -%}
{% for comment in section['#'] -%}
{{ comment }}
{% endfor %}
{% endif %}
{% endfor -%}
{% endif -%}
[{{ section_name[0] + section_name[1:] | join('][') }}]
{% for parameter_name in document_dictionary[section_name].keys() %}
{% if parameter_name != '#' %}
{% for comment in document_dictionary[section_name][parameter_name][:-1]%}
{% for parameter_name, value in section.items() -%}
{% if parameter_name != '#' -%}
{% for comment in value[:-1] -%}
{{ comment }}
{% endfor %}
{{ parameter_name[0] + parameter_name[1] }}={{ document_dictionary[section_name][parameter_name][-1] }}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor -%}
{{ parameter_name[0] + parameter_name[1] }}={{ value[-1] }}
{% endif -%}
{% endfor -%}
{% endfor -%}

@ -1,6 +1,6 @@
{% for parameter_name in document_dictionary.keys() %}
{% for comment in document_dictionary[parameter_name][:-1]%}
{% for parameter_name in document_dictionary.keys() -%}
{% for comment in document_dictionary[parameter_name][:-1] -%}
{{ comment }}
{% endfor %}
{% endfor -%}
{{ parameter_name[0] + parameter_name[1] }}={{ document_dictionary[parameter_name][-1] }}
{% endfor %}
{% endfor -%}

@ -1,59 +1,56 @@
{% for section_type in document_dictionary.keys() %}
{% if '#' in document_dictionary[section_type] %}
{% for comment in document_dictionary[section_type]['#']%}
{% for section_type in document_dictionary.keys() -%}
{{ '' if loop.first else '\n' -}}
{% if '#' in document_dictionary[section_type] -%}
{% for comment in document_dictionary[section_type]['#'] -%}
{{ comment }}
{% endfor %}
{% endif %}
{% if section_type != ('', 'global')%}
{% endfor -%}
{% endif -%}
{% if section_type != ('', 'global') -%}
{{ section_type[0] + section_type[1] }} {{ section_type[2] }}
{% endif %}
{% for directive in document_dictionary[section_type].keys() if directive[1] == 'include' %}
{% for comment in document_dictionary[section_type][directive][:-1] %}
{% endif -%}
{% for directive in document_dictionary[section_type].keys() if directive[1] == 'include' -%}
{% for comment in document_dictionary[section_type][directive][:-1] -%}
{{ comment }}
{% endfor %}
{% endfor -%}
{{ directive[0] + directive[1] }} {{ directive[2] }}
{% endfor %}
{% for directive in document_dictionary[section_type].keys() %}
{% if directive != '#' and directive[1] != 'include' %}
{% set directive_value = document_dictionary[section_type][directive] %}
{% if directive[1] == 'access to' %}
{% set access_values = directive_value.keys()|list %}
{% if '#' in directive_value %}
{% for comment in directive_value['#'] %}
{% endfor -%}
{% for directive in document_dictionary[section_type].keys() -%}
{% if directive != '#' and directive[1] != 'include' -%}
{% set directive_value = document_dictionary[section_type][directive] -%}
{% if directive[1] == 'access to' -%}
{% set access_values = directive_value.keys()|list -%}
{% if '#' in directive_value -%}
{% for comment in directive_value['#'] -%}
{{ comment }}
{% endfor %}
{% set access_values = access_values[1:] %}
{% endif %}
{% if access_values|length == 1 %}
{% endfor -%}
{% set access_values = access_values[1:] -%}
{% endif -%}
{% if access_values|length == 1 -%}
{{ directive[0] + directive[1] }} {{ directive[2] }} by {{ access_values[0][1] }} {{ directive_value[access_values[0]][0] }}
{% else %}
{% else -%}
{{ directive[0] + directive[1] }} {{ directive[2] }}
{% for value in access_values|reverse %}
by {{ value[0] + value[1] }} {{ directive_value[value][0] }}
{% endfor %}
{% endif %}
{% elif directive[1] == 'syncrepl' %}
{% set syncrepl_values = directive_value.keys()|list%}
{% if '#' in directive_value %}
{% for comment in directive_value['#'] %}
{% for value in access_values|reverse -%}
{{ ' by ' + value[0] + value[1] }} {{ directive_value[value][0] }}
{% endfor -%}
{% endif -%}
{% elif directive[1] == 'syncrepl' -%}
{% set syncrepl_values = directive_value.keys()|list -%}
{% if '#' in directive_value -%}
{% for comment in directive_value['#'] -%}
{{ comment }}
{% endfor %}
{% set syncrepl_values = syncrepl_values[1:]%}
{% endif %}
{% endfor -%}
{% set syncrepl_values = syncrepl_values[1:] -%}
{% endif -%}
{{ directive[0] + directive[1] }} {{ directive[2] }}
{% for value in syncrepl_values %}
{{ value[0] + value[1] }}={{ directive_value[value][0] }}
{% endfor %}
{% else %}
{% for comment in directive_value[:-1] %}
{% for value in syncrepl_values -%}
{{ ' ' + value[0] + value[1] }}={{ directive_value[value][0] }}
{% endfor -%}
{% else -%}
{% for comment in directive_value[:-1] -%}
{{ comment }}
{% endfor %}
{{ directive[0] + directive[1:]|join(' ') }}{% if directive_value[-1] != '' %} {{ directive_value[-1] }}
{% else %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor -%}
{{ directive[0] + directive[1:]|join(' ') }}{{ ' ' + directive_value[-1] if directive_value[-1] else '' }}
{% endif -%}
{% endif -%}
{% endfor -%}
{% endfor -%}

@ -1,7 +1,7 @@
{% for parameter_name in document_dictionary.keys() %}
{% for comment in document_dictionary[parameter_name][:-1]%}
{% for parameter_name in document_dictionary.keys() -%}
{% for comment in document_dictionary[parameter_name][:-1] -%}
{{ comment }}
{% endfor %}
{{ parameter_name[0] + parameter_name[1] }}={{ document_dictionary[parameter_name][-1] }}
{% endfor %}
{% endfor -%}
{{ parameter_name[0] + parameter_name[1] }}={{ document_dictionary[parameter_name][-1] -}}
{{ '\n' if loop.last else '\n\n' -}}
{% endfor -%}

@ -1,8 +1,7 @@
{% for parameter_name in document_dictionary.keys() %}
{% for comment in document_dictionary[parameter_name][:-1]%}
{% for parameter_name in document_dictionary.keys() -%}
{% for comment in document_dictionary[parameter_name][:-1] -%}
{{ comment }}
{% endfor %}
{{ parameter_name[0] + parameter_name[1] }} = {{ document_dictionary[parameter_name][-1] }}
{% endfor %}
{% endfor -%}
{{ parameter_name[0] + parameter_name[1] }} = {{ document_dictionary[parameter_name][-1] -}}
{{ '\n' if loop.last else '\n\n' -}}
{% endfor -%}

@ -1,7 +1,7 @@
{% for parameter_name in document_dictionary.keys() %}
{% for comment in document_dictionary[parameter_name][:-1]%}
{% for parameter_name in document_dictionary.keys() -%}
{% for comment in document_dictionary[parameter_name][:-1] -%}
{{ comment }}
{% endfor %}
{{ parameter_name[0] + parameter_name[1] }}={{ document_dictionary[parameter_name][-1] }}
{% endfor %}
{% endfor -%}
{{ parameter_name[0] + parameter_name[1] }}={{ document_dictionary[parameter_name][-1] -}}
{{ '\n' if loop.last else '\n\n' -}}
{% endfor -%}

@ -1,16 +1,16 @@
{% for section_name in document_dictionary.keys() %}
{% if '#' in document_dictionary[section_name].keys() %}
{% for comment in document_dictionary[section_name]['#'] %}
{% for section_name in document_dictionary.keys() -%}
{% if '#' in document_dictionary[section_name].keys() -%}
{% for comment in document_dictionary[section_name]['#'] -%}
{{ comment }}
{% endfor %}
{% endif %}
{% endfor -%}
{% endif -%}
[{{ section_name | join('') }}]
{% for parameter_name in document_dictionary[section_name].keys() %}
{% if parameter_name != '#' %}
{% for comment in document_dictionary[section_name][parameter_name][:-1]%}
{{ comment }}
{% endfor %}
{{ parameter_name | join('') }} = {{ document_dictionary[section_name][parameter_name][-1] }}
{% endif %}
{% endfor %}
{% endfor %}
{% for parameter_name in document_dictionary[section_name].keys() -%}
{% if parameter_name != '#' -%}
{% for comment in document_dictionary[section_name][parameter_name][:-1] -%}
{{ " " + comment }}
{% endfor -%}
{{ " " + parameter_name | join('') }} = {{ document_dictionary[section_name][parameter_name][-1] }}
{% endif -%}
{% endfor -%}
{% endfor -%}

@ -1,8 +1,7 @@
from calculate.variables.datavars import (
Variable,
StringType,
ListType,
Calculate
ListType
)
'''
main:
@ -10,15 +9,6 @@ main:
cl_template_path -> string
'''
class A:
@classmethod
def test(cls):
return "test"
Variable("test", type=StringType, source=Calculate(A.test))
Variable('cl_chroot_path', type=StringType.readonly, source='/')
Variable('cl_root_path', type=StringType.readonly, source='/')

@ -253,7 +253,6 @@ video/mp4=smplayer.desktop;
video/mpeg=smplayer.desktop;
video/quicktime=smplayer.desktop;
video/vnd.mpegurl=smplayer.desktop;
'''
document_1_object = CompizFormat(document_1, '/path/to/template')
@ -305,7 +304,6 @@ application/pdf=evince.desktop;
# Comment1
application/illustrator=zzz-gimp.desktop
application/pdf=evince.desktop;
'''
original_object = CompizFormat(original_text, '/path/to/template',
@ -361,7 +359,6 @@ application/pdf=evince.desktop;
# Comment1
application/illustrator=zzz-gimp.desktop
application/pdf=evince.desktop;
'''
original_object = CompizFormat(original_text, '/path/to/template',
@ -418,7 +415,6 @@ application/pdf=evince.desktop;
# Comment1
application/illustrator=zzz-gimp.desktop
application/pdf=evince.desktop;
'''
original_object = CompizFormat(original_text, '/path/to/template',

@ -268,7 +268,6 @@ pluginWhiteList=shell,bookmarks,locations
[FileDialogSize]
Height 1080=466
Width 1920=747
'''
document_1_object = KDEFormat(document_1, '/path/to/template')
@ -303,7 +302,6 @@ Width 1920=747
#-------------------------------------------------------------------------------
[PlasmaRunnerManager]
pluginWhiteList=shell,bookmarks,locations
'''
original_object = KDEFormat(original_text, '/path/to/template',
@ -341,7 +339,6 @@ Width 1920=747
#-------------------------------------------------------------------------------
[PlasmaRunnerManager]
pluginWhiteList=shell,bookmarks,locations
'''
original_object = KDEFormat(original_text, '/path/to/template',
@ -380,7 +377,6 @@ Width 1920=747
#-------------------------------------------------------------------------------
[PlasmaRunnerManager]
pluginWhiteList=shell,bookmarks,locations
'''
original_object = KDEFormat(original_text, '/path/to/template',
@ -403,7 +399,6 @@ NoShow=true
join_result = '''[Test]
Name[pl]=Przechowalnia certyfikatów i\xa0kluczy
Comment[fr]=Trousseau de clés de GNOME\xa0: composant PKCS#11
'''
original_object = KDEFormat(original_text, '/path/to/template')
@ -425,7 +420,6 @@ NoShow=true
join_result = '''[Test]
Name[pl]=Hello
'''
original_object = KDEFormat(original_text, '/path/to/template')
@ -445,7 +439,6 @@ NoShow=true
join_result = '''[Test]
Name[pl]= Hello
'''
original_object = KDEFormat(original_text, '/path/to/template')

@ -376,6 +376,8 @@ database bdb
'r') as result_file:
result_text = result_file.read()
print('RESULT TEXT:')
print(ldap_original_object.document_text)
assert ldap_original_object.document_text == result_text
def test_if_input_documents_are_an_original_document_without_calculate_header_and_a_template_and_the_add_header_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
@ -409,7 +411,6 @@ modulepath /usr/lib/openldap/openldap
database bdb
checkpoint 1024 5
'''
original_object = LDAPFormat(original_text, '/path/to/template',
@ -453,7 +454,6 @@ modulepath /usr/lib/openldap/openldap
database bdb
checkpoint 1024 5
'''
original_object = LDAPFormat(original_text, '/path/to/template',
@ -498,7 +498,6 @@ modulepath /usr/lib/openldap/openldap
database bdb
checkpoint 1024 5
'''
original_object = LDAPFormat(original_text, '/path/to/template',

@ -192,7 +192,6 @@ instance="openldap${SVCNAME#slapd}"
rc_cgroup_cleanup="NO"
rc_send_sighup="YES"
'''
document_1_object = OpenRCFormat(document_1, '/path/to/template')
@ -225,7 +224,6 @@ OPTS_CONF="-f /etc/${INSTANCE}/slapd.conf"
rc_interactive="NO"
INSTANCE="openldap${SVCNAME#slapd}"
'''
original_object = OpenRCFormat(original_text, '/path/to/template',
@ -262,7 +260,6 @@ RC_INTERACTIVE="NO"
RC_INTERACTIVE="NO"
INSTANCE="openldap${SVCNAME#slapd}"
'''
original_object = OpenRCFormat(original_text, '/path/to/template',
@ -299,7 +296,6 @@ OPTS_CONF="-f /etc/${INSTANCE}/slapd.conf"
rc_interactive="NO"
INSTANCE="openldap${SVCNAME#slapd}"
'''
original_object = OpenRCFormat(original_text, '/path/to/template',
@ -330,7 +326,6 @@ LOW_PARAM=4
new_param=5
NEW_PARAM2=6
'''
original_object = OpenRCFormat(original, '/path/to/template')

@ -174,7 +174,6 @@ chmod = 0644
chown = root:root
mail_owner = postfix
'''
document_1_object = PostfixFormat(document_1, '/path/to/template')
@ -210,7 +209,6 @@ tls_random_source = dev:/dev/urandom
parameter_name = /home/divanov/Home
smtp_tls_note_starttls_offer = yes
'''
original_object = PostfixFormat(original_text, '/path/to/template',
@ -249,7 +247,6 @@ tls_random_source = dev:/dev/urandom
parameter_name = /home/divanov/Home
smtp_tls_note_starttls_offer = yes
'''
original_object = PostfixFormat(original_text, '/path/to/template',
@ -289,7 +286,6 @@ tls_random_source = dev:/dev/urandom
parameter_name = /home/divanov/Home
smtp_tls_note_starttls_offer = yes
'''
original_object = PostfixFormat(original_text, '/path/to/template',

@ -157,7 +157,6 @@ vm.dirty_ratio=4
media_dir=PV,/var/calculate/server-data/samba/share
net.ipv4.icmp_echo_ignore_broadcasts=1
'''
document_1_object = ProcmailFormat(document_1, '/path/to/template')
@ -186,7 +185,6 @@ other_parameter = yes
net.ipv4.ip_forward=0
other_parameter=yes
'''
original_object = ProcmailFormat(original_text, '/path/to/template',
@ -218,7 +216,6 @@ other_parameter = yes
net.ipv4.ip_forward=0
other_parameter=yes
'''
original_object = ProcmailFormat(original_text, '/path/to/template',
@ -251,7 +248,6 @@ other_parameter = yes
net.ipv4.ip_forward=0
other_parameter=yes
'''
original_object = ProcmailFormat(original_text, '/path/to/template',

@ -31,4 +31,3 @@ audio/mpeg=clementine.desktop;
audio/x-flac=clementine.desktop;
audio/x-ms-wma=clementine.desktop;
audio/x-wav=clementine.desktop;

@ -72,4 +72,3 @@ length=674
maxLength=674
minLength=674
thickness=56

@ -64,4 +64,3 @@ updateref ldap://ldapmaster.newexample.com
modulepath /usr/lib/openldap
moduleload accesslog.la
moduleload syncprov.la

@ -34,4 +34,3 @@ clock="Any Clock Type"
clock_systohc="YES"
rc_timeout_stopsec="90"

@ -38,4 +38,3 @@ recipient_maps = ldap:/etc/postfix/ldap-recipient.cf, ldap:/etc/postfix/ldap-rec
local_recipient_maps = ldap:/etc/postfix/ldap-recipient.cf, ldap:/etc/postfix/ldap-recipient-gr.cf, ldap:/etc/postfix/ldap-recipient-repl.cf
unknown_local_recipient_reject_code = 550

@ -28,4 +28,3 @@ friendly_name=mike-desktop
media_dir=PV,/var/calculate/server-data/samba/share
net.ipv4.icmp_echo_ignore_broadcasts=1

Loading…
Cancel
Save