Michał Górny committed 00be1d0

Portage: support dropping conditionals using use_reduce().

Comments (0)

Files changed (1)


 # (c) 2011 Michał Górny <>
 # Released under the terms of the 2-clause BSD license.
-from portage.dep import paren_reduce
+from portage.dep import paren_reduce, use_reduce
 from gentoopm.basepm.depend import PMPackageDepSet, PMConditionalDep, \
 	PMOneOfDep, PMAllOfDep, PMBaseDep
 class PortagePackageDepSet(PMPackageDepSet, PortageBaseDep):
 	def __init__(self, s, puse):
-		PortageBaseDep.__init__(self, paren_reduce(s), puse)
+		self._depstr = s
+		PortageBaseDep.__init__(self, None, puse)
+	def __iter__(self):
+		if self._deps is None:
+			self._deps = paren_reduce(self._depstr)
+		return PortageBaseDep.__iter__(self)
+	@property
+	def without_conditionals(self):
+		return PortageUncondPackageDepSet(
+				use_reduce(self._depstr, self._puse))
+class PortageUncondDep(PortageBaseDep):
+	def __init__(self, deps):
+		self._deps = deps
+	@property
+	def without_conditionals(self):
+		return self
+	def __iter__(self):
+		it = iter(self._deps)
+		for d in it:
+			if d == '||':
+				yield PortageUncondOneOfDep(next(it))
+			elif d == '&&':
+				yield PortageUncondAllOfDep(next(it))
+			else:
+				yield PortageAtom(d)
+class PortageUncondOneOfDep(PMOneOfDep, PortageUncondDep):
+	pass
+class PortageUncondAllOfDep(PMAllOfDep, PortageUncondDep):
+	pass
+class PortageUncondPackageDepSet(PortageUncondDep):
+	pass
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
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.