summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/sets/__init__.py10
-rw-r--r--pym/portage/sets/dbapi.py12
-rw-r--r--pym/portage/sets/files.py30
-rw-r--r--pym/portage/sets/security.py7
4 files changed, 39 insertions, 20 deletions
diff --git a/pym/portage/sets/__init__.py b/pym/portage/sets/__init__.py
index 5f82b69b7..39cebdf84 100644
--- a/pym/portage/sets/__init__.py
+++ b/pym/portage/sets/__init__.py
@@ -9,6 +9,16 @@ from portage.const import USER_CONFIG_PATH, GLOBAL_CONFIG_PATH
SETPREFIX = "@"
+def get_boolean(options, name, default):
+ if not name in options:
+ return default
+ elif options[name].lower() in ("1", "yes", "on", "true"):
+ return True
+ elif options[name].lower() in ("0", "no", "off", "false"):
+ return False
+ else:
+ raise SetConfigError("invalid value '%s' for option '%s'" % (options[name], name))
+
class SetConfigError(Exception):
pass
diff --git a/pym/portage/sets/dbapi.py b/pym/portage/sets/dbapi.py
index 220ff2283..c4f974aa9 100644
--- a/pym/portage/sets/dbapi.py
+++ b/pym/portage/sets/dbapi.py
@@ -4,7 +4,7 @@
from portage.versions import catsplit, catpkgsplit
from portage.sets.base import PackageSet
-from portage.sets import SetConfigError
+from portage.sets import SetConfigError, get_boolean
from portage.dbapi.vartree import dblink
from portage.util import grabfile
@@ -65,10 +65,7 @@ class CategorySet(PackageSet):
_builderGetRepository = classmethod(_builderGetRepository)
def _builderGetVisible(cls, options):
- visible = options.get("only_visible", "true").lower()
- if visible not in ["1", "0", "yes", "no", "true", "false", "on", "off"]:
- raise SetConfigError("invalid value for only_visible: %s" % visible)
- return bool(visible in ["1", "yes", "true", "on"])
+ return get_boolean(options, "only_visible", True)
_builderGetVisible = classmethod(_builderGetVisible)
def singleBuilder(cls, options, settings, trees):
@@ -176,9 +173,6 @@ class MissingLibraryConsumerSet(LibraryConsumerSet):
self._setAtoms(self.mapPathsToAtoms(consumers))
def singleBuilder(cls, options, settings, trees):
- if options.get("debug", "true").lower() in ["true", "on", "1", "yes"]:
- debug = True
- else:
- debug = False
+ debug = get_boolean(options, "debug", False)
return MissingLibraryConsumerSet(trees["vartree"].dbapi, debug=debug)
singleBuilder = classmethod(singleBuilder)
diff --git a/pym/portage/sets/files.py b/pym/portage/sets/files.py
index c6a6f7430..cc4862cc8 100644
--- a/pym/portage/sets/files.py
+++ b/pym/portage/sets/files.py
@@ -11,7 +11,7 @@ from portage.const import PRIVATE_PATH, USER_CONFIG_PATH
from portage.locks import lockfile, unlockfile
from portage import portage_gid
from portage.sets.base import PackageSet, EditablePackageSet
-from portage.sets import SetConfigError, SETPREFIX
+from portage.sets import SetConfigError, SETPREFIX, get_boolean
from portage.env.loaders import ItemFileLoader, KeyListFileLoader
from portage.env.validators import ValidAtomValidator
from portage import dep_getkey, cpv_getkey
@@ -21,12 +21,17 @@ __all__ = ["StaticFileSet", "ConfigFileSet", "WorldSet"]
class StaticFileSet(EditablePackageSet):
_operations = ["merge", "unmerge"]
- def __init__(self, filename):
+ def __init__(self, filename, greedy=False, dbapi=None):
super(StaticFileSet, self).__init__()
self._filename = filename
self._mtime = None
self.description = "Package set loaded from file %s" % self._filename
self.loader = ItemFileLoader(self._filename, self._validate)
+ if greedy and not dbapi:
+ self.errors.append("%s configured as greedy set, but no dbapi instance passed in constructor" % self._filename)
+ greedy = False
+ self.greedy = greedy
+ self.dbapi = dbapi
metadata = grabfile(self._filename + ".metadata")
key = None
@@ -70,13 +75,25 @@ class StaticFileSet(EditablePackageSet):
raise
del e
data = {}
- self._setAtoms(data.keys())
+ if self.greedy:
+ atoms = []
+ for a in data.keys():
+ matches = self.dbapi.match(a)
+ if len(matches) > 1:
+ for cpv in matches:
+ atoms.append(dep_getkey(cpv)+":"+self.dbapi.aux_get(cpv, ["SLOT"])[0])
+ else:
+ atoms.append(a)
+ else:
+ atoms = data.keys()
+ self._setAtoms(atoms)
self._mtime = mtime
def singleBuilder(self, options, settings, trees):
if not "filename" in options:
raise SetConfigError("no filename specified")
- return ConfigFileSet(options[filename])
+ greedy = get_boolean(options, "greedy", True)
+ return StaticFileSet(options["filename"], greedy=greedy, dbapi=trees["vartree"].dbapi)
singleBuilder = classmethod(singleBuilder)
def multiBuilder(self, options, settings, trees):
@@ -85,13 +102,14 @@ class StaticFileSet(EditablePackageSet):
name_pattern = options.get("name_pattern", "sets/$name")
if not "$name" in name_pattern and not "${name}" in name_pattern:
raise SetConfigError("name_pattern doesn't include $name placeholder")
+ greedy = get_boolean(options, "greedy", True)
if os.path.isdir(directory):
for filename in os.listdir(directory):
if filename.endswith(".metadata"):
continue
myname = name_pattern.replace("$name", filename)
myname = myname.replace("${name}", filename)
- rValue[myname] = StaticFileSet(os.path.join(directory, filename))
+ rValue[myname] = StaticFileSet(os.path.join(directory, filename), greedy=greedy, dbapi=trees["vartree"].dbapi)
return rValue
multiBuilder = classmethod(multiBuilder)
@@ -109,7 +127,7 @@ class ConfigFileSet(PackageSet):
def singleBuilder(self, options, settings, trees):
if not "filename" in options:
raise SetConfigError("no filename specified")
- return ConfigFileSet(options[filename])
+ return ConfigFileSet(options["filename"])
singleBuilder = classmethod(singleBuilder)
def multiBuilder(self, options, settings, trees):
diff --git a/pym/portage/sets/security.py b/pym/portage/sets/security.py
index f93b34ef8..928fecbcf 100644
--- a/pym/portage/sets/security.py
+++ b/pym/portage/sets/security.py
@@ -7,6 +7,7 @@ import portage.glsa as glsa
from portage.util import grabfile, write_atomic
from portage.sets.base import PackageSet
from portage.versions import catpkgsplit, pkgcmp
+from portage.sets import get_boolean
__all__ = ["SecuritySet", "NewGlsaSet", "NewAffectedSet", "AffectedSet"]
@@ -69,11 +70,7 @@ class SecuritySet(PackageSet):
myglsa.inject()
def singleBuilder(cls, options, settings, trees):
- if "use_emerge_resoler" in options \
- and options.get("use_emerge_resolver").lower() in ["1", "yes", "true", "on"]:
- least_change = False
- else:
- least_change = True
+ least_change = not get_boolean(options, "use_emerge_resolver", False)
return cls(settings, trees["vartree"].dbapi, trees["porttree"].dbapi, least_change=least_change)
singleBuilder = classmethod(singleBuilder)