Commits

Michał Górny committed 8b1eaf1

Introduce an interface and pkgcore implem for getting package maintainers.

Comments (0)

Files changed (2)

gentoopm/basepm/pkg.py

 		"""
 		pass
 
+class PMPackageMaintainer(ABCObject, StringCompat):
+	"""
+	A base class for a package maintainer.
+	"""
+
+	def __new__(self, email, name = None):
+		"""
+		Instantiate the actual string. Requires other props prepared
+		beforehand.
+
+		@param email: maintainer's e-mail address
+		@type email: string
+		@param name: maintainer's real name
+		@type name: string/C{None}
+		"""
+
+		ret = ['<%s>' % email]
+		if name is not None:
+			ret.insert(0, name)
+
+		ret = StringCompat.__new__(self, ' '.join(ret))
+		ret._name = name
+		ret._email = email
+		return ret
+
+	@property
+	def name(self):
+		"""
+		Maintainer's real name.
+
+		@type: string/C{None}
+		"""
+		return self._name
+
+	@property
+	def email(self):
+		"""
+		Maintainer's e-mail address.
+
+		@type: string
+		"""
+		return self._email
+
+	@abstractproperty
+	def description(self):
+		"""
+		Detailed maintainership description.
+
+		@type: string/C{None}
+		"""
+		pass
+
+class PMPackageHerd(PMPackageMaintainer):
+	"""
+	A helper class for herd maintainers.
+	"""
+
+	def __new__(self, name):
+		"""
+		Instantiate for the named herd.
+
+		@param name: name of the herd
+		@type name: string
+		"""
+		return PMPackageMaintainer.__new__(self,
+				'%s@gentoo.org' % name)
+
+	@property
+	def description(self):
+		return None
+
 class PMPackage(PMAtom, FillMissingComparisons):
 	"""
 	An abstract class representing a single, uniquely-identified package
 		pass
 
 	@abstractproperty
+	def maintainers(self):
+		"""
+		Get the package maintainer list.
+
+		@type: tuple(L{PMPackageMaintainer})
+		"""
+		pass
+
+	@abstractproperty
 	def slotted_atom(self):
 		"""
 		Return an atom matching all packages in the same slot as the package.

gentoopm/pkgcorepm/pkg.py

 
 from ..basepm.pkg import PMPackage, PMPackageDescription, \
 		PMInstalledPackage, PMInstallablePackage, PMBoundPackageKey, \
-		PMPackageState, PMUseFlag
+		PMPackageState, PMUseFlag, PMPackageMaintainer, PMPackageHerd
 from ..basepm.pkgset import PMPackageSet, PMFilteredPackageSet
 from ..util import SpaceSepTuple, SpaceSepFrozenSet
 
 			# XXX, incorrect flags?
 			return PkgCoreUseFlag(k, self._use)
 
+class PkgCorePackageMaintainer(PMPackageMaintainer):
+	def __new__(self, m):
+		ret = PMPackageMaintainer.__new__(self, m.email, m.name)
+		ret._m = m
+		return ret
+
+	@property
+	def description(self):
+		return self._m.description
+
+class PkgCorePackageHerd(PMPackageHerd):
+	pass
+
+class PkgCoreMaintainerTuple(tuple):
+	def __new__(self, maints, herds):
+		def _iter_maints():
+			for m in maints:
+				yield PkgCorePackageMaintainer(m)
+			for h in herds:
+				if h != 'no-herd':
+					yield PkgCorePackageHerd(h)
+
+		return tuple.__new__(self, _iter_maints())
+
 class PkgCorePackage(PMPackage, PkgCoreAtom):
 	def __init__(self, pkg, repo_index = 0):
 		self._pkg = pkg
 		return PkgCoreUseSet(self._pkg.iuse, self._pkg.use)
 
 	@property
+	def maintainers(self):
+		return PkgCoreMaintainerTuple(self._pkg.maintainers, self._pkg.herds)
+
+	@property
 	def slotted_atom(self):
 		return PkgCoreAtom(self._pkg.slotted_atom)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.