|
|
|
@ -43,7 +43,11 @@ class Version:
|
|
|
|
|
"Can't initialize Version object using '{0}'"
|
|
|
|
|
" value with type {1}".format(version_value,
|
|
|
|
|
type(version_value)))
|
|
|
|
|
self._version_string = str(version_value)
|
|
|
|
|
if isinstance(version_value, str):
|
|
|
|
|
self._version_string = version_value.strip('-')
|
|
|
|
|
else:
|
|
|
|
|
self._version_string = str(version_value)
|
|
|
|
|
|
|
|
|
|
self._version_value = value
|
|
|
|
|
|
|
|
|
|
def _get_version_value(self, version):
|
|
|
|
@ -60,6 +64,7 @@ class Version:
|
|
|
|
|
version_value.append(int(version_part.strip()))
|
|
|
|
|
|
|
|
|
|
elif isinstance(version, str):
|
|
|
|
|
version = version.strip('-')
|
|
|
|
|
version_value = []
|
|
|
|
|
|
|
|
|
|
if '-' in version:
|
|
|
|
@ -93,8 +98,20 @@ class Version:
|
|
|
|
|
version_value.append(0)
|
|
|
|
|
|
|
|
|
|
for lvalue, rvalue in zip(version_value, other_value):
|
|
|
|
|
if lvalue == rvalue:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if compare_operator(lvalue, rvalue):
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
if (compare_operator != operator.lt and
|
|
|
|
|
compare_operator != operator.gt and
|
|
|
|
|
compare_operator != operator.ne):
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def __lt__(self, other):
|
|
|
|
|
'''Перегрузка x < y.'''
|
|
|
|
@ -174,43 +191,63 @@ class Version:
|
|
|
|
|
|
|
|
|
|
class PackageAtomName:
|
|
|
|
|
def __init__(self, atom_dictionary):
|
|
|
|
|
self._atom_dictionary = atom_dictionary
|
|
|
|
|
self._package_directory = atom_dictionary['pkg_path']
|
|
|
|
|
self._version = atom_dictionary['version']
|
|
|
|
|
|
|
|
|
|
def __getattr__(self, name):
|
|
|
|
|
if name in self._atom_dictionary:
|
|
|
|
|
return self._atom_dictionary[name]
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
@property
|
|
|
|
|
def name(self):
|
|
|
|
|
return os.path.basename(self._package_directory)
|
|
|
|
|
|
|
|
|
|
def __getitem__(self, key):
|
|
|
|
|
if key in self._atom_dictionary:
|
|
|
|
|
return self._atom_dictionary[key]
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
@property
|
|
|
|
|
def category(self):
|
|
|
|
|
return os.path.basename(os.path.dirname(self._package_directory))
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def version(self):
|
|
|
|
|
return self._version
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def use_flags(self):
|
|
|
|
|
use_path = os.path.join(self._package_directory, '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))
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def pkg_path(self):
|
|
|
|
|
return self._package_directory
|
|
|
|
|
|
|
|
|
|
def __setitem__(self, key, value):
|
|
|
|
|
self._atom_dictionary[key] = value
|
|
|
|
|
@property
|
|
|
|
|
def slot(self):
|
|
|
|
|
slot_path = os.path.join(self._package_directory, '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 __eq__(self, other):
|
|
|
|
|
if isinstance(other, PackageAtomName):
|
|
|
|
|
return (self._atom_dictionary['contents'] ==
|
|
|
|
|
other._atom_dictionary.contents)
|
|
|
|
|
elif isinstance(other, dict):
|
|
|
|
|
return self._atom_dictionary['contents'] == other['contents']
|
|
|
|
|
return (self._package_directory ==
|
|
|
|
|
other._package_directory)
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def __ne__(self, other):
|
|
|
|
|
if isinstance(other, PackageAtomName):
|
|
|
|
|
return (self._atom_dictionary['contents'] !=
|
|
|
|
|
other._atom_dictionary.contents)
|
|
|
|
|
elif isinstance(other, dict):
|
|
|
|
|
return self._atom_dictionary['contents'] != other['contents']
|
|
|
|
|
return (self._package_directory !=
|
|
|
|
|
other._package_directory)
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def __bool__(self):
|
|
|
|
|
return bool(self._atom_dictionary)
|
|
|
|
|
return bool(self._package_directory)
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
return '<PackageAtomName: {}/{}>'.format(self.category,
|
|
|
|
|
self.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PackageAtomParser:
|
|
|
|
@ -238,8 +275,6 @@ class PackageAtomParser:
|
|
|
|
|
self._atom_dictionary = {}
|
|
|
|
|
|
|
|
|
|
parsing_result = self.atom_regex.search(package_atom)
|
|
|
|
|
print('pkg_path = {}'.format(self.pkg_path))
|
|
|
|
|
print('parsing result: {}'.format(parsing_result.groupdict()))
|
|
|
|
|
|
|
|
|
|
if (not parsing_result or parsing_result.string != package_atom or
|
|
|
|
|
not parsing_result.groupdict()['category'] or
|
|
|
|
@ -257,7 +292,6 @@ class PackageAtomParser:
|
|
|
|
|
version_value = parsing_result.groupdict()['version'].strip('-')
|
|
|
|
|
|
|
|
|
|
self._atom_dictionary['version'] = Version(version_value)
|
|
|
|
|
print('version = {}'.format(version_value))
|
|
|
|
|
|
|
|
|
|
if (parsing_result.groupdict()['slot'] and
|
|
|
|
|
parsing_result.groupdict()['slot'] != ':'):
|
|
|
|
@ -274,6 +308,10 @@ class PackageAtomParser:
|
|
|
|
|
|
|
|
|
|
self._check_package_existance()
|
|
|
|
|
|
|
|
|
|
atom_name_object = PackageAtomName(self._atom_dictionary)
|
|
|
|
|
self._atom_dictionary.clear()
|
|
|
|
|
return atom_name_object
|
|
|
|
|
|
|
|
|
|
def _check_package_existance(self, package_atom=''):
|
|
|
|
|
if package_atom:
|
|
|
|
|
self.parse_package_parameter(package_atom)
|
|
|
|
@ -286,11 +324,6 @@ class PackageAtomParser:
|
|
|
|
|
full_name = self._atom_dictionary['name']
|
|
|
|
|
|
|
|
|
|
if 'version' not in self._atom_dictionary:
|
|
|
|
|
print('contents_path:')
|
|
|
|
|
print(r'{0}/{1}/{2}-[0-9]*/CONTENTS'.format(
|
|
|
|
|
self.pkg_path,
|
|
|
|
|
self._atom_dictionary['category'],
|
|
|
|
|
full_name))
|
|
|
|
|
glob_result = glob.glob(
|
|
|
|
|
r'{0}/{1}/{2}-[0-9]*/CONTENTS'.format(
|
|
|
|
|
self.pkg_path,
|
|
|
|
@ -304,32 +337,34 @@ class PackageAtomParser:
|
|
|
|
|
full_name))
|
|
|
|
|
|
|
|
|
|
if not glob_result:
|
|
|
|
|
print('glob is empty')
|
|
|
|
|
raise PackageAtomError("Package from 'package' parameter value"
|
|
|
|
|
" '{}' does not exist".format(
|
|
|
|
|
self.package_atom),
|
|
|
|
|
errno=NOTEXIST)
|
|
|
|
|
|
|
|
|
|
if len(glob_result) == 1:
|
|
|
|
|
contents_path = next(iter(glob_result))
|
|
|
|
|
self._check_slot_value(contents_path)
|
|
|
|
|
self._check_use_flags_value(contents_path)
|
|
|
|
|
|
|
|
|
|
self._atom_dictionary['name'] = contents_path.split('/')[-2]
|
|
|
|
|
self._atom_dictionary['contents'] = contents_path
|
|
|
|
|
pkg_path = os.path.dirname(next(iter(glob_result)))
|
|
|
|
|
self._check_slot_value(pkg_path)
|
|
|
|
|
self._check_use_flags_value(pkg_path)
|
|
|
|
|
|
|
|
|
|
parsed_name = self._atom_dictionary['name']
|
|
|
|
|
full_name = os.path.basename(pkg_path)
|
|
|
|
|
self._atom_dictionary['version'] = Version(
|
|
|
|
|
full_name[len(parsed_name):])
|
|
|
|
|
self._atom_dictionary['pkg_path'] = pkg_path
|
|
|
|
|
else:
|
|
|
|
|
packages = dict()
|
|
|
|
|
for contents_path in glob_result:
|
|
|
|
|
package_info = dict()
|
|
|
|
|
pkg_path = os.path.dirname(contents_path)
|
|
|
|
|
try:
|
|
|
|
|
self._check_slot_value(contents_path)
|
|
|
|
|
self._check_use_flags_value(contents_path)
|
|
|
|
|
package_info['name'] = contents_path.split('/')[-2]
|
|
|
|
|
package_info['version'] = Version(
|
|
|
|
|
package_info['name'].split('-', 1)[1])
|
|
|
|
|
self._check_slot_value(pkg_path)
|
|
|
|
|
self._check_use_flags_value(pkg_path)
|
|
|
|
|
parsed_name = self._atom_dictionary['name']
|
|
|
|
|
full_name = os.path.basename(pkg_path)
|
|
|
|
|
packages[pkg_path] = Version(
|
|
|
|
|
full_name[len(parsed_name):])
|
|
|
|
|
except PackageAtomError:
|
|
|
|
|
continue
|
|
|
|
|
packages[contents_path] = package_info
|
|
|
|
|
|
|
|
|
|
if not packages:
|
|
|
|
|
raise PackageAtomError(
|
|
|
|
@ -339,19 +374,19 @@ class PackageAtomParser:
|
|
|
|
|
errno=NOTEXIST)
|
|
|
|
|
|
|
|
|
|
if len(packages) == 1:
|
|
|
|
|
contents_path = next(iter(packages.keys()))
|
|
|
|
|
self._atom_dictionary['contents'] = contents_path
|
|
|
|
|
self._atom_dictionary.update(packages[contents_path])
|
|
|
|
|
pkg_path = next(iter(packages.keys()))
|
|
|
|
|
self._atom_dictionary['pkg_path'] = pkg_path
|
|
|
|
|
self._atom_dictionary['version'] = packages[pkg_path]
|
|
|
|
|
else:
|
|
|
|
|
contents_path = sorted(
|
|
|
|
|
packages.keys(),
|
|
|
|
|
key=lambda path: packages[path]['version'])[-1]
|
|
|
|
|
self._atom_dictionary['contents'] = contents_path
|
|
|
|
|
self._atom_dictionary.update(packages[contents_path])
|
|
|
|
|
# Берем старшую версию.
|
|
|
|
|
pkg_path = sorted(packages.keys(),
|
|
|
|
|
key=lambda path: packages[path])[-1]
|
|
|
|
|
self._atom_dictionary['pkg_path'] = pkg_path
|
|
|
|
|
self._atom_dictionary['version'] = packages[pkg_path]
|
|
|
|
|
|
|
|
|
|
def _check_slot_value(self, contents_path):
|
|
|
|
|
def _check_slot_value(self, pkg_path):
|
|
|
|
|
if 'slot' in self._atom_dictionary:
|
|
|
|
|
slot = self._get_slot_value(contents_path)
|
|
|
|
|
slot = self._get_slot_value(pkg_path)
|
|
|
|
|
|
|
|
|
|
if slot != self._atom_dictionary['slot']:
|
|
|
|
|
raise PackageAtomError("Package from 'package' parameter value"
|
|
|
|
@ -359,9 +394,9 @@ class PackageAtomParser:
|
|
|
|
|
self.package_atom),
|
|
|
|
|
errno=NOTEXIST)
|
|
|
|
|
|
|
|
|
|
def _check_use_flags_value(self, contents_path):
|
|
|
|
|
def _check_use_flags_value(self, pkg_path):
|
|
|
|
|
if 'use_flags' in self._atom_dictionary:
|
|
|
|
|
use_flags = self._get_use_flags_value(contents_path)
|
|
|
|
|
use_flags = self._get_use_flags_value(pkg_path)
|
|
|
|
|
|
|
|
|
|
for use_flag in self._atom_dictionary['use_flags']:
|
|
|
|
|
if use_flag not in use_flags:
|
|
|
|
@ -371,16 +406,16 @@ class PackageAtomParser:
|
|
|
|
|
self.package_atom),
|
|
|
|
|
errno=NOTEXIST)
|
|
|
|
|
|
|
|
|
|
def _get_slot_value(self, contents_path):
|
|
|
|
|
slot_path = os.path.join(os.path.dirname(contents_path), 'SLOT')
|
|
|
|
|
def _get_slot_value(self, pkg_path):
|
|
|
|
|
slot_path = os.path.join(pkg_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):
|
|
|
|
|
use_path = os.path.join(os.path.dirname(contents_path), 'USE')
|
|
|
|
|
def _get_use_flags_value(self, pkg_path):
|
|
|
|
|
use_path = os.path.join(pkg_path, 'USE')
|
|
|
|
|
try:
|
|
|
|
|
return read_file(use_path).strip('\n').split(' ')
|
|
|
|
|
except FilesError:
|
|
|
|
@ -464,25 +499,11 @@ class Package:
|
|
|
|
|
def __init__(self, package_atom, pkg_path='/var/db/pkg', chroot_path='/'):
|
|
|
|
|
self.chroot_path = chroot_path
|
|
|
|
|
|
|
|
|
|
self._get_package_atom(package_atom)
|
|
|
|
|
|
|
|
|
|
if 'contents' in self._atom_dictionary:
|
|
|
|
|
self.contents_file_path = self._atom_dictionary['contents']
|
|
|
|
|
else:
|
|
|
|
|
if ('name' in self._atom_dictionary and
|
|
|
|
|
'category' in self._atom_dictionary):
|
|
|
|
|
self.contents_file_path = '{0}/{1}/{2}'.format(
|
|
|
|
|
pkg_path,
|
|
|
|
|
self._atom_dictionary['category'],
|
|
|
|
|
self._atom_dictionary['name'])
|
|
|
|
|
if chroot_path != '/':
|
|
|
|
|
self.contents_file_path = join_paths(
|
|
|
|
|
chroot_path,
|
|
|
|
|
self.contents_file_path)
|
|
|
|
|
else:
|
|
|
|
|
raise PackageError(
|
|
|
|
|
"Incorrect 'pakage_atom' value: '{}', type: '{}'".
|
|
|
|
|
format(package_atom, type(package_atom)))
|
|
|
|
|
self.contents_file_path = self._get_contents_path(package_atom)
|
|
|
|
|
if (chroot_path != '/' and
|
|
|
|
|
not self.contents_file_path.startswith(chroot_path)):
|
|
|
|
|
self.contents_file_path = join_paths(chroot_path,
|
|
|
|
|
self.contents_file_path)
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(self.contents_file_path):
|
|
|
|
|
raise PackageError("Can not find CONTENTS file in path: {}".format(
|
|
|
|
@ -491,17 +512,17 @@ class Package:
|
|
|
|
|
self.contents_dictionary = OrderedDict()
|
|
|
|
|
self.read_contents_file()
|
|
|
|
|
|
|
|
|
|
def _get_package_atom(self, package_atom):
|
|
|
|
|
print('in get package: {}'.format(package_atom))
|
|
|
|
|
def _get_contents_path(self, package_atom):
|
|
|
|
|
if isinstance(package_atom, str):
|
|
|
|
|
package_atom_parser = PackageAtomParser(
|
|
|
|
|
chroot_path=self.chroot_path)
|
|
|
|
|
package_atom_parser.parse_package_parameter(package_atom)
|
|
|
|
|
self._atom_dictionary = package_atom_parser.atom_dictionary
|
|
|
|
|
elif isinstance(package_atom, PackageAtomParser):
|
|
|
|
|
self._atom_dictionary = package_atom._atom_dictionary
|
|
|
|
|
elif isinstance(package_atom, dict):
|
|
|
|
|
self._atom_dictionary = package_atom
|
|
|
|
|
atom_name = package_atom_parser.parse_package_parameter(
|
|
|
|
|
package_atom)
|
|
|
|
|
return os.path.join(atom_name.pkg_path,
|
|
|
|
|
'CONTENTS')
|
|
|
|
|
if isinstance(package_atom, PackageAtomName):
|
|
|
|
|
return os.path.join(package_atom.pkg_path,
|
|
|
|
|
'CONTENTS')
|
|
|
|
|
else:
|
|
|
|
|
raise PackageError(
|
|
|
|
|
"Incorrect 'pakage_atom' value: '{}', type: '{}''".
|
|
|
|
|