Fixed some typing errors.

master
Иванов Денис 3 years ago
parent 5b76fdfcd9
commit 79ee3146e7

@ -32,6 +32,7 @@ class OpenRCFormat(Format):
self._parse_to_delete_line]
super().__init__(processing_methods)
self._ignore_comments = ignore_comments
self._comments_processing = True
@ -52,6 +53,21 @@ class OpenRCFormat(Format):
document_lines = self._get_list_of_logic_lines(document_text)
self._lines_to_dictionary(document_lines)
def join_template(self, template: "OpenRCFormat") -> None:
'''Метод запускающий наложение шаблона.'''
self._document_dictionary = self._correct_register(template)
self._join(self._document_dictionary,
template._document_dictionary,
self._join_before)
print('AFTER JOIN')
self.print_dictionary()
def _correct_register(self, template: "OpenRCFormat") -> dict:
'''Метод для корректировки всех регистров.'''
corrected_dict = OrderedDict()
return self._document_dictionary
@classmethod
def _initialize_parser(cls):
'''Метод для инициализации парсеров.'''
@ -84,7 +100,7 @@ class OpenRCFormat(Format):
parsing_result = self._parameter_line.parseString(line)
key_value = (parsing_result.parameter_name.action,
parsing_result.parameter_name.name.lower())
parsing_result.parameter_name.name)
parameter_value = parsing_result.parameter_value
parameter_value = self._last_comments_list + [parameter_value]
@ -108,7 +124,7 @@ class OpenRCFormat(Format):
return
key_value = (parsing_result.parameter_name.action,
parsing_result.parameter_name.name.lower())
parsing_result.parameter_name.name)
parameter_value = self._last_comments_list
self._last_comments_list = []

