MigrationItem: calculate (uv)name

Caclulate the (uv)name of the items, instead of accepting it from other
functions.
ubuntu/rebased
Ivo De Decker 5 years ago
parent 5dc892ae8f
commit 76dc7cc0d2

@ -19,17 +19,45 @@ from britney2 import SuiteClass
class MigrationItem(object): class MigrationItem(object):
def __init__(self, package=None, version=None, architecture=None, uvname=None, suite=None, is_cruft_removal=False): def __init__(self, package=None, version=None, architecture=None,
self._uvname = uvname suite=None, is_removal=False, is_cruft_removal=False):
if architecture is None:
architecture = 'source'
if is_cruft_removal:
is_removal = True
self._package = package self._package = package
self._version = version self._version = version
self._architecture = architecture self._architecture = architecture
self._suite = suite self._suite = suite
self._is_removal = is_removal
self._is_cruft_removal = is_cruft_removal self._is_cruft_removal = is_cruft_removal
if version is not None: self._uvname = self.get_uvname()
self._name = "%s/%s" % (uvname, version) self._name = self.get_name()
else:
self._name = uvname def get_name(self):
name = self._package
if self._architecture != "source":
name = "%s/%s" % (name, self._architecture)
if self._version:
name = "%s/%s" % (name, self._version)
if self._suite.excuses_suffix:
name = "%s_%s" % (name, self._suite.excuses_suffix)
if self._is_removal:
name = "-%s" % (name)
return name
def get_uvname(self):
name = self._package
if self._architecture != "source":
name = "%s/%s" % (name, self._architecture)
if self._suite.excuses_suffix:
name = "%s_%s" % (name, self._suite.excuses_suffix)
if self._is_removal:
name = "-%s" % (name)
return name
def __str__(self): def __str__(self):
if self.version is not None: if self.version is not None:
@ -59,7 +87,7 @@ class MigrationItem(object):
@property @property
def is_removal(self): def is_removal(self):
return self._name.startswith('-') return self._is_removal
@property @property
def architecture(self): def architecture(self):
@ -95,11 +123,9 @@ class MigrationItemFactory(object):
self.logger = logging.getLogger(logger_name) self.logger = logging.getLogger(logger_name)
def generate_removal_for_cruft_item(self, pkg_id): def generate_removal_for_cruft_item(self, pkg_id):
uvname = "-%s/%s" % (pkg_id.package_name, pkg_id.architecture)
return MigrationItem(package=pkg_id.package_name, return MigrationItem(package=pkg_id.package_name,
version=pkg_id.version, version=pkg_id.version,
architecture=pkg_id.architecture, architecture=pkg_id.architecture,
uvname=uvname,
suite=self._suites.target_suite, suite=self._suites.target_suite,
is_cruft_removal=True, is_cruft_removal=True,
) )
@ -181,27 +207,12 @@ class MigrationItemFactory(object):
else: else:
suite = self._find_suite_for_item(suites, suite_name, package_name, version, auto_correct) suite = self._find_suite_for_item(suites, suite_name, package_name, version, auto_correct)
uvname = self._canonicalise_uvname(item_text, package_name, architecture, suite, is_removal)
return MigrationItem(package=package_name, return MigrationItem(package=package_name,
version=version, version=version,
architecture=architecture, architecture=architecture,
uvname=uvname,
suite=suite, suite=suite,
is_removal=is_removal,
) )
def parse_items(self, *args, **kwargs): def parse_items(self, *args, **kwargs):
return [self.parse_item(x, **kwargs) for x in args] return [self.parse_item(x, **kwargs) for x in args]
@staticmethod
def _canonicalise_uvname(item_text_sans_removal, package, architecture, suite, is_removal):
parts = item_text_sans_removal.split('/', 3)
if len(parts) == 1 or architecture == 'source':
uvname = package
else:
uvname = "%s/%s" % (package, architecture)
if suite.suite_class.is_additional_source:
uvname = '%s_%s' % (uvname, suite.suite_short_name)
if is_removal:
uvname = '-%s' % (uvname)
return uvname

Loading…
Cancel
Save