Parameters processing and 'package' module are added. Some changes to the structure of the utility are made.
parent
fcf41bcf8a
commit
9c339bb03b
@ -0,0 +1,140 @@
|
||||
# vim: fileencoding=utf-8
|
||||
#
|
||||
from .base_format import BaseFormat
|
||||
from collections import OrderedDict
|
||||
from jinja2 import PackageLoader, Environment
|
||||
from pyparsing import Literal, Regex, Word, nums, alphanums, Optional,\
|
||||
ParseException
|
||||
|
||||
|
||||
class ContentsFormat(BaseFormat):
|
||||
FORMAT = 'contents'
|
||||
|
||||
_initialized = False
|
||||
|
||||
def __init__(self, document_text: str,
|
||||
ignore_comments=False,
|
||||
join_before=False,
|
||||
template_parser=True):
|
||||
processing_methods = [self._parse_dir_line,
|
||||
self._parse_sym_line,
|
||||
self._parse_obj_line]
|
||||
|
||||
super().__init__(processing_methods)
|
||||
|
||||
self._ignore_comments = ignore_comments
|
||||
self._join_before = join_before
|
||||
self._template_parser_flag = template_parser
|
||||
|
||||
if not self._initialized:
|
||||
self._initialize_parser()
|
||||
|
||||
if document_text == '':
|
||||
self._document_dictionary = OrderedDict()
|
||||
else:
|
||||
document_lines = self._get_list_of_logic_lines(document_text)
|
||||
self._lines_to_dictionary(document_lines)
|
||||
|
||||
@classmethod
|
||||
def _initialize_parser(cls):
|
||||
action_symbols = (Literal('!') | Literal('-'))
|
||||
|
||||
sym_keyword = Literal('sym')
|
||||
dir_keyword = Literal('dir')
|
||||
obj_keyword = Literal('obj')
|
||||
|
||||
symlink_arrow = Literal('->')
|
||||
|
||||
file_path = Regex(r'\S+')
|
||||
|
||||
time_value = Word(nums)
|
||||
|
||||
md5 = Word(alphanums)
|
||||
|
||||
cls.sym_line = (Optional(action_symbols, default='')('action')
|
||||
+ sym_keyword('type') + file_path('name')
|
||||
+ symlink_arrow.suppress() + file_path('target')
|
||||
+ time_value('time'))
|
||||
|
||||
cls.dir_line = (Optional(action_symbols, default='')('action')
|
||||
+ dir_keyword('type') + file_path('name'))
|
||||
|
||||
cls.obj_line = (Optional(action_symbols, default='')('action')
|
||||
+ obj_keyword('type') + file_path('name')
|
||||
+ md5('md5') + time_value('time'))
|
||||
|
||||
cls._initialized = True
|
||||
|
||||
def _parse_sym_line(self, line):
|
||||
try:
|
||||
parsing_result = self.sym_line.parseString(line)
|
||||
self._match = True
|
||||
if self._template_parser_flag:
|
||||
output_name = (parsing_result.action, parsing_result.name)
|
||||
output_value = (parsing_result.type,
|
||||
parsing_result.target,
|
||||
parsing_result.time)
|
||||
self._item_to_add = OrderedDict({output_name: [output_value]})
|
||||
else:
|
||||
output_name = parsing_result.name
|
||||
output_value = OrderedDict({'type': parsing_result.type,
|
||||
'target': parsing_result.target,
|
||||
'mtime': parsing_result.time})
|
||||
|
||||
self._item_to_add = OrderedDict({output_name: output_value})
|
||||
self._ready_to_update = True
|
||||
except ParseException:
|
||||
return
|
||||
|
||||
def _parse_dir_line(self, line):
|
||||
try:
|
||||
parsing_result = self.dir_line.parseString(line)
|
||||
self._match = True
|
||||
if self._template_parser_flag:
|
||||
output_name = (parsing_result.action, parsing_result.name)
|
||||
output_value = (parsing_result.type,)
|
||||
self._item_to_add = OrderedDict({output_name: [output_value]})
|
||||
else:
|
||||
output_name = parsing_result.name
|
||||
output_value = OrderedDict({'type': parsing_result.type})
|
||||
|
||||
self._item_to_add = OrderedDict({output_name: output_value})
|
||||
self._ready_to_update = True
|
||||
except ParseException:
|
||||
return
|
||||
|
||||
def _parse_obj_line(self, line):
|
||||
try:
|
||||
parsing_result = self.obj_line.parseString(line)
|
||||
self._match = True
|
||||
if self._template_parser_flag:
|
||||
output_name = (parsing_result.action, parsing_result.name)
|
||||
output_value = (parsing_result.type,
|
||||
parsing_result.md5,
|
||||
parsing_result.time)
|
||||
self._item_to_add = OrderedDict({output_name: [output_value]})
|
||||
else:
|
||||
output_name = parsing_result.name
|
||||
output_value = OrderedDict({'type': parsing_result.type,
|
||||
'md5': parsing_result.md5,
|
||||
'mtime': parsing_result.time})
|
||||
self._item_to_add = OrderedDict({output_name: output_value})
|
||||
|
||||
self._ready_to_update = True
|
||||
except ParseException:
|
||||
return
|
||||
|
||||
def get_document_text(self):
|
||||
file_loader = PackageLoader('calculate.templates.format',
|
||||
self.TEMPLATES_DIRECTORY)
|
||||
formats_environment = Environment(loader=file_loader,
|
||||
trim_blocks=True,
|
||||
lstrip_blocks=True)
|
||||
formats_environment.globals.update(zip=zip)
|
||||
formats_environment.add_extension('jinja2.ext.do')
|
||||
template = formats_environment.get_template(self.FORMAT)
|
||||
document_text = template.render(
|
||||
document_dictionary=self._document_dictionary,
|
||||
template_parser=self._template_parser_flag
|
||||
)
|
||||
return document_text
|
@ -0,0 +1,14 @@
|
||||
{% for file_name, contents_values in document_dictionary.items() %}
|
||||
{% if contents_values is mapping %}
|
||||
{% set contents_values = (contents_values.values()|list) %}
|
||||
{% else %}
|
||||
{% set contents_values = (contents_values[0]|list) %}
|
||||
{% set file_name = file_name[-1] %}
|
||||
{% endif %}
|
||||
{% if contents_values[0] == 'sym' %}
|
||||
{{ contents_values[0] }} {{ file_name }} -> {{ contents_values[1:]|join(' ') }}
|
||||
{% else %}
|
||||
{{ contents_values[0] }} {{ file_name }}{% if contents_values[1:] %} {{ contents_values[1:]|join(' ') }}{% endif %}
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,298 @@
|
||||
# vim: fileencoding=utf-8
|
||||
#
|
||||
import os
|
||||
import re
|
||||
import glob
|
||||
from collections import OrderedDict
|
||||
from ..templates.format.contents_format import ContentsFormat
|
||||
from .files import read_file, read_link, join_paths, FilesError
|
||||
import hashlib
|
||||
|
||||
|
||||
class PackageError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class PackageAtomError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class PackageAtom:
|
||||
atom_regex = re.compile(r'''(?P<category>[^\s/]*)/
|
||||
(?P<name>[^\s:]*)
|
||||
(?P<slot>:\S*)?
|
||||
(?P<uses>(?:\s+\S*)*)
|
||||
''', re.VERBOSE)
|
||||
|
||||
def __init__(self, pkg_path='/var/db/pkg',
|
||||
chroot_path='/'):
|
||||
self.chroot_path = chroot_path
|
||||
|
||||
if chroot_path != '/':
|
||||
self.pkg_path = join_paths(chroot_path, pkg_path)
|
||||
else:
|
||||
self.pkg_path = pkg_path
|
||||
|
||||
self.package_atom = ''
|
||||
self._atom_dictionary = {}
|
||||
|
||||
def parse_package_parameter(self, package_atom,
|
||||
add_slot=False, add_uses=False):
|
||||
self.package_atom = package_atom
|
||||
self._atom_dictionary = {}
|
||||
|
||||
parsing_result = self.atom_regex.search(package_atom)
|
||||
|
||||
if not parsing_result or parsing_result.string != package_atom:
|
||||
raise PackageAtomError("'package' parameter value '{}' is not"
|
||||
" correct".format(package_atom))
|
||||
|
||||
if 'category' in parsing_result.groupdict():
|
||||
self._atom_dictionary['category'] = parsing_result.groupdict(
|
||||
)['category']
|
||||
|
||||
if 'name' in parsing_result.groupdict():
|
||||
self._atom_dictionary['name'] = parsing_result.groupdict()['name']
|
||||
|
||||
self._check_package_existance()
|
||||
|
||||
if ('slot' in parsing_result.groupdict() and
|
||||
parsing_result.groupdict()['slot'] and
|
||||
parsing_result.groupdict()['slot'] != ':'):
|
||||
print('slot value is correct')
|
||||
self._atom_dictionary['slot'] = parsing_result.groupdict(
|
||||
)['slot'][1:]
|
||||
elif add_slot:
|
||||
self._atom_dictionary['slot'] = self._get_slot_value()
|
||||
|
||||
if ('uses' in parsing_result.groupdict() and
|
||||
parsing_result.groupdict()['uses']):
|
||||
self._atom_dictionary['uses'] = []
|
||||
uses = parsing_result.groupdict()['uses'].strip().split(' ')
|
||||
for use_flag in uses:
|
||||
self._atom_dictionary['uses'].append(use_flag.strip())
|
||||
|
||||
elif add_uses:
|
||||
self._atom_dictionary['uses'] = self._get_use_flags_value()
|
||||
|
||||
def _check_package_existance(self, package_atom=''):
|
||||
if package_atom:
|
||||
self.parse_package_parameter(package_atom)
|
||||
return True
|
||||
elif (self._atom_dictionary['category'] and
|
||||
self._atom_dictionary['name']):
|
||||
glob_result = glob.glob(
|
||||
'{0}/{1}/{2}*/CONTENTS'.format(self.pkg_path,
|
||||
self._atom_dictionary['category'],
|
||||
self._atom_dictionary['name']))
|
||||
if not glob_result:
|
||||
raise PackageAtomError("Package from 'package' parameter value"
|
||||
" '{}' does not exist".format(
|
||||
self.package_atom))
|
||||
elif len(glob_result) == 1:
|
||||
contents_path = next(iter(glob_result))
|
||||
self._atom_dictionary['name'] = contents_path.split('/')[-2]
|
||||
self._atom_dictionary['contents'] = contents_path
|
||||
else:
|
||||
raise PackageAtomError("'package' parameter value '{}' matches"
|
||||
" multiple installed packages".format(
|
||||
self.package_atom))
|
||||
|
||||
def _get_slot_value(self):
|
||||
contents_path = self._atom_dictionary['contents']
|
||||
slot_path = os.path.join(os.path.dirname(contents_path), 'SLOT')
|
||||
try:
|
||||
return read_file(slot_path).strip('\n')
|
||||
except FilesError:
|
||||
raise PackageAtomError("could not read slot value for"
|
||||
" 'package': {}".format(self.package_atom))
|
||||
|
||||
def _get_use_flags_value(self):
|
||||
contents_path = self._atom_dictionary['contents']
|
||||
use_path = os.path.join(os.path.dirname(contents_path), 'USE')
|
||||
try:
|
||||
return read_file(use_path).strip('\n').split(' ')
|
||||
except FilesError:
|
||||
raise PackageAtomError("could not read use flags for 'package'"
|
||||
" parameter: {}".format(self.package_atom))
|
||||
|
||||
def _get_category_packages(self, category):
|
||||
for path in glob.glob('{0}/{1}/*/CONTENTS'.format(self.pkg_path,
|
||||
category)):
|
||||
yield path
|
||||
|
||||
def get_file_package(self, file_path, with_slot=False, with_uses=False):
|
||||
if self.chroot_path != '/' and file_path.startswith(self.chroot_path):
|
||||
file_path = file_path[len(self.chroot_path):]
|
||||
|
||||
for category in os.listdir(self.pkg_path):
|
||||
for contents_path in self._get_category_packages(category):
|
||||
try:
|
||||
with open(contents_path, 'r') as contents_file:
|
||||
for file_line in contents_file.readlines():
|
||||
contents_name = file_line.split(' ')[1].strip()
|
||||
if contents_name == file_path:
|
||||
package = '/'.join(os.path.dirname(
|
||||
contents_path).split('/')[-2:])
|
||||
return package
|
||||
except (OSError, IOError):
|
||||
continue
|
||||
else:
|
||||
raise PackageAtomError("The file does not belong to any package")
|
||||
|
||||
@property
|
||||
def atom_dictionary(self):
|
||||
return self._atom_dictionary
|
||||
|
||||
@property
|
||||
def category(self):
|
||||
if 'category' in self._atom_dictionary:
|
||||
return self._atom_dictionary['category']
|
||||
else:
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
if 'name' in self._atom_dictionary:
|
||||
return self._atom_dictionary['name']
|
||||
else:
|
||||
return False
|
||||
|
||||
@property
|
||||
def slot(self):
|
||||
if 'slot' in self._atom_dictionary:
|
||||
return self._atom_dictionary['slot']
|
||||
else:
|
||||
return False
|
||||
|
||||
@property
|
||||
def uses(self):
|
||||
if 'uses' in self._atom_dictionary:
|
||||
return self._atom_dictionary['uses']
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
class Package:
|
||||
re_cfg = re.compile(r'/\._cfg\d{4}_')
|
||||
|
||||
def __init__(self, package_atom, pkg_path='/var/db/pkg', chroot_path='/'):
|
||||
self.chroot_path = chroot_path
|
||||
|
||||
self.contents_file_path = os.path.join(pkg_path, package_atom,
|
||||
'CONTENTS')
|
||||
self.contents_dictionary = OrderedDict()
|
||||
|
||||
if chroot_path != '/':
|
||||
self.contents_file_path = join_paths(chroot_path,
|
||||
self.contents_file_path)
|
||||
os.path.exists(self.contents_file_path)
|
||||
self.read_contents_file()
|
||||
|
||||
def remove_cfg_prefix(self, file_name):
|
||||
return self.re_cfg.sub('/', file_name)
|
||||
|
||||
def remove_chroot_path(self, file_name):
|
||||
if self.chroot_path != '/' and file_name.startswith(self.chroot_path):
|
||||
return file_name[len(self.chroot_path):]
|
||||
else:
|
||||
return file_name
|
||||
|
||||
def read_contents_file(self):
|
||||
try:
|
||||
contents_text = read_file(self.contents_file_path)
|
||||
except FilesError as error:
|
||||
raise PackageError(str(error))
|
||||
if contents_text:
|
||||
contents_format = ContentsFormat(contents_text,
|
||||
template_parser=False)
|
||||
self.contents_dictionary = contents_format._document_dictionary
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def write_contents_file(self):
|
||||
pass
|
||||
|
||||
def render_contents_file(self):
|
||||
contents_format = ContentsFormat('', template_parser=False)
|
||||
contents_format._document_dictionary = self.contents_dictionary
|
||||
return contents_format.get_document_text()
|
||||
|
||||
def add_dir(self, file_name):
|
||||
file_name = self.remove_cfg_prefix(file_name)
|
||||
file_name = self.remove_chroot_path(file_name)
|
||||
|
||||
if (file_name != '/' and
|
||||
(file_name not in self.contents_dictionary
|
||||
or self.contents_dictionary[file_name]['type'] != 'dir')):
|
||||
self.add_dir(os.path.dirname(file_name))
|
||||
contents_item = OrderedDict({'type': 'dir'})
|
||||
self.contents_dictionary[file_name] = contents_item
|
||||
|
||||
def add_sym(self, file_name):
|
||||
file_name = self.remove_cfg_prefix(file_name)
|
||||
|
||||
real_path = file_name
|
||||
file_name = self.remove_chroot_path(file_name)
|
||||
|
||||
if real_path == file_name:
|
||||
real_path = join_paths(self.chroot_path, file_name)
|
||||
|
||||
self.add_dir(os.path.dirname(file_name))
|
||||
mtime = str(int(os.lstat(real_path).st_mtime))
|
||||
try:
|
||||
contents_item = OrderedDict({'type': 'sym',
|
||||
'target': read_link(real_path),
|
||||
'mtime': mtime})
|
||||
except FilesError as error:
|
||||
raise PackageError(str(error))
|
||||
|
||||
self.contents_dictionary[file_name] = contents_item
|
||||
|
||||
def add_obj(self, file_name):
|
||||
file_name = self.remove_cfg_prefix(file_name)
|
||||
|
||||
real_path = file_name
|
||||
file_name = self.remove_chroot_path(file_name)
|
||||
|
||||
if real_path == file_name:
|
||||
real_path = join_paths(self.chroot_path, file_name)
|
||||
self.add_dir(os.path.dirname(file_name))
|
||||
|
||||
try:
|
||||
file_text = read_file(real_path).encode()
|
||||
except FilesError as error:
|
||||
raise PackageError(str(error))
|
||||
|
||||
contents_item = OrderedDict({'type': 'obj',
|
||||
'md5': hashlib.md5(file_text).hexdigest(),
|
||||
'mtime':
|
||||
str(int(os.lstat(real_path).st_mtime))})
|
||||
self.contents_dictionary[file_name] = contents_item
|
||||
|
||||
def add_file(self, file_name):
|
||||
if file_name != '/':
|
||||
real_path = file_name
|
||||
file_name = self.remove_chroot_path(file_name)
|
||||
|
||||
if real_path != file_name:
|
||||
real_path = join_paths(self.chroot_path, file_name)
|
||||
if os.path.isdir(real_path):
|
||||
self.add_dir(file_name)
|
||||
elif os.path.islink(real_path):
|
||||
self.add_link(file_name)
|
||||
elif os.path.isfile(real_path):
|
||||
self.add_obj(file_name)
|
||||
|
||||
def modify_contents_item(self, file_name, item_value):
|
||||
pass
|
||||
|
||||
def remove_file(self, file_name):
|
||||
pass
|
||||
|
||||
def remove_empty_directories(self):
|
||||
pass
|
||||
|
||||
def check_file_md5(self, file_path):
|
||||
pass
|
@ -0,0 +1,82 @@
|
||||
import pytest
|
||||
from collections import OrderedDict
|
||||
from calculate.templates.format.contents_format import ContentsFormat
|
||||
|
||||
|
||||
@pytest.mark.contents
|
||||
class TestParsingMethods:
|
||||
def test_if_input_document_contains_a_few_lines_without_any_action_symbols__the_initialised_object_contains_correct_dictionary(self):
|
||||
document_text = '''
|
||||
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
|
||||
sym /usr/share/bash-completion/completions/ex -> vim 1573538054
|
||||
dir /usr/share/bash-completion/completions
|
||||
'''
|
||||
|
||||
result = OrderedDict({('', '/usr/bin/vim'):
|
||||
[('obj', '30acc0f256e11c1ecdb1bd80b688d238',
|
||||
'1573538056')],
|
||||
('', '/usr/share/bash-completion/completions/ex'):
|
||||
[('sym', 'vim', '1573538054')],
|
||||
('', '/usr/share/bash-completion/completions'):
|
||||
[('dir',)]})
|
||||
|
||||
contents_object = ContentsFormat(document_text)
|
||||
assert result == contents_object._document_dictionary
|
||||
|
||||
def test_if_input_document_contains_a_few_lines_with_some_action_symbols__the_initialised_object_contains_correct_dictionary(self):
|
||||
document_text = '''
|
||||
!obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
|
||||
-sym /usr/share/bash-completion/completions/ex -> vim 1573538054
|
||||
!dir /usr/share/bash-completion/completions
|
||||
'''
|
||||
|
||||
result = OrderedDict({('!', '/usr/bin/vim'):
|
||||
[('obj', '30acc0f256e11c1ecdb1bd80b688d238',
|
||||
'1573538056')],
|
||||
('-', '/usr/share/bash-completion/completions/ex'):
|
||||
[('sym', 'vim', '1573538054')],
|
||||
('!', '/usr/share/bash-completion/completions'):
|
||||
[('dir',)]})
|
||||
|
||||
contents_object = ContentsFormat(document_text)
|
||||
assert result == contents_object._document_dictionary
|
||||
|
||||
def test_if_template_parser_flag_is_set_False__the_initialized_object_contains_correct_dictionary_for_contents_util_module(self):
|
||||
document_text = '''
|
||||
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
|
||||
sym /usr/share/bash-completion/completions/ex -> vim 1573538054
|
||||
dir /usr/share/bash-completion/completions
|
||||
'''
|
||||
|
||||
result = OrderedDict({'/usr/bin/vim':
|
||||
OrderedDict(
|
||||
{'type': 'obj',
|
||||
'md5': '30acc0f256e11c1ecdb1bd80b688d238',
|
||||
'mtime': '1573538056'}),
|
||||
'/usr/share/bash-completion/completions/ex':
|
||||
OrderedDict(
|
||||
{'type': 'sym',
|
||||
'target': 'vim',
|
||||
'mtime': '1573538054'}),
|
||||
'/usr/share/bash-completion/completions':
|
||||
OrderedDict({'type': 'dir'})})
|
||||
|
||||
contents_object = ContentsFormat(document_text, template_parser=False)
|
||||
assert result == contents_object._document_dictionary
|
||||
|
||||
def test_joining_documents_1(self):
|
||||
with open('./tests/templates/format/testfiles/contents_original', 'r') as original_file:
|
||||
original_text = original_file.read()
|
||||
contents_original_object = ContentsFormat(original_text)
|
||||
|
||||
with open('./tests/templates/format/testfiles/contents_template', 'r') as template_file:
|
||||
template_text = template_file.read()
|
||||
contents_template_object = ContentsFormat(template_text,
|
||||
ignore_comments=True)
|
||||
|
||||
contents_original_object.join_template(contents_template_object)
|
||||
|
||||
with open('./tests/templates/format/testfiles/contents_result', 'r') as result_file:
|
||||
result_text = result_file.read()
|
||||
|
||||
assert contents_original_object.get_document_text() == result_text
|
@ -0,0 +1,18 @@
|
||||
dir /usr
|
||||
dir /usr/bin
|
||||
sym /usr/bin/rview -> vim 1573538053
|
||||
sym /usr/bin/rvim -> vim 1573538053
|
||||
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
|
||||
sym /usr/bin/vimdiff -> vim 1573538053
|
||||
dir /usr/share
|
||||
dir /urs/share/dir
|
||||
obj /urs/share/dir/file 4580e5268ddf10175cdd86f87f481d71 1560504013
|
||||
dir /usr/share/applications
|
||||
dir /usr/share/bash-completion
|
||||
dir /usr/share/bash-completion/completions
|
||||
sym /usr/share/bash-completion/completions/ex -> vim 1573538054
|
||||
sym /usr/share/bash-completion/completions/rview -> vim 1573538054
|
||||
sym /usr/share/bash-completion/completions/rvim -> vim 1573538054
|
||||
sym /usr/share/bash-completion/completions/vi -> vim 1573538054
|
||||
obj /usr/share/bash-completion/completions/vim 49aa29933e92bb54d84eb6efc5cdd801 1573538054
|
||||
sym /usr/share/bash-completion/completions/vimdiff -> vim 1573538054
|
@ -0,0 +1,22 @@
|
||||
dir /usr
|
||||
dir /usr/bin
|
||||
sym /usr/bin/rview -> vim 1573538053
|
||||
sym /usr/bin/rvim -> vim 1573538053
|
||||
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
|
||||
sym /usr/bin/vimdiff -> vim 1573538053
|
||||
dir /usr/share
|
||||
dir /usr/share/applications
|
||||
dir /usr/share/bash-completion
|
||||
dir /usr/share/bash-completion/completions
|
||||
sym /usr/share/bash-completion/completions/ex -> vim 1573538054
|
||||
sym /usr/share/bash-completion/completions/rview -> vim 1573538054
|
||||
sym /usr/share/bash-completion/completions/rvim -> vim 1573538054
|
||||
sym /usr/share/bash-completion/completions/vi -> vi 1573538054
|
||||
obj /usr/share/bash-completion/completions/vim 49aa29933e92bb54d84eb6efc5cdd801 1573538054
|
||||
sym /usr/share/bash-completion/completions/vimdiff -> vim 1573538054
|
||||
dir /etc
|
||||
dir /etc/env.d
|
||||
obj /etc/env.d/99editor 835da024d5f3c7a862934df592cdc9fe 1574417039
|
||||
sym /usr/share/bash-completion/completions/view -> vim 1573538054
|
||||
dir /etc/vim
|
||||
obj /etc/vim/vimrc.local ed7cd3cef611ff49b12093b93fed59be 1574417039
|
@ -0,0 +1,9 @@
|
||||
dir /etc
|
||||
dir /etc/env.d
|
||||
obj /etc/env.d/99editor 835da024d5f3c7a862934df592cdc9fe 1574417039
|
||||
sym /usr/share/bash-completion/completions/vi -> vi 1573538054
|
||||
sym /usr/share/bash-completion/completions/view -> vim 1573538054
|
||||
!dir /urs/share/dir
|
||||
!obj /urs/share/dir/file 4580e5268ddf10175cdd86f87f481d71 1560504013
|
||||
dir /etc/vim
|
||||
obj /etc/vim/vimrc.local ed7cd3cef611ff49b12093b93fed59be 1574417039
|
@ -1,8 +1,52 @@
|
||||
import pytest
|
||||
from calculate.templates.template_processor import TemplateAction
|
||||
from calculate.templates.template_engine import Variables
|
||||
import os
|
||||
from calculate.templates.template_processor import TemplateAction,\
|
||||
TemplateParameters, DIR
|
||||
|
||||
|
||||
template_action = TemplateAction()
|
||||
|
||||
TEST_DIRECTORY_PATH = os.path.join(os.getcwd(), 'tests/templates/testfiles')
|
||||
|
||||
|
||||
@pytest.mark.template_action
|
||||
class TestTemplateAction:
|
||||
pass
|
||||
def test_chown_directory(self):
|
||||
pass
|
||||
|
||||
def test_chmod_directory(self):
|
||||
pass
|
||||
|
||||
def test_create_directory(self):
|
||||
path_to_create = os.path.join(TEST_DIRECTORY_PATH,
|
||||
'dir_tests/new_dir/new_subdir')
|
||||
template_action.template_parameters = TemplateParameters(
|
||||
{'chown':
|
||||
'{0}:{1}'.format(os.getuid(),
|
||||
os.getgid())},
|
||||
DIR)
|
||||
template_action._create_directory(target_path=path_to_create)
|
||||
assert os.path.exists(path_to_create)
|
||||
|
||||
def test_link_directory(self):
|
||||
path_to_source = os.path.join(TEST_DIRECTORY_PATH,
|
||||
'dir_tests/new_dir/new_subdir')
|
||||
path_to_link = os.path.join(TEST_DIRECTORY_PATH,
|
||||
'dir_tests/new_dir/new_subdir_link')
|
||||
template_action.source = path_to_source
|
||||
template_action._link_directory(path_to_link)
|
||||
|
||||
template_action.source = False
|
||||
assert os.path.exists(path_to_link) and os.path.islink(path_to_link)
|
||||
|
||||
def test_remove_directory(self):
|
||||
directory_to_remove = os.path.join(TEST_DIRECTORY_PATH,
|
||||
'dir_tests/dir')
|
||||
link_to_remove = os.path.join(TEST_DIRECTORY_PATH,
|
||||
'dir_tests/new_dir/new_subdir_link')
|
||||
|
||||
template_action._remove_directory(link_to_remove)
|
||||
assert not os.path.exists(link_to_remove)
|
||||
|
||||
template_action._remove_directory(directory_to_remove)
|
||||
assert not os.path.exists(directory_to_remove)
|
||||
|
@ -0,0 +1,137 @@
|
||||
import pytest
|
||||
import os
|
||||
from calculate.templates.template_processor import TemplateParameters, DIR,\
|
||||
FILE, IncorrectParameter,\
|
||||
TemplateAction
|
||||
from calculate.utils.files import join_paths
|
||||
from pprint import pprint
|
||||
|
||||
|
||||
CHROOT_PATH = os.path.join(os.getcwd(), 'tests/templates/testfiles')
|
||||
|
||||
|
||||
@pytest.mark.template_parameters
|
||||
class TestTemplateParameters:
|
||||
def test_if_TemplateParameters_object_is_initialized_accoding_to_dictionary_of_correct_template_parameters__the_TemplateParameters_object_contains_processed_parameters_as_its_attributes_including_default_values(self):
|
||||
parameters = {'append': 'join',
|
||||
'chmod': '600',
|
||||
'force': True}
|
||||
template_parameters = TemplateParameters(parameters, DIR)
|
||||
assert (template_parameters.append == 'join' and
|
||||
template_parameters.chmod == 0o600 and
|
||||
template_parameters.force and
|
||||
not template_parameters.autoupdate)
|
||||
|
||||
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_append_parameter__a_value_of_the_parameter_will_be_checked(self):
|
||||
parameters = {'append': 'join'}
|
||||
# Для получения множества доступных значений параметра append.
|
||||
TemplateAction()
|
||||
try:
|
||||
template_parameters = TemplateParameters(parameters, FILE)
|
||||
assert template_parameters.append == 'join'
|
||||
except Exception as error:
|
||||
pytest.fail('Unexpected exception: {0}'.
|
||||
format(str(error)))
|
||||
|
||||
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_source_parameter__the_object_will_be_initialized_successfully(self):
|
||||
parameters = {'source': '/test_dir_1/file.test'}
|
||||
|
||||
try:
|
||||
template_parameters = TemplateParameters(parameters, FILE,
|
||||
chroot_path=CHROOT_PATH)
|
||||
assert template_parameters.source == join_paths(
|
||||
CHROOT_PATH,
|
||||
'/test_dir_1/file.test')
|
||||
except Exception as error:
|
||||
pytest.fail('Unexpected exception: {0}'.
|
||||
format(str(error)))
|
||||
|
||||
def test_if_TemplateParameters_object_is_intialized_as_dir_parameters_object_using_correct_source_parameter_with_append_link__the_object_will_be_initialized_successfully(self):
|
||||
parameters = {'append': 'link', 'source': '/test_dir_1'}
|
||||
|
||||
try:
|
||||
template_parameters = TemplateParameters(parameters, DIR,
|
||||
chroot_path=CHROOT_PATH)
|
||||
assert template_parameters.source == join_paths(CHROOT_PATH,
|
||||
'/test_dir_1')
|
||||
except Exception as error:
|
||||
pytest.fail('Unexpected exception: {0}'.
|
||||
format(str(error)))
|
||||
|
||||
def test_if_TemplateParameters_object_is_intialized_using_source_parameter_with_unexisting_file_path__the_initialization_of_the_object_will_be_failed(self):
|
||||
parameters = {'source': '/test_dir_1/unexisted_file.test'}
|
||||
with pytest.raises(IncorrectParameter):
|
||||
template_parameters = TemplateParameters(parameters, FILE)
|
||||
|
||||
def test_if_TemplateParameters_object_is_intialized_as_dir_parameters_object_using_source_parameter_but_without_append_link__the_initialization_of_the_object_will_be_failed(self):
|
||||
parameters = {'source': '/test_dir_1/file.test'}
|
||||
with pytest.raises(IncorrectParameter):
|
||||
template_parameters = TemplateParameters(parameters, DIR,
|
||||
chroot_path=CHROOT_PATH)
|
||||
|
||||
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_force_parameter__the_object_will_be_initialized_successfully(self):
|
||||
parameters = {'force': True}
|
||||
try:
|
||||
template_parameters = TemplateParameters(parameters, FILE)
|
||||
assert template_parameters.force
|
||||
except Exception as error:
|
||||
pytest.fail('Unexpected exception: {0}'.
|
||||
format(str(error)))
|
||||
|
||||
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_force_parameter__the_initialization_of_the_object_will_be_failed(self):
|
||||
parameters = {'force': 'value'}
|
||||
with pytest.raises(IncorrectParameter):
|
||||
template_parameters = TemplateParameters(parameters, FILE)
|
||||
|
||||
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_autoupdate_parameter__a_value_of_the_parameter_will_be_checked(self):
|
||||
parameters = {'autoupdate': True}
|
||||
try:
|
||||
template_parameters = TemplateParameters(parameters, FILE)
|
||||
assert template_parameters.autoupdate
|
||||
except Exception as error:
|
||||
pytest.fail('Unexpected exception: {0}'.
|
||||
format(str(error)))
|
||||
|
||||
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_autoupdate_parameter__the_initialization_of_the_object_will_be_failed(self):
|
||||
parameters = {'autoupdate': 'value'}
|
||||
with pytest.raises(IncorrectParameter):
|
||||
template_parameters = TemplateParameters(parameters, FILE)
|
||||
|
||||
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chown_parameter__the_object_will_be_initialized_successfully(self):
|
||||
parameters = {'chown': 'root:root'}
|
||||
try:
|
||||
template_parameters = TemplateParameters(parameters, FILE)
|
||||
assert template_parameters.chown == {'uid': 0, 'gid': 0}
|
||||
except Exception as error:
|
||||
pytest.fail('Unexpected exception: {0}'.
|
||||
format(str(error)))
|
||||
|
||||
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chown_parameter_in_its_digital_form__the_object_will_be_initialized_successfully(self):
|
||||
uid = os.getuid()
|
||||
gid = os.getgid()
|
||||
parameters = {'chown': '{0}:{1}'.format(uid, gid)}
|
||||
try:
|
||||
template_parameters = TemplateParameters(parameters, FILE)
|
||||
assert template_parameters.chown == {'uid': uid, 'gid': gid}
|
||||
except Exception as error:
|
||||
pytest.fail('Unexpected exception: {0}'.
|
||||
format(str(error)))
|
||||
|
||||
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_chown_parameter__the_initialization_of_the_object_will_be_failed(self):
|
||||
parameters = {'chown': 'wrong_user_name:wrong_group_name'}
|
||||
with pytest.raises(IncorrectParameter):
|
||||
template_parameters = TemplateParameters(parameters, FILE)
|
||||
|
||||
def test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chmod_parameter__the_object_will_be_initialized_successfully(self):
|
||||
try:
|
||||
parameters = {'chmod': 'rw-r--r--'}
|
||||
template_parameters = TemplateParameters(parameters, FILE)
|
||||
assert template_parameters.chmod == 0o644
|
||||
del(template_parameters)
|
||||
|
||||
parameters = {'chmod': '600'}
|
||||
template_parameters = TemplateParameters(parameters, FILE)
|
||||
assert template_parameters.chmod == 0o600
|
||||
except Exception as error:
|
||||
pytest.fail('Unexpected exception: {0}'.
|
||||
format(str(error)))
|
@ -0,0 +1,2 @@
|
||||
{% calculate append = 'skip', name = 'test_root', chown = 'divanov:guest',
|
||||
action = 'install', path = test.test_root %}
|
@ -1,4 +1,8 @@
|
||||
{% calculate format = 'kde', action = 'install', package = 'kde' -%}
|
||||
{% calculate format = 'kde', action = 'install',
|
||||
package = 'xfce-base/xfce4-session' -%}
|
||||
{% set file_path = test.test_root + '/test_root/conf_dir'%}
|
||||
{% calculate path = file_path %}
|
||||
{% calculate merge = 'xfce-base/xfconf' %}
|
||||
[section][parts][of][section name]
|
||||
parameter 1 = {{ variables.variable_1 }}
|
||||
|
@ -1,3 +1,4 @@
|
||||
{% calculate name = 'subdir_1_folder', env='merge', chmod = 'rwxr-xr-x', action = 'install' -%}
|
||||
{% calculate package = 'xfce', merge = 'package_2' -%}
|
||||
{% calculate package = 'xfce-base/xfce4-panel', merge = 'xfce-base/xfce4-session' -%}
|
||||
{% calculate append = 'join' %}
|
||||
{% calculate not install.boolean -%}
|
@ -1,4 +1,5 @@
|
||||
{% calculate format='xml_xfce', mirror -%}
|
||||
{% calculate merge='xfce-base/xfconf' %}
|
||||
{% save custom.group.parameter = 'DoubleClickTime' -%}
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<channel name="xsettings" version="{{ version }}">
|
@ -0,0 +1,4 @@
|
||||
{% calculate name = 'important_dir', path = '/etc/folder/in_folder', action = 'install',
|
||||
package = 'media-sound/alsa-utils' -%}
|
||||
{% calculate install.version > 1.4 %}
|
||||
{% calculate merge.version < 1.2 -%}
|
@ -1,5 +1,5 @@
|
||||
{% calculate format = 'kde', path = '/etc/folder/in_folder', name = 'filename.conf' -%}
|
||||
{% calculate merge = 'any, xfce' -%}
|
||||
{% calculate merge = 'xfce-base/xfce4-panel' -%}
|
||||
# KDE or Plasma config file.
|
||||
# Part from Plasma
|
||||
[PlasmaViews][Panel 69][Horizontal1024]
|
@ -0,0 +1,3 @@
|
||||
{% calculate name = 'directory', path = '/etc/important_dir',
|
||||
package = 'xfce-base/xfconf' %}
|
||||
{% calculate action = 'install' %}
|
@ -1,4 +1,4 @@
|
||||
{% calculate name = 'important.conf', merge = 'kde', autoupdate -%}
|
||||
{% calculate name = 'important.conf', merge = 'xfce-base/xfce4-panel', autoupdate -%}
|
||||
relay_domains = {{ merge.calculate_domains }}
|
||||
|
||||
#Для создания базы используется postmap
|
@ -0,0 +1 @@
|
||||
{% calculate append = 'skip', action = 'install', chown = 'divanov:guest' %}
|
@ -0,0 +1 @@
|
||||
{% calculate append = 'join', name = 'test_root', path = test.test_root %}
|
@ -0,0 +1,2 @@
|
||||
{% calculate name = 'configuration_1', path = '/etc',
|
||||
package = 'xfce-extra/xfce4-clipman-plugin' %}
|
@ -1,5 +1,5 @@
|
||||
{% calculate name = 'template', format = 'bind', append = 'before' -%}
|
||||
{% calculate merge = 'package_2' -%}
|
||||
{% calculate merge = 'xfce-base/xfce4-panel' -%}
|
||||
acl "trusted" {
|
||||
{{ merge.ip_value }};
|
||||
10.0.0.0/8;
|
@ -0,0 +1,2 @@
|
||||
{% calculate name = 'config.d', path = '/etc/dir',
|
||||
package = 'xfce-extra/xfce4-screenshooter' %}
|
@ -1,4 +1,5 @@
|
||||
{% calculate name = 'wow_file.conf', force, format = 'samba', merge = 'kde' -%}
|
||||
{% calculate name = 'wow_file.conf', force, format = 'samba',
|
||||
merge = 'media-sound/alsa-utils, xfce-extra/xfce4-clipman-plugin' -%}
|
||||
[global]
|
||||
server role = standalone server
|
||||
hosts allow = 192.168.1. 192.168.2. 127.
|
@ -1 +0,0 @@
|
||||
{% calculate append="skip" %}
|
@ -1,4 +0,0 @@
|
||||
{% calculate name = 'important_dir', path = '/etc/folder/in_folder', action = 'install' -%}
|
||||
{% calculate install.version > 2.0 %}
|
||||
{% calculate package = 'kde' -%}
|
||||
{% calculate merge.version < 1.2 -%}
|
@ -1,2 +0,0 @@
|
||||
{% calculate name = 'directory', path = '/etc/important_dir', package = 'any' %}
|
||||
{% calculate action = 'install' %}
|
@ -1 +0,0 @@
|
||||
{% calculate append = 'skip', action = 'install' %}
|
@ -1 +0,0 @@
|
||||
{% calculate name = 'configuration_1', path = '/etc', package = 'package_1' %}
|
@ -1 +0,0 @@
|
||||
{% calculate name = 'config.d', path = '/etc/dir', package = 'package_2' %}
|
@ -0,0 +1,183 @@
|
||||
import pytest
|
||||
import os
|
||||
from calculate.utils.package import Package, PackageAtom, PackageAtomError
|
||||
from pprint import pprint
|
||||
from collections import OrderedDict
|
||||
import re
|
||||
|
||||
|
||||
BASE_DIRECTORY = os.path.join(os.getcwd(), 'tests/utils/testfiles/')
|
||||
|
||||
|
||||
@pytest.mark.package_utils
|
||||
class TestContents:
|
||||
def test_if_PackageContents_object_initialized_by_existing_package__it_contains_dictionary_of_items_from_contents_file(self):
|
||||
result = OrderedDict({
|
||||
'/usr':
|
||||
OrderedDict({'type': 'dir'}),
|
||||
'/usr/bin':
|
||||
OrderedDict({'type': 'dir'}),
|
||||
'/usr/bin/rview':
|
||||
OrderedDict({'type': 'sym',
|
||||
'target': 'vim',
|
||||
'mtime': '1573538053'}),
|
||||
'/usr/bin/rvim':
|
||||
OrderedDict({'type': 'sym',
|
||||
'target': 'vim',
|
||||
'mtime': '1573538053'}),
|
||||
'/usr/bin/vim':
|
||||
OrderedDict({'type': 'obj',
|
||||
'md5': '30acc0f256e11c1ecdb1bd80b688d238',
|
||||
'mtime': '1573538056'}),
|
||||
'/usr/bin/vimdiff':
|
||||
OrderedDict({'type': 'sym',
|
||||
'target': 'vim',
|
||||
'mtime': '1573538053'})})
|
||||
contents_object = Package('category_1/package_1',
|
||||
chroot_path=BASE_DIRECTORY)
|
||||
assert contents_object.contents_dictionary == result
|
||||
|
||||
def test_if_PackageContents_object_contains_contents_dictionary__it_renders_CONTENTS_file_correctly(self):
|
||||
contents_object = Package('category_1/package_1',
|
||||
chroot_path=BASE_DIRECTORY)
|
||||
result = '''dir /usr
|
||||
dir /usr/bin
|
||||
sym /usr/bin/rview -> vim 1573538053
|
||||
sym /usr/bin/rvim -> vim 1573538053
|
||||
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
|
||||
sym /usr/bin/vimdiff -> vim 1573538053
|
||||
'''
|
||||
assert contents_object.render_contents_file() == result
|
||||
|
||||
def test_if_new_directory_is_added_in_contents_file_using_add_dir_method__the_PackageContents_object_renders_the_contents_file_with_new_dir(self):
|
||||
contents_object = Package('category_1/package_1',
|
||||
chroot_path=BASE_DIRECTORY)
|
||||
result = '''dir /usr
|
||||
dir /usr/bin
|
||||
sym /usr/bin/rview -> vim 1573538053
|
||||
sym /usr/bin/rvim -> vim 1573538053
|
||||
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
|
||||
sym /usr/bin/vimdiff -> vim 1573538053
|
||||
dir /etc
|
||||
dir /etc/test_dir_1
|
||||
'''
|
||||
contents_object.add_dir('/etc/test_dir_1')
|
||||
assert contents_object.render_contents_file() == result
|
||||
|
||||
def test_if_new_object_is_added_in_contents_file_using_add_obj_method__the_PackageContents_object_renders_the_contents_file_with_new_obj(self):
|
||||
contents_object = Package('category_1/package_1',
|
||||
chroot_path=BASE_DIRECTORY)
|
||||
result = '''dir /usr
|
||||
dir /usr/bin
|
||||
sym /usr/bin/rview -> vim 1573538053
|
||||
sym /usr/bin/rvim -> vim 1573538053
|
||||
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
|
||||
sym /usr/bin/vimdiff -> vim 1573538053
|
||||
dir /etc
|
||||
dir /etc/test_dir_2
|
||||
obj /etc/test_dir_2/file_2.cfg a371f4d456d471ac0ed0e8befff1cb6d 1586531028
|
||||
'''
|
||||
contents_object.add_obj('/etc/test_dir_2/file_2.cfg')
|
||||
print('RESULT:')
|
||||
print(contents_object.render_contents_file())
|
||||
assert contents_object.render_contents_file() == result
|
||||
|
||||
def test_if_new_link_is_added_in_contents_file_using_add_sym_method__the_PackageContents_object_renders_the_contents_file_with_new_sym(self):
|
||||
contents_object = Package('category_1/package_1',
|
||||
chroot_path=BASE_DIRECTORY)
|
||||
result = '''dir /usr
|
||||
dir /usr/bin
|
||||
sym /usr/bin/rview -> vim 1573538053
|
||||
sym /usr/bin/rvim -> vim 1573538053
|
||||
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
|
||||
sym /usr/bin/vimdiff -> vim 1573538053
|
||||
dir /etc
|
||||
dir /etc/test_dir_2
|
||||
sym /etc/test_dir_2/symlink -> file_2.cfg 1587117567
|
||||
'''
|
||||
contents_object.add_sym('/etc/test_dir_2/symlink')
|
||||
print('RESULT:')
|
||||
print(contents_object.render_contents_file())
|
||||
assert contents_object.render_contents_file() == result
|
||||
|
||||
def test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_but_without_a_slot_and_use_flags__the_PackageAtom_object_contains_name_and_category_values(self):
|
||||
package_atom = PackageAtom()
|
||||
package_atom.parse_package_parameter('dev-lang/python-3.6')
|
||||
parsing_result = {
|
||||
'category': 'dev-lang',
|
||||
'contents': '/var/db/pkg/dev-lang/python-3.6.9/CONTENTS',
|
||||
'name': 'python-3.6.9'
|
||||
}
|
||||
assert package_atom._atom_dictionary == parsing_result
|
||||
|
||||
def test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_with_a_slot_value__the_PackageAtom_object_contains_name_category_values_and_slot_value(self):
|
||||
package_atom = PackageAtom()
|
||||
package_atom.parse_package_parameter('dev-lang/python-3.6:3.6/3.6m')
|
||||
parsing_result = {
|
||||
'category': 'dev-lang',
|
||||
'contents': '/var/db/pkg/dev-lang/python-3.6.9/CONTENTS',
|
||||
'name': 'python-3.6.9',
|
||||
'slot': '3.6/3.6m'
|
||||
}
|
||||
assert package_atom._atom_dictionary == parsing_result
|
||||
|
||||
def test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_with_an_empty_slot_value__the_PackageAtom_object_contains_name_category_values_and_slot_value(self):
|
||||
package_atom = PackageAtom()
|
||||
package_atom.parse_package_parameter('dev-lang/python-3.6:')
|
||||
parsing_result = {
|
||||
'category': 'dev-lang',
|
||||
'contents': '/var/db/pkg/dev-lang/python-3.6.9/CONTENTS',
|
||||
'name': 'python-3.6.9'
|
||||
}
|
||||
assert package_atom._atom_dictionary == parsing_result
|
||||
|
||||
def test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_with_a_uses_value__the_PackageAtom_object_contains_name_category_values_and_slot_value(self):
|
||||
package_atom = PackageAtom()
|
||||
package_atom.parse_package_parameter('dev-lang/python-3.6 abi_x86_64 ssl')
|
||||
parsing_result = {
|
||||
'category': 'dev-lang',
|
||||
'contents': '/var/db/pkg/dev-lang/python-3.6.9/CONTENTS',
|
||||
'name': 'python-3.6.9',
|
||||
'uses': ['abi_x86_64', 'ssl']
|
||||
}
|
||||
assert package_atom._atom_dictionary == parsing_result
|
||||
|
||||
def test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_and_add_slot_and_add_use_flags_is_set__the_PackageAtom_object_contains_name_category_slot_and_uses_values(self):
|
||||
package_atom = PackageAtom()
|
||||
package_atom.parse_package_parameter('dev-lang/python-3.6',
|
||||
add_slot=True,
|
||||
add_uses=True)
|
||||
parsing_result = {
|
||||
'category': 'dev-lang',
|
||||
'contents': '/var/db/pkg/dev-lang/python-3.6.9/CONTENTS',
|
||||
'name': 'python-3.6.9'
|
||||
}
|
||||
assert parsing_result
|
||||
|
||||
def test_if_the_PackageAtom_object_tried_to_parse_an_incorrect_package_atom_name__the_PackageAtom_object_throws_the_PackageAtomError_exception(self):
|
||||
package_atom = PackageAtom()
|
||||
with pytest.raises(PackageAtomError):
|
||||
package_atom.parse_package_parameter(
|
||||
'dev-lang/something_i_can_never_have:3.6/3.6m')
|
||||
|
||||
def test_if_the_PackageAtom_object_tried_to_parse_an_correct_package_atom_name_that_matches_multiple_packages__the_PackageAtom_object_throws_the_PackageAtomError_exception(self):
|
||||
package_atom = PackageAtom()
|
||||
with pytest.raises(PackageAtomError):
|
||||
package_atom.parse_package_parameter(
|
||||
'dev-lang/python')
|
||||
|
||||
def test_if_the_get_file_package_method_of_the_PackageAtom_object_is_called_with_a_name_of_a_file_that_belongs_to_any_package__the_PackageAtom_object_contains_dictionary_with_an_owner_package(self):
|
||||
package_atom = PackageAtom()
|
||||
package_atom_regex = re.compile(r'dev-lang/python-3.6.\d+')
|
||||
try:
|
||||
file_package = package_atom.get_file_package('/usr/bin/python3.6')
|
||||
assert package_atom_regex.search(file_package)
|
||||
except Exception as error:
|
||||
pytest.fail('Unexpected exception: {0}'.
|
||||
format(str(error)))
|
||||
|
||||
def test_if_the_get_file_package_method_of_the_PackageAtom_object_is_called_with_a_name_of_a_file_that_does_not_belong_to_any_package__the_PackageAtom_object_throws_the_PackageAtomError_exception(self):
|
||||
package_atom = PackageAtom()
|
||||
with pytest.raises(PackageAtomError):
|
||||
file_package = package_atom.get_file_package('/etc/shadow')
|
||||
print('package = {}'.format(file_package))
|
@ -0,0 +1 @@
|
||||
something
|
@ -0,0 +1 @@
|
||||
very important information...
|
@ -0,0 +1 @@
|
||||
file_2.cfg
|
@ -0,0 +1,6 @@
|
||||
dir /usr
|
||||
dir /usr/bin
|
||||
sym /usr/bin/rview -> vim 1573538053
|
||||
sym /usr/bin/rvim -> vim 1573538053
|
||||
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
|
||||
sym /usr/bin/vimdiff -> vim 1573538053
|
Loading…
Reference in new issue