Improved rendering of the some formats. Shebang processing is fixed #39

master
Иванов Денис 3 years ago
parent cdd626823a
commit fbb42da924

@ -366,9 +366,11 @@ class Format:
if check_shebang: if check_shebang:
# Удаление #! # Удаление #!
print("FIND SHEBANG")
shebang_regex = re.compile(self.SHEBANG_PATTERN) shebang_regex = re.compile(self.SHEBANG_PATTERN)
shebang_result = shebang_regex.search(input_text) shebang_result = shebang_regex.search(input_text)
if shebang_result is not None: if shebang_result is not None:
print("SHEBANG WAS FOUND")
shebang = shebang_result.groupdict()['shebang'] shebang = shebang_result.groupdict()['shebang']
input_text = shebang_regex.sub("", input_text) input_text = shebang_regex.sub("", input_text)
else: else:

@ -20,17 +20,12 @@ class RawFormat(Format):
self.comment_symbol = parameters.comment or "" self.comment_symbol = parameters.comment or ""
self._before = join_before self._before = join_before
if add_header and not ignore_comments: self.header, self._document_text, self.shebang =\
self.header, self._document_text, self.shebang =\ self._get_header_and_document_text(
self._get_header_and_document_text( document_text,
document_text, template_path,
template_path, already_changed=already_changed,
already_changed=already_changed, check_shebang=True)
check_shebang=True)
else:
self.header = ''
self.shebang = ''
self._document_text = document_text
@property @property
def document_text(self): def document_text(self):
@ -52,6 +47,8 @@ class RawFormat(Format):
self._document_text = '{0}{1}{2}'.format( self._document_text = '{0}{1}{2}'.format(
self._document_text, sep, self._document_text, sep,
template._document_text) template._document_text)
if template.shebang:
self.shebang = template.shebang
def __bool__(self): def __bool__(self):
return bool(self.document_text.strip()) return bool(self.document_text.strip())

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

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

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

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

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

@ -186,11 +186,8 @@ rc_cgroup_memory_use_hierarchy="YES"
# For example, you would use this to set the maximum memory and maximum # For example, you would use this to set the maximum memory and maximum
# number of pids for a service. # number of pids for a service.
rc_cgroup_settings="10485760" rc_cgroup_settings="10485760"
instance="openldap${SVCNAME#slapd}" instance="openldap${SVCNAME#slapd}"
rc_cgroup_cleanup="NO" rc_cgroup_cleanup="NO"
rc_send_sighup="YES" rc_send_sighup="YES"
''' '''
@ -222,7 +219,6 @@ OPTS_CONF="-f /etc/${INSTANCE}/slapd.conf"
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# If you have multiple slapd instances per #376699, this will provide a default config # If you have multiple slapd instances per #376699, this will provide a default config
rc_interactive="NO" rc_interactive="NO"
INSTANCE="openldap${SVCNAME#slapd}" INSTANCE="openldap${SVCNAME#slapd}"
''' '''
@ -258,7 +254,6 @@ RC_INTERACTIVE="NO"
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# If you have multiple slapd instances per #376699, this will provide a default config # If you have multiple slapd instances per #376699, this will provide a default config
RC_INTERACTIVE="NO" RC_INTERACTIVE="NO"
INSTANCE="openldap${SVCNAME#slapd}" INSTANCE="openldap${SVCNAME#slapd}"
''' '''
@ -277,6 +272,7 @@ INSTANCE="openldap${SVCNAME#slapd}"
# If you have multiple slapd instances per #376699, this will provide a default config # If you have multiple slapd instances per #376699, this will provide a default config
rc_interactive="NO" rc_interactive="NO"
INSTANCE="openldap${SVCNAME#slapd}" INSTANCE="openldap${SVCNAME#slapd}"
# Comment1 # Comment1
# Comment2 # Comment2
OPTS_CONF="-f /etc/${INSTANCE}/slapd.conf" OPTS_CONF="-f /etc/${INSTANCE}/slapd.conf"
@ -294,7 +290,6 @@ OPTS_CONF="-f /etc/${INSTANCE}/slapd.conf"
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# If you have multiple slapd instances per #376699, this will provide a default config # If you have multiple slapd instances per #376699, this will provide a default config
rc_interactive="NO" rc_interactive="NO"
INSTANCE="openldap${SVCNAME#slapd}" INSTANCE="openldap${SVCNAME#slapd}"
''' '''
@ -316,15 +311,10 @@ new_param=5
NEW_PARAM2=6''' NEW_PARAM2=6'''
result = '''PARAM=1 result = '''PARAM=1
param2=2 param2=2
big_param=3 big_param=3
LOW_PARAM=4 LOW_PARAM=4
new_param=5 new_param=5
NEW_PARAM2=6 NEW_PARAM2=6
''' '''