@ -53,7 +53,8 @@ class Version:
'rc': 3, 'no': 4, 'p': 5}
'''Класс для работы со значениями версий.'''
def __init__(self, version_value=None):
def __init__(self, version_value: Union["Version", None, int,
float, str] = None):
if version_value is None:
self._string = '-1'
self._value = [-1]
@ -79,7 +80,8 @@ class Version:
self._suffix = value['suffix']
self._revision = value['revision']
def _get_version_value(self, version):
def _get_version_value(self, version: Union["Version", int, float, str]
) -> Union[dict, None]:
'''Вспомогательный метод для получения значения версии, представленного
в виде списка.'''
if isinstance(version, Version):
@ -172,7 +174,7 @@ class Version:
def string(self):
return self._string
def __lt__(self, other):
def __lt__(self, other: "Version") -> bool:
'''Перегрузка x < y.'''
other_version = self._get_version_value(other)
if other_version is None:
@ -194,7 +196,7 @@ class Version:
return self._revision < other_version['revision']
def __le__(self, other: Version) -> bool:
def __le__(self, other: "Version") -> bool:
'''Перегрузка x <= y.'''
other_version = self._get_version_value(other)
if other_version is None:
@ -213,7 +215,7 @@ class Version:
return cmp_res < 0
return self._revision <= other_version['revision']
def __eq__(self, other: Version, ignore_revision: bool = False) -> bool:
def __eq__(self, other: "Version", ignore_revision: bool = False) -> bool:
'''Перегрузка x == y.'''
other_version = self._get_version_value(other)
if other_version is None:
@ -237,15 +239,15 @@ class Version:
else:
return self._revision == other_version['revision']
def __ne__(self, other: Version) -> bool:
def __ne__(self, other: "Version") -> bool:
'''Перегрузка x != y.'''
return not self.__eq__(other)
def __gt__(self, other: Version) -> bool:
def __gt__(self, other: "Version") -> bool:
'''Перегрузка x > y.'''
return not self.__le__(other)
def __ge__(self, other: Version) -> bool:
def __ge__(self, other: "Version") -> bool:
'''Перегрузка x >= y.'''
return not self.__lt__(other)
@ -516,27 +518,6 @@ class PackageAtomParser:
'''Метод для проверки существования пакета. Существование пакета
определяется наличием соответствующего CONTENTS файла.'''
# Используем glob-паттерн для поиска.
if atom_dictionary['version'] is not None:
full_name = atom_dictionary['name'] + '-' +\
str(atom_dictionary['version'])
else:
full_name = atom_dictionary['name']
# if (atom_dictionary['version'] is None or
# (atom_dictionary['condition'] is not None and
# atom_dictionary['condition'] in {'~', '>', '<'})):
# glob_result = glob.glob(
# r'{0}/{1}/{2}-[0-9]*/CONTENTS'.format(
# self.pkg_path,
# atom_dictionary['category'],
# full_name))
# else:
# glob_result = glob.glob(
# r'{0}/{1}/{2}*/CONTENTS'.format(
# self.pkg_path,
# atom_dictionary['category'],
# full_name))
glob_result = glob.glob(r'{0}/{1}/{2}*/CONTENTS'.format(
self.pkg_path,
atom_dictionary['category'],

@ -14,9 +14,9 @@ class TestParsingMethods:
'''
result = OrderedDict({('', 'rc_interactive'): ['"NO"'],
('', 'instance'): ['"openldap${SVCNAME#slapd}"'],
('', 'opts_conf'): ['"-f /etc/${INSTANCE}/slapd.conf"'],
('', 'opts'): ['"${OPTS_CONF} -h \'ldaps:// ldap:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock\'"']})
('', 'INSTANCE'): ['"openldap${SVCNAME#slapd}"'],
('', 'OPTS_CONF'): ['"-f /etc/${INSTANCE}/slapd.conf"'],
('', 'OPTS'): ['"${OPTS_CONF} -h \'ldaps:// ldap:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock\'"']})
openrc_object = OpenRCFormat(document_text, '/path/to/template')
assert openrc_object._document_dictionary == result
@ -35,9 +35,9 @@ class TestParsingMethods:
'''
result = OrderedDict({('', 'rc_interactive'): ['"NO"'],
('', 'instance'): ['"openldap${SVCNAME#slapd}"'],
('', 'opts_conf'): ['"-f /etc/${INSTANCE}/slapd.conf"'],
('', 'opts'): ['"${OPTS_CONF} -h \'ldaps:// ldap:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock\'"']})
('', 'INSTANCE'): ['"openldap${SVCNAME#slapd}"'],
('', 'OPTS_CONF'): ['"-f /etc/${INSTANCE}/slapd.conf"'],
('', 'OPTS'): ['"${OPTS_CONF} -h \'ldaps:// ldap:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock\'"']})
openrc_object = OpenRCFormat(document_text, '/path/to/template')
assert openrc_object._document_dictionary == result
@ -51,9 +51,9 @@ class TestParsingMethods:
'''
result = OrderedDict({('!', 'rc_interactive'): ['"NO"'],
('-', 'instance'): ['"openldap${SVCNAME#slapd}"'],
('', 'opts_conf'): ['"-f /etc/${INSTANCE}/slapd.conf"'],
('!', 'opts'): ['"${OPTS_CONF} -h \'ldaps:// ldap:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock\'"']})
('-', 'INSTANCE'): ['"openldap${SVCNAME#slapd}"'],
('', 'OPTS_CONF'): ['"-f /etc/${INSTANCE}/slapd.conf"'],
('!', 'OPTS'): ['"${OPTS_CONF} -h \'ldaps:// ldap:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock\'"']})
openrc_object = OpenRCFormat(document_text, '/path/to/template')
assert openrc_object._document_dictionary == result
@ -75,13 +75,13 @@ class TestParsingMethods:
result = OrderedDict({('', 'rc_interactive'):
['# If you have multiple slapd instances per #376699, this will provide a default config', '"NO"'],
('', 'instance'):
('', 'INSTANCE'):
['"openldap${SVCNAME#slapd}"'],
('', 'opts_conf'):
('', 'OPTS_CONF'):
['# Comment1',
'# Comment2',
'"-f /etc/${INSTANCE}/slapd.conf"'],
('', 'opts'):
('', 'OPTS'):
['"${OPTS_CONF} -h \'ldaps:// ldap:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock\'"']})
openrc_object = OpenRCFormat(document_text, '/path/to/template')
@ -104,11 +104,11 @@ class TestParsingMethods:
result = OrderedDict({('', 'rc_interactive'):
['"NO"'],
('', 'instance'):
('', 'INSTANCE'):
['"openldap${SVCNAME#slapd}"'],
('', 'opts_conf'):
('', 'OPTS_CONF'):
['"-f /etc/${INSTANCE}/slapd.conf"'],
('', 'opts'):
('', 'OPTS'):
['"${OPTS_CONF} -h \'ldaps:// ldap:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock\'"']})
openrc_object = OpenRCFormat(document_text, '/path/to/template',
@ -123,8 +123,8 @@ class TestParsingMethods:
'''
result = OrderedDict({('!', 'rc_interactive'): ['"NO"'],
('!', 'instance'): [],
('!', 'opts_conf'): []})
('!', 'INSTANCE'): [],
('!', 'OPTS_CONF'): []})
openrc_object = OpenRCFormat(document_text,
'/path/to/template')
@ -224,7 +224,7 @@ OPTS_CONF="-f /etc/${INSTANCE}/slapd.conf"
# If you have multiple slapd instances per #376699, this will provide a default config
rc_interactive="NO"
instance="openldap${SVCNAME#slapd}"
INSTANCE="openldap${SVCNAME#slapd}"
'''
@ -249,6 +249,7 @@ OPTS_CONF="-f /etc/${INSTANCE}/slapd.conf"
'''
template_text = '''
RC_INTERACTIVE="NO"
!OPTS_CONF
'''
@ -258,9 +259,9 @@ OPTS_CONF="-f /etc/${INSTANCE}/slapd.conf"
# /path/to/template
#-------------------------------------------------------------------------------
# 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}"
'''
@ -297,7 +298,7 @@ OPTS_CONF="-f /etc/${INSTANCE}/slapd.conf"
# If you have multiple slapd instances per #376699, this will provide a default config
rc_interactive="NO"
instance="openldap${SVCNAME#slapd}"
INSTANCE="openldap${SVCNAME#slapd}"
'''

Loading…
Cancel
Save