|
|
|
@ -1,11 +1,10 @@
|
|
|
|
|
# vim: fileencoding=utf-8
|
|
|
|
|
#
|
|
|
|
|
import os
|
|
|
|
|
from .base_format import Format
|
|
|
|
|
from .base_format import Format, FormatError
|
|
|
|
|
from pyparsing import Literal, Regex, SkipTo, LineEnd, lineno, LineStart
|
|
|
|
|
from calculate.utils.package import PackageAtomParser, Package, PackageNotFound
|
|
|
|
|
from calculate.utils.files import join_paths
|
|
|
|
|
from pprint import pprint
|
|
|
|
|
from glob import iglob
|
|
|
|
|
from fnmatch import fnmatch
|
|
|
|
|
|
|
|
|
@ -24,15 +23,18 @@ class ContentsFormat(Format):
|
|
|
|
|
cls._initialize_parser()
|
|
|
|
|
return super().__new__(cls)
|
|
|
|
|
|
|
|
|
|
def __init__(self, document_text: str,
|
|
|
|
|
template_path,
|
|
|
|
|
ignore_comments=False):
|
|
|
|
|
def __init__(self, template_text: str,
|
|
|
|
|
template_path: str,
|
|
|
|
|
ignore_comments=None):
|
|
|
|
|
self._command_methods = {ADD: self._add_command,
|
|
|
|
|
REMOVE: self._remove_command,
|
|
|
|
|
MOVE: self._move_command}
|
|
|
|
|
self._errors = []
|
|
|
|
|
self._parse_errors = []
|
|
|
|
|
|
|
|
|
|
self._commands = self._parse_template(document_text)
|
|
|
|
|
self._commands = self._parse_template(template_text)
|
|
|
|
|
if self._parse_errors:
|
|
|
|
|
raise FormatError('errors while parsing template:\n{}'.
|
|
|
|
|
format('\n'.join(self._parse_errors)))
|
|
|
|
|
self._template_path = template_path
|
|
|
|
|
self._packages = dict()
|
|
|
|
|
self._atom_parser = None
|
|
|
|
@ -54,8 +56,7 @@ class ContentsFormat(Format):
|
|
|
|
|
command['path'],
|
|
|
|
|
command['lineno'],
|
|
|
|
|
source=source_package)
|
|
|
|
|
pprint(target_package.contents_dictionary)
|
|
|
|
|
self._save_changes()
|
|
|
|
|
return self._save_changes()
|
|
|
|
|
|
|
|
|
|
def _add_command(self, target, glob_path, lineno, source=None):
|
|
|
|
|
# Если файл уже есть в пакете -- ничего не делаем.
|
|
|
|
@ -67,10 +68,8 @@ class ContentsFormat(Format):
|
|
|
|
|
|
|
|
|
|
# Проверяем существование файла.
|
|
|
|
|
if not os.path.exists(file_path):
|
|
|
|
|
error = (f"Format processing error:{lineno}: file "
|
|
|
|
|
f"'{file_path}' does not exist.")
|
|
|
|
|
self._errors.append(error)
|
|
|
|
|
continue
|
|
|
|
|
raise FormatError(f"Format processing error:{lineno}: file "
|
|
|
|
|
f"'{file_path}' does not exist.")
|
|
|
|
|
|
|
|
|
|
# Проверяем, не принадлежит ли файл какому-нибудь другому пакету.
|
|
|
|
|
try:
|
|
|
|
@ -78,11 +77,10 @@ class ContentsFormat(Format):
|
|
|
|
|
except PackageNotFound:
|
|
|
|
|
file_package = None
|
|
|
|
|
if file_package is not None:
|
|
|
|
|
error = (f"Format processing error:{lineno}: can not add file"
|
|
|
|
|
f" '{file_path}' belonging to the package"
|
|
|
|
|
f" {file_package} into the package '{target}'.")
|
|
|
|
|
self._errors.append(error)
|
|
|
|
|
continue
|
|
|
|
|
raise FormatError(f"Format processing error:{lineno}: can not"
|
|
|
|
|
f" add file '{file_path}' belonging to the"
|
|
|
|
|
f" package {file_package} into the package"
|
|
|
|
|
f" '{target}'.")
|
|
|
|
|
|
|
|
|
|
target.add_file(file_path)
|
|
|
|
|
|
|
|
|
@ -128,12 +126,12 @@ class ContentsFormat(Format):
|
|
|
|
|
target.sort_contents_dictionary()
|
|
|
|
|
|
|
|
|
|
def _save_changes(self):
|
|
|
|
|
changed_files = []
|
|
|
|
|
for atom_name, package in self._packages.items():
|
|
|
|
|
print(f"SAVING CHANGES FOR PACKAGE: {package}")
|
|
|
|
|
print('CONTENTS TEXT:')
|
|
|
|
|
print(package.render_contents_file())
|
|
|
|
|
package.write_contents_file()
|
|
|
|
|
changed_files.append(package.contents_file_path)
|
|
|
|
|
self._packages = {}
|
|
|
|
|
return changed_files
|
|
|
|
|
|
|
|
|
|
def _get_package(self, atom_name: str, chroot_path: str) -> Package:
|
|
|
|
|
atom = self._atom_parser.parse_package_parameter(atom_name)
|
|
|
|
@ -154,7 +152,7 @@ class ContentsFormat(Format):
|
|
|
|
|
elif 'error' in parse_result:
|
|
|
|
|
error = (f'Parse Error:{parse_result["lineno"]}:'
|
|
|
|
|
f' {parse_result["error"]}')
|
|
|
|
|
self._errors.append(error)
|
|
|
|
|
self._parse_errors.append(error)
|
|
|
|
|
continue
|
|
|
|
|
yield parse_result
|
|
|
|
|
|
|
|
|
|