Browse Source

Package search was improved. fixed #74

master
Иванов Денис 1 year ago
parent
commit
c59f6033c9
  1. 2
      calculate/templates/format/base_format.py
  2. 1
      calculate/templates/template_processor.py
  3. 7
      calculate/utils/package.py
  4. 34
      tests/templates/test_directory_processor.py
  5. 1
      tests/templates/testfiles/test_dir_processor_root/etc.backup/file_26
  6. 2
      tests/templates/testfiles/test_dir_processor_root/templates_48/install/dir_66/.calculate_directory
  7. 2
      tests/templates/testfiles/test_dir_processor_root/templates_64/install/.calculate_directory
  8. 2
      tests/templates/testfiles/test_dir_processor_root/templates_64/install/file_26
  9. 2
      tests/templates/testfiles/test_dir_processor_root/var.backup/db/pkg/app-editors/vim-8.2.0360/CONTENTS
  10. 1
      tests/templates/testfiles/test_dir_processor_root/var.backup/db/pkg/app-editors/vim-8.2.0360/SLOT
  11. 0
      tests/templates/testfiles/test_dir_processor_root/var.backup/db/pkg/app-editors/vim-core-8.2.0360/CONTENTS
  12. 1
      tests/templates/testfiles/test_dir_processor_root/var.backup/db/pkg/app-editors/vim-core-8.2.0360/SLOT

2
calculate/templates/format/base_format.py

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

1
calculate/templates/template_processor.py

@ -524,7 +524,6 @@ class TemplateWrapper:
self.contents_matching = (self.parameters.autoupdate
or self.parameters.force)
print(f'contents_matching: {self.contents_matching}')
if not self.protected:
self.contents_matching = True

7
calculate/utils/package.py

@ -587,10 +587,12 @@ class PackageAtomParser:
'''Метод для разбора значения package, после разбора инициирует
проверку полученных значений. Возвращает объект PackageAtomName.'''
self.package_atom = package_atom
print(f'value: {package_atom}')
if isinstance(package_atom, str):
atom_dictionary = self.parse_atom_name(package_atom)
atom_dictionary['package_atom'] = package_atom
print(f'atom_dict: {atom_dictionary}')
elif isinstance(package_atom, dict):
atom_dictionary = package_atom
if 'package_atom' not in atom_dictionary:
@ -615,10 +617,11 @@ class PackageAtomParser:
'''Метод для проверки существования пакета. Существование пакета
определяется наличием соответствующего CONTENTS файла.'''
# Используем glob-паттерн для поиска.
glob_result = glob.glob(r'{0}/{1}/{2}*/CONTENTS'.format(
glob_pattern = r'{0}/{1}/{2}-[0-9]*/CONTENTS'.format(
self.pkg_path,
atom_dictionary['category'],
atom_dictionary['name']))
atom_dictionary['name'])
glob_result = glob.glob(glob_pattern)
if not glob_result:
# Если ничего не нашлось.

34
tests/templates/test_directory_processor.py

@ -8,7 +8,8 @@ from typing import Optional, List
from calculate.templates.template_processor import DirectoryProcessor,\
TemplateWrapper
from calculate.utils.package import PackageAtomName, Version, Package,\
NonePackage, PackageCreator
NonePackage, PackageCreator,\
PackageAtomParser
from calculate.utils.files import join_paths
from calculate.utils.io_module import IOModule
from calculate.templates.template_engine import Variables
@ -91,7 +92,8 @@ datavars = Variables({'install': install,
def show_tree(dir_path: str, indent: int = 0,
test_names: Optional[List[str]] = None) -> None:
test_names: Optional[List[str]] = None,
check_cfg: bool = False) -> None:
last_names = dict()
if test_names is not None:
for name in test_names:
@ -107,9 +109,12 @@ def show_tree(dir_path: str, indent: int = 0,
pass
if last_names:
node_name = node.name
if node_name.startswith("._cfg") and check_cfg:
node_name = node.name[len("._cfg0000_"):]
for name in test_names:
if node.name.startswith(name):
number = int(node.name[len(name) + 1:])
if node_name.startswith(name):
number = int(node_name[len(name) + 1:])
if number > last_names[name]:
last_names[name] = number
break
@ -1846,11 +1851,30 @@ class TestDirectoryProcessor:
assert os.path.lexists(join_paths(CHROOT_PATH,
'/etc/._cfg0000_link_5'))
def test_for_debug_packages_error(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_64')
directory_processor = DirectoryProcessor('install',
datavars_module=datavars)
directory_processor.process_template_directories()
atom_parser = PackageAtomParser(chroot_path=CHROOT_PATH)
vim_pkg = Package(
atom_parser.parse_package_parameter(">app-editors/vim-8.0"),
chroot_path=CHROOT_PATH)
vim_core_pkg = Package(
atom_parser.parse_package_parameter("app-editors/vim-core"),
chroot_path=CHROOT_PATH)
assert '/etc/file_26' in vim_pkg
assert '/etc/file_26' not in vim_core_pkg
def test_view_tree(self):
list_path = join_paths(CHROOT_PATH, '/etc')
test_names = ['dir', 'file', 'link']
last_names = show_tree(list_path,
test_names=test_names)
test_names=test_names,
check_cfg=True)
if last_names:
print('last names:')
print("\n".join(

1
tests/templates/testfiles/test_dir_processor_root/etc.backup/file_26

@ -0,0 +1 @@
salem -- we make it good

2
tests/templates/testfiles/test_dir_processor_root/templates_48/install/dir_66/.calculate_directory

@ -1,2 +1,2 @@
{% calculate package = "test-category/test-package",
merge = "test-category/new/package" %}
merge = "test-category/new-package" %}

2
tests/templates/testfiles/test_dir_processor_root/templates_64/install/.calculate_directory

@ -0,0 +1,2 @@
{% calculate append = "skip", action = "install",
package = "app-editors/vim" %}

2
tests/templates/testfiles/test_dir_processor_root/templates_64/install/file_26

@ -0,0 +1,2 @@
{% calculate append = "join" %}
salem -- onagainoffagain

2
tests/templates/testfiles/test_dir_processor_root/var.backup/db/pkg/app-editors/vim-8.2.0360/CONTENTS

@ -0,0 +1,2 @@
dir /etc
obj /etc/file_26 23163aa36018dd607a3cc3487108439a 1611822287

1
tests/templates/testfiles/test_dir_processor_root/var.backup/db/pkg/app-editors/vim-8.2.0360/SLOT

@ -0,0 +1 @@
0

0
tests/templates/testfiles/test_dir_processor_root/var.backup/db/pkg/app-editors/vim-core-8.2.0360/CONTENTS

1
tests/templates/testfiles/test_dir_processor_root/var.backup/db/pkg/app-editors/vim-core-8.2.0360/SLOT

@ -0,0 +1 @@
0
Loading…
Cancel
Save