Commits

Michał Górny  committed 448e5a4

Introduce PMRequiredUseAtom type.

  • Participants
  • Parent commits 35ccdf9

Comments (0)

Files changed (6)

File gentoopm/basepm/depend.py

 
 from abc import abstractmethod, abstractproperty
 
-from gentoopm.util import ABCObject
+from gentoopm.util import ABCObject, StringCompat
+
+class PMRequiredUseAtom(StringCompat):
+	"""
+	An atom for C{REQUIRED_USE} specification.
+	"""
+
+	def __init__(self, s):
+		self._blocks = s.startswith('!')
+		if self._blocks:
+			s = s[1:]
+		self._flag = s
+
+	@property
+	def name(self):
+		"""
+		Relevant USE flag name.
+
+		@type: string
+		"""
+		return self._flag
+
+	@property
+	def blocking(self):
+		"""
+		Whether the atom blocks the USE flag (requires it not to be set).
+
+		@type: bool
+		"""
+		return self._blocks
+
+	@property
+	def requiring(self):
+		"""
+		Whether the atom requires the USE flag to be set.
+
+		@type: bool
+		"""
+		return not self._blocks
+
+	def __str__(self):
+		return '%s%s' % ('!' if self._blocks else '',
+				self.name)
 
 class PMBaseDep(ABCObject):
 	"""

File gentoopm/basepm/pkg.py

 		pass
 
 	@abstractproperty
+	def required_use(self):
+		"""
+		Get the C{REQUIRED_USE} specification.
+
+		@type: L{PMPackageDepSet}
+		"""
+		pass
+
+	@abstractproperty
 	def slotted(self):
 		"""
 		Return an atom matching all packages in the same slot as the associated

File gentoopm/paludispm/depend.py

 	def __iter__(self):
 		for d in self._deps:
 			if isinstance(d, paludis.PackageDepSpec):
+				assert(self._args.cls is None)
 				yield PaludisAtom(d, self._args.env)
 			elif isinstance(d, paludis.BlockDepSpec):
+				assert(self._args.cls is None)
 				yield PaludisAtom(d.blocking, self._args.env,
 						block = _block_re.match(d.text).group(0))
 			elif isinstance(d, paludis.AnyDepSpec):
 			elif isinstance(d, paludis.ConditionalDepSpec):
 				yield PaludisConditionalDep(d, self._args)
 			elif isinstance(d, paludis.PlainTextDepSpec):
-				# XXX: this is in REQUIRED_USE as well
-				yield str(d)
+				assert(self._args.cls is not None)
+				yield self._args.cls(str(d))
 			else:
 				raise NotImplementedError('Unable to parse %s' % repr(d))
 

File gentoopm/paludispm/pkg.py

 
 import paludis
 
+from gentoopm.basepm.depend import PMRequiredUseAtom
 from gentoopm.basepm.metadata import PMPackageMetadata
 from gentoopm.basepm.pkg import PMPackage, PMPackageDescription, \
 		PMInstallablePackage, PMInstalledPackage, PMBoundPackageKey, \
 		k = self._pkg.find_metadata('REQUIRED_USE')
 		if k is None:
 			return None
-		return PaludisPackageDepSet(k.parse_value(), self)
+		return PaludisPackageDepSet(k.parse_value(), self,
+				PMRequiredUseAtom)
 
 	@property
 	def use(self):

File gentoopm/pkgcorepm/depend.py

 from pkgcore.restrictions.values import ContainmentMatch
 
 from gentoopm.basepm.depend import PMPackageDepSet, PMConditionalDep, \
-	PMAnyOfDep, PMAllOfDep, PMExactlyOneOfDep, PMBaseDep
+	PMAnyOfDep, PMAllOfDep, PMExactlyOneOfDep, PMBaseDep, PMRequiredUseAtom
 from gentoopm.pkgcorepm.atom import PkgCoreAtom
 
 class PkgCoreBaseDep(PMBaseDep):
 				yield PkgCoreAtom(d)
 			elif isinstance(d, ContainmentMatch): # REQUIRED_USE
 				assert(len(d.vals) == 1)
-				yield next(iter(d.vals))
+				yield PMRequiredUseAtom(next(iter(d.vals)))
 			elif isinstance(d, OrRestriction):
 				yield PkgCoreAnyOfDep(d, self._pkg)
 			elif isinstance(d, AndRestriction):

File gentoopm/portagepm/pkg.py

 
 from portage.versions import cpv_getkey, cpv_getversion, vercmp
 
+from gentoopm.basepm.depend import PMRequiredUseAtom
 from gentoopm.basepm.metadata import PMPackageMetadata
 from gentoopm.basepm.pkg import PMPackage, PMPackageDescription, \
 		PMInstalledPackage, PMInstallablePackage, PMBoundPackageKey, \
 	@property
 	def required_use(self):
 		return PortagePackageDepSet(self._aux_get('REQUIRED_USE'),
-				self._applied_use, str) # XXX
+				self._applied_use, PMRequiredUseAtom)
 
 	def __str__(self):
 		return '=%s' % self._cpv