Commits

Michał Górny committed e91eb97

Portage: support simple USE collapsing.

Comments (0)

Files changed (2)

gentoopm/portagepm/depend.py

 from gentoopm.portagepm.atom import PortageAtom
 
 class PortageBaseDep(PMBaseDep):
-	def __init__(self, deps):
+	def __init__(self, deps, puse):
 		self._deps = deps
+		self._puse = puse
 
 	def __iter__(self):
 		it = iter(self._deps)
 		for d in it:
 			if d == '||':
-				yield PortageOneOfDep(next(it))
+				yield PortageOneOfDep(next(it), self._puse)
 			elif d == '&&':
-				yield PortageAllOfDep(next(it))
+				yield PortageAllOfDep(next(it), self._puse)
 			elif d.endswith('?'):
-				yield PortageConditionalUseDep(next(it))
+				yield PortageConditionalUseDep(next(it),
+						self._puse, d.rstrip('?'))
 			else:
 				yield PortageAtom(d)
 
 	pass
 
 class PortageConditionalUseDep(PMConditionalDep, PortageBaseDep):
+	def __init__(self, deps, puse, flag):
+		PortageBaseDep.__init__(self, deps, puse)
+		self._flag = flag
+
 	@property
 	def enabled(self):
-		# XXX
-		raise NotImplementedError()
+		return self._flag in self._puse
 
 class PortagePackageDepSet(PMPackageDepSet, PortageBaseDep):
-	def __init__(self, s):
-		self._deps = paren_reduce(s)
+	def __init__(self, s, puse):
+		PortageBaseDep.__init__(self, paren_reduce(s), puse)

gentoopm/portagepm/pkg.py

 		return _get_atom(str(self))
 
 	@property
+	def _applied_use(self):
+		class LazyUseGetter(object):
+			def __init__(self, dbapi, cpv):
+				self._cpv = cpv
+				self._dbapi = dbapi
+				self._settings = dbapi.settings
+				self._use_cache = None
+
+			@property
+			def _use_set(self):
+				if self._use_cache is None:
+					s = self._settings.__class__(clone = self._settings)
+					# XXX: repos? _emerge.Package or compatible API?
+					s.setcpv(self._cpv, mydb = self._dbapi)
+					self._use_cache = frozenset(s['PORTAGE_USE'].split())
+				return self._use_cache
+
+			def __iter__(self):
+				return iter(self._use_set)
+
+			def __contains__(self, k):
+				return k in self._use_set
+
+		return LazyUseGetter(self._dbapi, self._cpv)
+
+	@property
 	def build_dependencies(self):
-		return PortagePackageDepSet(self._aux_get('DEPEND'))
+		return PortagePackageDepSet(self._aux_get('DEPEND'),
+				self._applied_use)
 
 	@property
 	def run_dependencies(self):
-		return PortagePackageDepSet(self._aux_get('RDEPEND'))
+		return PortagePackageDepSet(self._aux_get('RDEPEND'),
+				self._applied_use)
 
 	@property
 	def post_dependencies(self):
-		return PortagePackageDepSet(self._aux_get('PDEPEND'))
+		return PortagePackageDepSet(self._aux_get('PDEPEND'),
+				self._applied_use)
 
 	def __str__(self):
 		return '=%s' % self._cpv