From f11d92bf8f36a21bd7615791cf2454863f65d09f Mon Sep 17 00:00:00 2001 From: Ivo De Decker Date: Wed, 6 Nov 2019 18:28:06 +0000 Subject: [PATCH] Add PackageId and BinaryPackageId objects --- britney2/__init__.py | 45 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/britney2/__init__.py b/britney2/__init__.py index 99b8573..639b38b 100644 --- a/britney2/__init__.py +++ b/britney2/__init__.py @@ -250,11 +250,46 @@ class SourcePackage(object): return getattr(self, self.__slots__[item]) -BinaryPackageId = namedtuple('BinaryPackageId', [ - 'package_name', - 'version', - 'architecture', -]) +class PackageId(namedtuple( + 'PackageId', + [ + 'package_name', + 'version', + 'architecture', + ])): + """Represent a source or binary package""" + + def __init__(self, package_name, version, architecture): + assert self.architecture != 'all', "all not allowed for PackageId (%s)" % (self.name) + + def __repr__(self): + return ('PID(%s)' % (self.name)) + + @property + def name(self): + if self.architecture == "source": + return ('%s/%s' % (self.package_name, self.version)) + else: + return ('%s/%s/%s' % (self.package_name, self.version, self.architecture)) + + @property + def uvname(self): + if self.architecture == "source": + return ('%s' % (self.package_name)) + else: + return ('%s/%s' % (self.package_name, self.architecture)) + + +class BinaryPackageId(PackageId): + """Represent a binary package""" + + def __init__(self, package_name, version, architecture): + assert self.architecture != 'source', "Source not allowed for BinaryPackageId (%s)" % (self.name) + super().__init__(package_name, version, architecture) + + def __repr__(self): + return ('BPID(%s)' % (self.name)) + BinaryPackage = namedtuple('BinaryPackage', [ 'version',