diff options
author | 2005-08-09 07:47:34 +0000 | |
---|---|---|
committer | 2005-08-09 07:47:34 +0000 | |
commit | 7f8d2108ca343a3fb3801a1bc4c05373b8f8e1a5 (patch) | |
tree | 7f3c74fe3aab61c27ef3b3ec7c58207333b5b012 | |
parent | dicts.py => mappings.py (diff) | |
download | portage-cvs-7f8d2108ca343a3fb3801a1bc4c05373b8f8e1a5.tar.gz portage-cvs-7f8d2108ca343a3fb3801a1bc4c05373b8f8e1a5.tar.bz2 portage-cvs-7f8d2108ca343a3fb3801a1bc4c05373b8f8e1a5.zip |
whee.
cparser holds the case sensitive configparser (broke it out of __init__)
documentation updates, and addition of most filters for domain, including license filters, p.mask, and keywords.
-rw-r--r-- | portage/config/__init__.py | 12 | ||||
-rw-r--r-- | portage/config/central.py | 6 | ||||
-rw-r--r-- | portage/config/cparser.py | 10 | ||||
-rw-r--r-- | portage/config/domain.py | 125 | ||||
-rw-r--r-- | portage/config/profiles.py | 2 |
5 files changed, 123 insertions, 32 deletions
diff --git a/portage/config/__init__.py b/portage/config/__init__.py index 59939f9..a9d5e82 100644 --- a/portage/config/__init__.py +++ b/portage/config/__init__.py @@ -1,13 +1,18 @@ # Copyright: 2005 Gentoo Foundation # Author(s): Brian Harring (ferringb@gentoo.org) # License: GPL2 -# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/config/__init__.py,v 1.3 2005/07/20 14:33:12 ferringb Exp $ +# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/config/__init__.py,v 1.4 2005/08/09 07:47:34 ferringb Exp $ -from ConfigParser import ConfigParser +from cparser import CaseSensitiveConfigParser import central, os from portage.const import DEFAULT_CONF_FILE def load_config(file=DEFAULT_CONF_FILE): + """the entry point for any code looking to use portagelib. + if file exists, loads it up, else defaults to trying to load portage 2 style configs (/etc/make.conf, /etc/make.profile) + + returns the generated configuration object representing the system config. + """ c = CaseSensitiveConfigParser() if os.path.isfile(file): c.read(file) @@ -18,6 +23,3 @@ def load_config(file=DEFAULT_CONF_FILE): file) return c -class CaseSensitiveConfigParser(ConfigParser): - def optionxform(self, val): - return val diff --git a/portage/config/central.py b/portage/config/central.py index 09ca6c1..0e39a14 100644 --- a/portage/config/central.py +++ b/portage/config/central.py @@ -1,13 +1,13 @@ # Copyright: 2005 Gentoo Foundation # Author(s): Brian Harring (ferringb@gentoo.org) # License: GPL2 -# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/config/central.py,v 1.8 2005/08/03 00:29:17 ferringb Exp $ +# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/config/central.py,v 1.9 2005/08/09 07:47:34 ferringb Exp $ import errors, new from portage.const import CONF_DEFAULTS from portage.util.modules import load_attribute -from ConfigParser import ConfigParser -from portage.util.dicts import LazyValDict +from cparser import CaseSensitiveConfigParser as ConfigParser +from portage.util.mappings import LazyValDict from portage.util.currying import pre_curry class config: diff --git a/portage/config/cparser.py b/portage/config/cparser.py new file mode 100644 index 0000000..d03c115 --- /dev/null +++ b/portage/config/cparser.py @@ -0,0 +1,10 @@ +# Copyright: 2005 Gentoo Foundation +# Author(s): Brian Harring (ferringb@gentoo.org) +# License: GPL2 +# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/config/cparser.py,v 1.1 2005/08/09 07:47:34 ferringb Exp $ + +from ConfigParser import ConfigParser + +class CaseSensitiveConfigParser(ConfigParser): + def optionxform(self, val): + return val diff --git a/portage/config/domain.py b/portage/config/domain.py index 303ee56..b7e74c3 100644 --- a/portage/config/domain.py +++ b/portage/config/domain.py @@ -1,7 +1,7 @@ # Copyright: 2005 Gentoo Foundation # Author(s): Brian Harring (ferringb@gentoo.org) # License: GPL2 -# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/config/domain.py,v 1.4 2005/08/03 00:29:17 ferringb Exp $ +# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/config/domain.py,v 1.5 2005/08/09 07:47:34 ferringb Exp $ from portage.restrictions.collapsed import DictBased from portage.restrictions.restrictionSet import OrRestrictionSet, AndRestrictionSet @@ -9,25 +9,30 @@ import os from errors import BaseException from portage.util.file import iter_read_bash from portage.package.atom import atom -from portage.restrictions.collapsed import DictBased from portage.repository.visibility import filterTree +from portage.restrictions.restriction import StrGlobMatch, PackageRestriction, StrExactMatch, ContainmentMatch from portage.util.currying import post_curry from portage.util.lists import unique +from itertools import imap class MissingFile(BaseException): def __init__(self, file, setting): self.file, self.setting = file, setting def __str__(self): return "setting %s points at %s, which doesn't exist." % (self.setting, self.file) class Failure(BaseException): - def __init__(self, text): self.text - def __str__(self): return "domain failure: %s" % text + def __init__(self, text): self.text = text + def __str__(self): return "domain failure: %s" % self.text -def split_atom(atom): - return atom.category + "/" + atom.package, atom.restrictions[2:] +def split_atom(inst): + return inst.category + "/" + inst.package, inst.restrictions[2:] + def get_key_from_package(pkg): return pkg.category + "/" + pkg.package +def package_keywords_splitter(val): + v=val.split() + return atom(v[0]), unique(v[1:]) # ow ow ow ow ow ow.... # this manages a *lot* of crap. so... this is fun. @@ -35,16 +40,22 @@ def get_key_from_package(pkg): class domain: def __init__(self, incrementals, root, profile, repositories, **settings): # voodoo, unfortunately (so it goes) - maskers, unmaskers, keywords, visibility = profile.maskers[:], [], [], profile.visibility + # break this up into chunks once it's stabilized (most of code here has already, but still more to add) + maskers, unmaskers, keywords, license = profile.maskers[:], [], [], [] + if len(profile.visibility): + maskers.extend(profile.visibility) - for key, val in (("package.mask", maskers), ("package.unmask", unmaskers), ("package.keywords", keywords)): + for key, val, action in (("package.mask", maskers, atom), ("package.unmask", unmaskers, atom), + ("package.keywords", keywords, package_keywords_splitter), ("package.license", license, package_keywords_splitter)): if key in settings: - if os.path.exists(settings[key]): - try: val.extend(map(atom, iter_read_bash(fp))) - except (IOError, OSError), e: - raise Failure("failed reading '%s': %s" % (settings[key], str(e))) - else: - raise MissingFile(settings[key], key) + + for fp in settings[key]: + if os.path.exists(fp): + try: val.extend(imap(action, iter_read_bash(fp))) + except (IOError, OSError, ValueError), e: + raise Failure("failed reading '%s': %s" % (fp, str(e))) + else: + raise MissingFile(settings[key], key) del settings[key] inc_d = set(incrementals) @@ -53,13 +64,14 @@ class domain: if x in inc_d: # strings overwrite, lists append. if isinstance(settings[x], (list, tuple)): - settings[x] += profile.conf[x] + # profile prefixes + settings[x] = profile.conf[x] + settings[x] else: settings[x] = profile.conf[x] del inc_d # visibility mask... - # if (package.mask and not package.unmask) or system-visibility-filter or not (package.keywords or accept_keywords) + # if ((package.mask or visibility) and not package.unmask) or not (package.keywords or accept_keywords) filter = OrRestrictionSet() masker_d = DictBased(maskers, get_key_from_package, split_atom) @@ -67,12 +79,79 @@ class domain: masker_d = AndRestrictionSet(masker_d, DictBased(unmaskers, get_key_from_package, split_atom, negate=True)) filter.add_restriction(masker_d) - # profile visibility filters. - if len(visibility): - filter.add_restriction(DictBased(visibility, get_key_from_package, split_atom)) + use, license, key = [], [], [] + + def filter_negations(setting, orig_list): + l = set() + for x in orig_list: + if x.startswith("-"): + if x.startswith("-*"): + l.clear() + else: + if len(x) == 1: + raise Failure("negation of a setting in '%s', but name negated isn't completed-" % (k, v)) + x=x[1:] + if x in l: l.remove(x) + else: + l.add(x) + return l + + master_license = [] + for k,v in (("USE", use), ("ACCEPT_KEYWORDS", key), ("ACCEPT_LICENSE", master_license)): + if k not in settings: + raise Failure("No %s setting detected from profile, or user config" % k) + v.extend(filter_negations(k, settings[k])) + + if "ARCH" not in settings: + raise Failure("No ARCH setting detected from profile, or user config") + + arch = settings["ARCH"] + + # faster check. if unstable arch is already in keywords, don't screw around with adding it to the filter + ukey = "~"+arch + ukey_check = ukey in key + keyword_filter = [] + for a, v in keywords: + if len(v) == 0: + if ukey_check: continue + # note that we created the atom above- so we can toy with it's innards if we want. :) + r = ContainmentMatch(ukey) + else: + r = OrRestrictionSet() + per_node = [] + exact = [] + for x in v: + if x == "*": per_node.append(StrGlobMatch("~", negate=True)) + elif x == "~*": per_node.append(StrGlobMatch("~")) + else: exact.append(x) + if len(exact): + r.add_restriction(ContainmentMatch(*exact)) + if len(per_node): + r.add_restriction(*exact) + a.add_restriction(PackageRestriction("keywords", r)) + keyword_filter.append(a) + + key_filter = ContainmentMatch(*key) + if len(keyword_filter) != 0: + filter.add_restriction(OrRestrictionSet(PackageRestriction("keywords", key_filter), + DictBased(keyword_filter, get_key_from_package, split_atom), negate=True)) + else: + filter.add_restriction(PackageRestriction("keywords", key_filter, negate=True)) + del key_filter, keywords, keyword_filter, key, ukey, ukey_check + + # we can finally close that fricking "DISALLOW NON FOSS LICENSES" bug via this >:) + if len(master_license) != 0: + if len(license) != 0: + r = OrRestrictionSet(negate=True) + r.add_restriction(PackageRestriction("license", ContainmentMatch(*master_license))) + r.add_restriction(DictBased(license, get_key_from_package, split_atom)) + filter.add_restriction(r) + else: + filter.add_restriction(PackageRestriction("license", ContainmentMatch(*master_license), negate=True)) + elif len(license): + filter.add_restriction(DictBased(license, get_key_from_package, split_atom, negate=True)) + + del master_license, license -# keywords, license = [], [] -# if "accept_keywords" in settings: -# keywords = settings["accept_keywords"] - self.repos = map(post_curry(filterTree, filter, False), repositories) + self.settings = settings diff --git a/portage/config/profiles.py b/portage/config/profiles.py index df2213d..e1f9cc4 100644 --- a/portage/config/profiles.py +++ b/portage/config/profiles.py @@ -1,7 +1,7 @@ # Copyright: 2005 Gentoo Foundation # Author(s): Brian Harring (ferringb@gentoo.org) # License: GPL2 -# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/config/profiles.py,v 1.1 2005/08/05 04:54:42 ferringb Exp $ +# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/config/profiles.py,v 1.2 2005/08/09 07:47:34 ferringb Exp $ class base(object): pass |