@ -164,15 +164,10 @@ queue_directory = /var/spool/postfix
#Путь для всех выполняемых программ почтового сервера. #Путь для всех выполняемых программ почтового сервера.
command_directory = /usr/sbin command_directory = /usr/sbin
mynetworks = 10.0.0.0/8, 80.246.243.18, 94.159.1.246, 80.246.245.82, 93.100.239.44 mynetworks = 10.0.0.0/8, 80.246.243.18, 94.159.1.246, 80.246.245.82, 93.100.239.44
relay_recipient_maps = hash:/etc/postfix/valid_recipient_maps relay_recipient_maps = hash:/etc/postfix/valid_recipient_maps
chmod = 0644 chmod = 0644
chown = root:root chown = root:root
mail_owner = postfix mail_owner = postfix
''' '''
@ -207,7 +202,6 @@ tls_random_source = dev:/dev/urandom
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Comment1 # Comment1
parameter_name = /home/divanov/Home parameter_name = /home/divanov/Home
smtp_tls_note_starttls_offer = yes smtp_tls_note_starttls_offer = yes
''' '''
@ -245,7 +239,6 @@ tls_random_source = dev:/dev/urandom
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Comment1 # Comment1
parameter_name = /home/divanov/Home parameter_name = /home/divanov/Home
smtp_tls_note_starttls_offer = yes smtp_tls_note_starttls_offer = yes
''' '''
@ -284,7 +277,6 @@ tls_random_source = dev:/dev/urandom
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Comment1 # Comment1
parameter_name = /home/divanov/Home parameter_name = /home/divanov/Home
smtp_tls_note_starttls_offer = yes smtp_tls_note_starttls_offer = yes
''' '''

@ -151,11 +151,8 @@ port=8200
# specify the user account name or uid to run as # specify the user account name or uid to run as
user=lol user=lol
vm.dirty_ratio=4 vm.dirty_ratio=4
media_dir=PV,/var/calculate/server-data/samba/share media_dir=PV,/var/calculate/server-data/samba/share
net.ipv4.icmp_echo_ignore_broadcasts=1 net.ipv4.icmp_echo_ignore_broadcasts=1
''' '''
@ -183,7 +180,6 @@ other_parameter = yes
# /path/to/template # /path/to/template
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
net.ipv4.ip_forward=0 net.ipv4.ip_forward=0
other_parameter=yes other_parameter=yes
''' '''
@ -214,7 +210,6 @@ other_parameter = yes
# /path/to/template # /path/to/template
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
net.ipv4.ip_forward=0 net.ipv4.ip_forward=0
other_parameter=yes other_parameter=yes
''' '''
@ -246,7 +241,6 @@ other_parameter = yes
# /path/to/template # /path/to/template
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
net.ipv4.ip_forward=0 net.ipv4.ip_forward=0
other_parameter=yes other_parameter=yes
''' '''

@ -242,3 +242,29 @@ exit 0
template_1 = RawFormat(template_text_1, 'path/to/template_1') template_1 = RawFormat(template_text_1, 'path/to/template_1')
original_1.join_template(template_1) original_1.join_template(template_1)
assert original_1.document_text == output assert original_1.document_text == output
def test_make_shebang_great_again(self):
parameters = ParametersContainer({'comment': '#'})
original_text = ''
template_text_1 = '''#!/bin/bash
echo "message"
exit 0'''
output = '''#!/bin/bash
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# path/to/template_1
#-------------------------------------------------------------------------------
echo "message"
exit 0
'''
original_1 = RawFormat(original_text, 'path/to/template_1',
add_header=True,
already_changed=False,
parameters=parameters)
template_1 = RawFormat(template_text_1, 'path/to/template_1')
original_1.join_template(template_1)
assert original_1.document_text == output

@ -257,9 +257,11 @@ class TestParsingMethods:
# comment 2 # comment 2
parameter name = /home/divanov/Home parameter name = /home/divanov/Home
other parameter = yes other parameter = yes
[section name 3] [section name 3]
unspoken parameter = 1 unspoken parameter = 1
unbelievable parameter = Mystical unbelievable parameter = Mystical
[section name 1] [section name 1]
parameter name = /homeless/poorness parameter name = /homeless/poorness
one more parameter = oh no one more parameter = oh no
@ -304,11 +306,13 @@ class TestParsingMethods:
# Comment2 # Comment2
# Comment3 # Comment3
other parameter = yes other parameter = yes
[section name3] [section name3]
#Comment #Comment
another parameter = 1 another parameter = 1
# Comment # Comment
unspoken parameter = 1 unspoken parameter = 1
[section name1] [section name1]
parameter name = /homeless/poorness parameter name = /homeless/poorness
one more parameter = oh no one more parameter = oh no
@ -358,11 +362,13 @@ class TestParsingMethods:
# Comment2 # Comment2
# Comment3 # Comment3
other parameter = yes other parameter = yes
[section name3] [section name3]
#Comment #Comment
another parameter = 1 another parameter = 1
# Comment # Comment
unspoken parameter = 1 unspoken parameter = 1
[section name1] [section name1]
parameter name = /homeless/poorness parameter name = /homeless/poorness
one more parameter = oh no one more parameter = oh no
@ -413,11 +419,13 @@ class TestParsingMethods:
# Comment2 # Comment2
# Comment3 # Comment3
other parameter = yes other parameter = yes
[section name3] [section name3]
#Comment #Comment
another parameter = 1 another parameter = 1
# Comment # Comment
unspoken parameter = 1 unspoken parameter = 1
[section name1] [section name1]
parameter name = /homeless/poorness parameter name = /homeless/poorness
one more parameter = oh no one more parameter = oh no

