Commits

Michał Górny committed 5d0ad77

Portage: support REQUIRED_USE.

Comments (0)

Files changed (2)

gentoopm/portagepm/depend.py

 # (c) 2011 Michał Górny <mgorny@gentoo.org>
 # Released under the terms of the 2-clause BSD license.
 
+from collections import namedtuple
 from portage.dep import paren_reduce, use_reduce
 
 from gentoopm.basepm.depend import PMPackageDepSet, PMConditionalDep, \
 	PMAnyOfDep, PMAllOfDep, PMExactlyOneOfDep, PMBaseDep
-from gentoopm.portagepm.atom import PortageAtom
 
 class PortageBaseDep(PMBaseDep):
-	def __init__(self, deps, puse):
+	def __init__(self, deps, args):
 		self._deps = deps
-		self._puse = puse
+		self._args = args
 
 	def __iter__(self):
 		it = iter(self._deps)
 		for d in it:
 			if d == '||':
-				yield PortageAnyOfDep(next(it), self._puse)
+				yield PortageAnyOfDep(next(it), self._args)
 			elif d == '&&':
-				yield PortageAllOfDep(next(it), self._puse)
+				yield PortageAllOfDep(next(it), self._args)
 			elif d == '__xor__?':
-				yield PortageExactlyOneOfDep(next(it), self._puse)
+				yield PortageExactlyOneOfDep(next(it), self._args)
 			elif d.endswith('?'):
 				yield PortageConditionalUseDep(next(it),
-						self._puse, d.rstrip('?'))
+						self._args, d.rstrip('?'))
 			else:
-				yield PortageAtom(d)
+				yield self._args.cls(d)
 
 class PortageAnyOfDep(PMAnyOfDep, PortageBaseDep):
 	pass
 	pass
 
 class PortageConditionalUseDep(PMConditionalDep, PortageBaseDep):
-	def __init__(self, deps, puse, flag):
-		PortageBaseDep.__init__(self, deps, puse)
+	def __init__(self, deps, args, flag):
+		PortageBaseDep.__init__(self, deps, args)
 		self._flag = flag
 
 	@property
 	def enabled(self):
-		return self._flag in self._puse
+		return self._flag in self._args.puse
+
+_argtuple = namedtuple('PortageDepArgTuple', ('puse', 'cls'))
 
 class PortagePackageDepSet(PMPackageDepSet, PortageBaseDep):
-	def __init__(self, s, puse):
+	def __init__(self, s, *args):
 		self._use_reducable = not '^^' in s
-		if not self._use_reducable:
-			# ARGV, paren_reduce() doesn't handle ^^
-			# so we hack it to a __xor__?, UGLY!
-			self._depstr = s.replace('^^', '__xor__?')
-		PortageBaseDep.__init__(self, None, puse)
+		# ARGV, paren_reduce() doesn't handle ^^
+		# so we hack it to a __xor__?, UGLY!
+		self._depstr = s.replace('^^', '__xor__?')
+		PortageBaseDep.__init__(self, None, _argtuple(*args))
 
 	def __iter__(self):
 		if self._deps is None:
 	def without_conditionals(self):
 		if self._use_reducable:
 			return PortageUncondAllOfDep(
-					use_reduce(self._depstr, self._puse))
+					use_reduce(self._depstr, self._args.puse),
+					self._args)
 		return PMPackageDepSet.without_conditionals.fget(self)
 
 class PortageUncondDep(PortageBaseDep):
-	def __init__(self, deps):
-		self._deps = deps
-
 	@property
 	def without_conditionals(self):
 		return self
 		it = iter(self._deps)
 		for d in it:
 			if d == '||':
-				yield PortageUncondAnyOfDep(next(it))
+				yield PortageUncondAnyOfDep(next(it), self._args)
 			elif d == '&&':
-				yield PortageUncondAllOfDep(next(it))
+				yield PortageUncondAllOfDep(next(it), self._args)
 			else:
-				yield PortageAtom(d)
+				yield self._args.cls(d)
 
 class PortageUncondAnyOfDep(PMAnyOfDep, PortageUncondDep):
 	pass

gentoopm/portagepm/pkg.py

 	@property
 	def build_dependencies(self):
 		return PortagePackageDepSet(self._aux_get('DEPEND'),
-				self._applied_use)
+				self._applied_use, PortageAtom)
 
 	@property
 	def run_dependencies(self):
 		return PortagePackageDepSet(self._aux_get('RDEPEND'),
-				self._applied_use)
+				self._applied_use, PortageAtom)
 
 	@property
 	def post_dependencies(self):
 		return PortagePackageDepSet(self._aux_get('PDEPEND'),
-				self._applied_use)
+				self._applied_use, PortageAtom)
 
 	@property
 	def required_use(self):
 		return PortagePackageDepSet(self._aux_get('REQUIRED_USE'),
-				self._applied_use)
+				self._applied_use, str) # XXX
 
 	def __str__(self):
 		return '=%s' % self._cpv