Michał Górny avatar Michał Górny committed 1e63873

Support getting hidden USEflags explicitly.

Comments (0)

Files changed (4)

gentoopm/basepm/pkg.py

 	@abstractproperty
 	def use(self):
 		"""
-		Get the list of USE flags applying to the ebuild.
+		Get the list of USE flags applying to the ebuild. Iterating over the
+		list should return only the explicitly listed flags (C{IUSE}), though
+		it is also possible to explicitly get other flags (using indexing)
+		applying to the ebuild.
 
 		@type: L{SpaceSepFrozenSet}(L{PMUseFlag})
 		"""

gentoopm/paludispm/pkg.py

 
 class PaludisChoiceSet(SpaceSepFrozenSet):
 	def __new__(self, choices):
-		l = []
-		for group in choices:
-			if group.raw_name == 'build_options': # paludis specific
-				continue
-			for c in group:
-				if c.explicitly_listed:
-					l.append(PaludisChoice(c))
-		return SpaceSepFrozenSet.__new__(self, l)
+		def _get_iuse():
+			for group in choices:
+				if group.raw_name == 'build_options': # paludis specific
+					continue
+				for c in group:
+					if c.explicitly_listed:
+						yield PaludisChoice(c)
+
+		self._choices = choices
+		return SpaceSepFrozenSet.__new__(self, _get_iuse())
+
+	def __getitem__(self, k):
+		try:
+			return SpaceSepFrozenSet.__getitem__(self, k)
+		except KeyError:
+			for group in self._choices:
+				for c in group:
+					if str(c.name_with_prefix) == k:
+						return PaludisChoice(c)
+			raise
 
 class PaludisID(PMPackage, PaludisAtom):
 	def __init__(self, pkg, env):

gentoopm/pkgcorepm/pkg.py

 		self._use = use
 		return SpaceSepFrozenSet.__new__(self, _get_iuse())
 
+	def __getitem__(self, k):
+		try:
+			return SpaceSepFrozenSet.__getitem__(self, k)
+		except KeyError:
+			# XXX, incorrect flags?
+			return PkgCoreUseFlag(k, self._use)
+
 class PkgCorePackage(PMPackage, PkgCoreAtom):
 	def __init__(self, pkg, repo_index = 0):
 		self._pkg = pkg

gentoopm/portagepm/pkg.py

 		self._use = use
 		return SpaceSepFrozenSet.__new__(self, _get_iuse())
 
+	def __getitem__(self, k):
+		try:
+			return SpaceSepFrozenSet.__getitem__(self, k)
+		except KeyError:
+			# XXX, incorrect flags?
+			return PortageUseFlag(k, self._use)
+
 class PortageDBCPV(PMPackage, CompletePortageAtom):
 	def __init__(self, cpv, dbapi):
 		self._cpv = cpv
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.