@ -28,9 +28,6 @@ rc_cgroup_cleanup="NO"
# If this is yes, we will send sighup to the processes in the cgroup # If this is yes, we will send sighup to the processes in the cgroup
# immediately after stopsig and sigcont. # immediately after stopsig and sigcont.
rc_send_sighup="YES" rc_send_sighup="YES"
clock="Any Clock Type" clock="Any Clock Type"
clock_systohc="YES" clock_systohc="YES"
rc_timeout_stopsec="90" rc_timeout_stopsec="90"

@ -24,17 +24,10 @@ mynetworks = 10.0.0.0/8, 80.246.243.18, 95.213.228.194, 94.159.1.246, 109.167.15
#по умолчанию: посылать в Internet напрямую #по умолчанию: посылать в Internet напрямую
#relayhost = [mail.$mydomain] #relayhost = [mail.$mydomain]
relay_domains = lists.calculate-linux.org, and something above relay_domains = lists.calculate-linux.org, and something above
relay_recipient_maps = hash:/etc/postfix/valid_recipient_maps relay_recipient_maps = hash:/etc/postfix/valid_recipient_maps
chmod = 0644 chmod = 0644
chown = root:root chown = root:root
mail_owner = postfix mail_owner = postfix
recipient_maps = ldap:/etc/postfix/ldap-recipient.cf, ldap:/etc/postfix/ldap-recipient-gr.cf recipient_maps = ldap:/etc/postfix/ldap-recipient.cf, ldap:/etc/postfix/ldap-recipient-gr.cf
local_recipient_maps = ldap:/etc/postfix/ldap-recipient.cf, ldap:/etc/postfix/ldap-recipient-gr.cf, ldap:/etc/postfix/ldap-recipient-repl.cf 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 unknown_local_recipient_reject_code = 550

@ -7,9 +7,7 @@ user=jmaggard
# You should compile nfsd into the kernel or add it # You should compile nfsd into the kernel or add it
# to modules.autoload for this to work properly # to modules.autoload for this to work properly
vm.dirty_background_ratio=1 vm.dirty_background_ratio=1
vm.dirty_ratio=3 vm.dirty_ratio=3
kernel.unprivileged_userns_clone=0 kernel.unprivileged_userns_clone=0
# this should be a list of file names to check for when searching for album art # this should be a list of file names to check for when searching for album art
@ -22,9 +20,6 @@ inotify=no
# set this to yes to enable support for streaming .jpg and .mp3 files to a TiVo supporting HMO # set this to yes to enable support for streaming .jpg and .mp3 files to a TiVo supporting HMO
enable_tivo=no enable_tivo=no
friendly_name=mike-desktop friendly_name=mike-desktop
media_dir=PV,/var/calculate/server-data/samba/share media_dir=PV,/var/calculate/server-data/samba/share
net.ipv4.icmp_echo_ignore_broadcasts=1 net.ipv4.icmp_echo_ignore_broadcasts=1

@ -13,6 +13,7 @@
force security mode = 0644 force security mode = 0644
create mask = 0644 create mask = 0644
enable privileges = yes enable privileges = yes
#============================== Share Definitions ============================= #============================== Share Definitions =============================
[homes] [homes]
path = /home/user/somewhere path = /home/user/somewhere
@ -20,11 +21,13 @@
valid users = %U valid users = %U
read only = No read only = No
browseable = No browseable = No
# Un-comment the following and create the netlogon directory for Domain Logons # Un-comment the following and create the netlogon directory for Domain Logons
[netlogon] [netlogon]
path = /var/lib/samba/netlogon path = /var/lib/samba/netlogon
guest ok = yes guest ok = yes
share modes = no share modes = no
[tmp] [tmp]
comment = Public Stuff comment = Public Stuff
path = /home/samba path = /home/samba
@ -32,6 +35,7 @@
writable = no writable = no
printable = no printable = no
write list = @staff write list = @staff
[unix] [unix]
path = /home/path path = /home/path
browseable = No browseable = No

Loading…
Cancel
Save