Adding newline character in raw format was fixed.

master
root 3 years ago
parent aed9be1eee
commit 1ee3326431

@ -2,8 +2,12 @@ from ..variables.loader import Datavars
from ..commands.commands import Command from ..commands.commands import Command
from ..logging import dictLogConfig from ..logging import dictLogConfig
from logging.config import dictConfig from logging.config import dictConfig
from typing import (
Callable,
Optional,
NoReturn
)
from logging import getLogger from logging import getLogger
from typing import Callable
from fastapi import FastAPI from fastapi import FastAPI
from .worker import Worker from .worker import Worker
import importlib import importlib
@ -119,13 +123,13 @@ class Server:
# Обработчики сообщений воркеров. # Обработчики сообщений воркеров.
# Вспомогательные методы. # Вспомогательные методы.
def _add_routes(self, method: Callable, routes: dict) -> None: def _add_routes(self, method: Callable, routes: dict) -> NoReturn:
'''Метод для добавления методов.''' '''Метод для добавления методов.'''
for path, handler in routes.items(): for path, handler in routes.items():
router = method(path) router = method(path)
router(handler) router(handler)
def _make_worker(self, wid: int = None): def _make_worker(self, wid: Optional[int] = None):
'''Метод для создания воркера для команды.''' '''Метод для создания воркера для команды.'''
if wid is not None: if wid is not None:
self._workers[wid] = Worker(wid, self._event_loop) self._workers[wid] = Worker(wid, self._event_loop)

@ -387,6 +387,7 @@ class Format:
template_paths.append(template_path) template_paths.append(template_path)
header = self._make_header(template_paths) header = self._make_header(template_paths)
print(header)
document_text = re.sub(header_pattern, '', input_text) document_text = re.sub(header_pattern, '', input_text)
if check_shebang: if check_shebang:

@ -38,17 +38,19 @@ class RawFormat(Format):
self._document_text) self._document_text)
def join_template(self, template): def join_template(self, template):
sep = ""
if self._before: if self._before:
if (template._document_text
and not template._document_text.endswith("\n")):
sep = "\n"
self._document_text = '{0}{1}{2}'.format( self._document_text = '{0}{1}{2}'.format(
template._document_text, template._document_text, sep,
"" if template._document_text.
endswith("\n") else "\n",
self._document_text) self._document_text)
else: else:
if self._document_text and not self._document_text.endswith("\n"):
sep = "\n"
self._document_text = '{0}{1}{2}'.format( self._document_text = '{0}{1}{2}'.format(
self._document_text, self._document_text, sep,
"" if self._document_text.
endswith("\n") else "\n",
template._document_text) template._document_text)
def __bool__(self): def __bool__(self):

@ -71,7 +71,7 @@ class Process:
self._process = None self._process = None
self._iterator = iter([]) self._iterator = iter([])
# Flags. # Флаги.
self._opened = False self._opened = False
self._is_read = False self._is_read = False
@ -79,12 +79,12 @@ class Process:
self._writable = False self._writable = False
self._readable_errors = False self._readable_errors = False
# I/O handlers. # I/O обработчики.
self.stdin_handler = None self.stdin_handler = None
self.stdout_handler = None self.stdout_handler = None
self.stderr_handler = None self.stderr_handler = None
# Caches. # Кэши.
self._output_cache = '' self._output_cache = ''
self._error_cache = '' self._error_cache = ''

@ -87,10 +87,10 @@ class PackageCreator(type):
class Version: class Version:
'''Класс объектов представляющих значения версий.'''
_suffix_order = {'alpha': 0, 'beta': 1, 'pre': 2, _suffix_order = {'alpha': 0, 'beta': 1, 'pre': 2,
'rc': 3, 'no': 4, 'p': 5} 'rc': 3, 'no': 4, 'p': 5}
'''Класс для работы со значениями версий.'''
def __init__(self, version_value: Union["Version", None, int, def __init__(self, version_value: Union["Version", None, int,
float, str] = None): float, str] = None):
if version_value is None: if version_value is None:

@ -1506,7 +1506,7 @@ class TestDirectoryProcessor:
'/etc/dir_61/._cfg0000_file_0'), '/etc/dir_61/._cfg0000_file_0'),
'r') as new_file: 'r') as new_file:
new_text = new_file.read() new_text = new_file.read()
assert new_text == '\nnew content\n' assert new_text == 'new content\n'
def test_current_template_variable(self): def test_current_template_variable(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH, datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
@ -1518,7 +1518,7 @@ class TestDirectoryProcessor:
'# Processed template files:\n' + '# Processed template files:\n' +
f'# {template_path}\n' + f'# {template_path}\n' +
'#' + '-' * 79 + '#' + '-' * 79 +
f'\n\ntemplate = {template_path}\n') f'\ntemplate = {template_path}\n')
directory_processor = DirectoryProcessor( directory_processor = DirectoryProcessor(
'install', 'install',
datavars_module=datavars, datavars_module=datavars,
@ -1803,7 +1803,7 @@ class TestDirectoryProcessor:
with open(join_paths(CHROOT_PATH, with open(join_paths(CHROOT_PATH,
'/etc/file_23'), 'r') as target_file: '/etc/file_23'), 'r') as target_file:
target_text = target_file.read() target_text = target_file.read()
assert target_text == "joy division -- new dawn fades" assert target_text == "joy division -- new dawn fades\n"
mode = os.stat(join_paths(CHROOT_PATH, '/etc/file_23')).st_mode mode = os.stat(join_paths(CHROOT_PATH, '/etc/file_23')).st_mode
assert int(mode) == 0o100645 assert int(mode) == 0o100645

@ -8,6 +8,7 @@ dir /etc/dir_60
obj /etc/dir_60/file_0 c9a9459e4266ea35a612b90dc3653112 1593525253 obj /etc/dir_60/file_0 c9a9459e4266ea35a612b90dc3653112 1593525253
obj /etc/file_19 3fd436479300b04370b97f4bcfdc90f7 1592574626 obj /etc/file_19 3fd436479300b04370b97f4bcfdc90f7 1592574626
obj /etc/file_20 3fd436479300b04370b97f4bcfdc90f7 1592574626 obj /etc/file_20 3fd436479300b04370b97f4bcfdc90f7 1592574626
obj /etc/file_23 c18d75dcdbe03b64a461dc708b5b1a80 1592574626
dir /etc/dir_76 dir /etc/dir_76
obj /etc/dir_76/file_0 3fd436479300b04370b97f4bcfdc90f7 1592574626 obj /etc/dir_76/file_0 3fd436479300b04370b97f4bcfdc90f7 1592574626
dir /etc/dir_77 dir /etc/dir_77

Loading…
Cancel
Save