Commits

Michał Górny committed 47fd2cb

Support checking whether a USEflag is enabled.

Comments (0)

Files changed (4)

gentoopm/basepm/pkg.py

 		"""
 		return self._name
 
+	@abstractproperty
+	def enabled(self):
+		"""
+		Whether the flag is enabled.
+
+		@type: bool
+		"""
+		pass
+
 	def __str__(self):
 		return self.name
 
 	@abstractproperty
 	def use(self):
 		"""
-		Get the list of USE flags declared in the ebuild (C{IUSE}).
+		Get the list of USE flags applying to the ebuild.
 
 		@type: L{SpaceSepFrozenSet}(L{PMUseFlag})
 		"""

gentoopm/paludispm/pkg.py

 	def name(self):
 		return str(self._c.name_with_prefix)
 
+	@property
+	def enabled(self):
+		return self._c.enabled
+
 class PaludisChoiceSet(SpaceSepFrozenSet):
 	def __new__(self, choices):
 		l = []

gentoopm/pkgcorepm/pkg.py

 			return None
 
 class PkgCoreUseFlag(PMUseFlag):
-	pass
+	def __init__(self, s, enabled_use):
+		PMUseFlag.__init__(self, s)
+		self._enabled = self.name in enabled_use
+
+	@property
+	def enabled(self):
+		return self._enabled
+
+class PkgCoreUseSet(SpaceSepFrozenSet):
+	def __new__(self, iuse, use):
+		def _get_iuse():
+			for u in iuse:
+				yield PkgCoreUseFlag(u, use)
+
+		self._use = use
+		return SpaceSepFrozenSet.__new__(self, _get_iuse())
 
 class PkgCorePackage(PMPackage, PkgCoreAtom):
 	def __init__(self, pkg, repo_index = 0):
 
 	@property
 	def use(self):
-		return SpaceSepFrozenSet([PkgCoreUseFlag(x) for x in self._pkg.iuse])
+		return PkgCoreUseSet(self._pkg.iuse, self._pkg.use)
 
 	@property
 	def slotted(self):

gentoopm/portagepm/pkg.py

 		return None # XXX
 
 class PortageUseFlag(PMUseFlag):
-	pass
+	def __init__(self, s, enabled_use):
+		PMUseFlag.__init__(self, s)
+		self._enabled = self.name in enabled_use
+
+	@property
+	def enabled(self):
+		return self._enabled
+
+class PortageUseSet(SpaceSepFrozenSet):
+	def __new__(self, iuse, use):
+		def _get_iuse():
+			for u in iuse:
+				yield PortageUseFlag(u, use)
+
+		self._use = use
+		return SpaceSepFrozenSet.__new__(self, _get_iuse())
 
 class PortageDBCPV(PMPackage, CompletePortageAtom):
 	def __init__(self, cpv, dbapi):
 
 	@property
 	def use(self):
-		return SpaceSepFrozenSet([PortageUseFlag(x) for x \
-				in self._aux_get('IUSE').split()])
+		return PortageUseSet(self._aux_get('IUSE').split(),
+				self._applied_use)
 
 	@property
 	def slotted(self):