|
|
|
@ -22,6 +22,8 @@ class Format:
|
|
|
|
|
FORMAT = 'none'
|
|
|
|
|
CALCULATE_VERSION = None
|
|
|
|
|
|
|
|
|
|
SHEBANG_PATTERN = r"^(?P<shebang>#!\s*[\w\d\/]+\n)"
|
|
|
|
|
|
|
|
|
|
def __init__(self, processing_methods: List[Callable]):
|
|
|
|
|
self._processing_methods = processing_methods
|
|
|
|
|
self._document_dictionary = OrderedDict()
|
|
|
|
@ -355,23 +357,43 @@ class Format:
|
|
|
|
|
|
|
|
|
|
def _get_header_and_document_text(self, input_text: str,
|
|
|
|
|
template_path: str,
|
|
|
|
|
already_changed: bool = False
|
|
|
|
|
already_changed: bool = False,
|
|
|
|
|
check_shebang: bool = False
|
|
|
|
|
) -> Tuple[str, str]:
|
|
|
|
|
'''Метод для создания заголовка измененного файла и удаления его из
|
|
|
|
|
текста исходного файла.'''
|
|
|
|
|
header_pattern = self._get_header_pattern()
|
|
|
|
|
template_paths = []
|
|
|
|
|
|
|
|
|
|
if check_shebang:
|
|
|
|
|
# Удаление #!
|
|
|
|
|
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:
|
|
|
|
|
shebang = ""
|
|
|
|
|
|
|
|
|
|
header_pattern = self._get_header_pattern()
|
|
|
|
|
header_regex = re.compile(header_pattern)
|
|
|
|
|
parsing_result = header_regex.search(input_text)
|
|
|
|
|
|
|
|
|
|
if already_changed and self.comment_symbol and parsing_result:
|
|
|
|
|
for template in parsing_result.\
|
|
|
|
|
groupdict()['template_paths'].strip().split('\n'):
|
|
|
|
|
if template.startswith(self.comment_symbol):
|
|
|
|
|
template = template[len(self.comment_symbol):]
|
|
|
|
|
template_paths.append(template.strip())
|
|
|
|
|
|
|
|
|
|
template_paths.append(template_path)
|
|
|
|
|
header = self._make_header(template_paths)
|
|
|
|
|
document_text = re.sub(header_pattern, '', input_text)
|
|
|
|
|
|
|
|
|
|
if check_shebang:
|
|
|
|
|
return header, document_text, shebang
|
|
|
|
|
else:
|
|
|
|
|
return header, document_text
|
|
|
|
|
|
|
|
|
|
def _make_header(self, template_paths: list) -> str:
|
|
|
|
|