aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Harring <ferringb@gentoo.org>2005-08-16 00:21:49 +0000
committerBrian Harring <ferringb@gentoo.org>2005-08-16 00:21:49 +0000
commita987096c3b581d582eb1bfc81be0779df74173d4 (patch)
tree26ff3d6b74336d959ef46e9ae6eeda653bbd29e5
parentrestriction subsystem slight redesign. (diff)
downloadportage-cvs-a987096c3b581d582eb1bfc81be0779df74173d4.tar.gz
portage-cvs-a987096c3b581d582eb1bfc81be0779df74173d4.tar.bz2
portage-cvs-a987096c3b581d582eb1bfc81be0779df74173d4.zip
removal of code that was transfered out of restriction, and adjustment of imports/code for collapsed for the tweaked restriction design
-rw-r--r--portage/restrictions/collapsed.py21
-rw-r--r--portage/restrictions/restriction.py227
2 files changed, 25 insertions, 223 deletions
diff --git a/portage/restrictions/collapsed.py b/portage/restrictions/collapsed.py
index e334583..127d630 100644
--- a/portage/restrictions/collapsed.py
+++ b/portage/restrictions/collapsed.py
@@ -1,12 +1,12 @@
# 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/restrictions/collapsed.py,v 1.4 2005/08/14 00:58:05 ferringb Exp $
+# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/restrictions/collapsed.py,v 1.5 2005/08/16 00:21:49 ferringb Exp $
__all__=("DictBased")
-from restriction import base, AlwaysTrue
from inspect import isroutine
-from restriction_set import bases, OrRestrictionSet
+from boolean import base as bool_base
+from packages import AndRestriction, OrRestriction, AlwaysTrue, AlwaysFalse, base
from portage.util.inheritance import check_for_base
class DictBased(base):
@@ -29,7 +29,7 @@ class DictBased(base):
in re: what restriction types are being collapsed; short version, api isn't declared stable yet.
"""
__slots__ = tuple(["restricts_dict", "get_pkg_key", "get_atom_key"] + base.__slots__)
-
+
def __init__(self, restriction_items, get_key_from_package, get_key_from_atom, *args, **kwargs):
"""restriction_items is a source of restriction keys and remaining restriction (if none, set it to None)
get_key is a function to get the key from a pkg instance"""
@@ -46,16 +46,17 @@ class DictBased(base):
else:
if len(remaining) == 1 and (isinstance(remaining, list) or isinstance(remaining, tuple)):
remaining = remaining[0]
- if not isinstance(remaining, base):
- b = check_for_base(r, bases)
- if b == None:
- raise KeyError("unable to convert '%s', remaining '%s' isn't of a known base" % (str(r), str(remaining)))
- remaining = b(*remaining)
+ elif isinstance(remaining, (tuple, list)):
+ remaining = AndRestriction(*remaining)
+ elif not isinstance(remaining, base):
+ print "remaining=",remaining
+ print "base=",base
+ raise KeyError("unable to convert '%s', remaining '%s' isn't of a known base" % (str(r), str(remaining)))
if key in self.restricts_dict:
self.restricts_dict[key].add_restriction(remaining)
else:
- self.restricts_dict[key] = OrRestrictionSet(remaining)
+ self.restricts_dict[key] = OrRestriction(remaining)
self.get_pkg_key, self.get_atom_key = get_key_from_package, get_key_from_atom
diff --git a/portage/restrictions/restriction.py b/portage/restrictions/restriction.py
index 60d1831..13c478f 100644
--- a/portage/restrictions/restriction.py
+++ b/portage/restrictions/restriction.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/restrictions/restriction.py,v 1.8 2005/08/09 07:51:09 ferringb Exp $
+# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/restrictions/restriction.py,v 1.9 2005/08/16 00:21:49 ferringb Exp $
import re, logging
@@ -10,7 +10,8 @@ class base(object):
all derivatives *must* be __slot__ based"""
__slots__ = ["negate"]
-
+ package_matching = False
+
def __init__(self, negate=False):
self.negate = negate
@@ -26,8 +27,16 @@ class base(object):
def match(self, *arg, **kwargs):
raise NotImplementedError
- def cmatch(self, *arg, **kwargs):
- return self.match(*arg, **kwargs)
+ force_False = force_True = match
+ def cmatch(self, pkg, *val):
+ m=self.match(value)
+ if m ^ self.negate:
+ return True
+ elif pkg == None or attr == None:
+ return False
+ elif self.negate:
+ return pkg.request_disable(attr, value)
+ return pkg.request_enable(attr, value)
def intersect(self, other):
return None
@@ -35,220 +44,12 @@ class base(object):
def __len__(self):
return 1
- total_len = __len__
-
class AlwaysBoolMatch(base):
__slots__ = base.__slots__
def match(self, *a, **kw): return self.negate
def __str__(self): return "always '%s'" % self.negate
+ def cmatch(self, *a, **kw): return self.negate
AlwaysFalse = AlwaysBoolMatch(False)
AlwaysTrue = AlwaysBoolMatch(True)
-
-class VersionRestriction(base):
- """use this as base for version restrictions, gives a clue to what the restriction does"""
- pass
-
-
-class StrMatch(base):
- """ Base string matching restriction. all derivatives must be __slot__ based classes"""
- __slots__ = ["flags"] + base.__slots__
- pass
-
-
-class StrRegexMatch(StrMatch):
- #potentially redesign this to jit the compiled_re object
- __slots__ = tuple(["regex", "compiled_re"] + StrMatch.__slots__)
-
- def __init__(self, regex, CaseSensitive=True, **kwds):
- super(StrRegexMatch, self).__init__(**kwds)
- self.regex = regex
- flags = 0
- if not CaseSensitive:
- flags = re.I
- self.flags = flags
- self.compiled_re = re.compile(regex, flags)
-
- def match(self, value):
- return (self.compiled_re.match(str(value)) != None) ^ self.negate
-
- def intersect(self, other):
- if self.regex == other.regex and self.negate == other.negate and self.flags == other.flags:
- return self
- return None
-
- def __eq__(self, other):
- return self.regex == other.regex and self.negate == other.negate and self.flags == other.flags
-
- def __str__(self):
- if self.negate: return "not like %s" % self.regex
- return "like %s" % self.regex
-
-
-class StrExactMatch(StrMatch):
- __slots__ = tuple(["exact", "flags"] + StrMatch.__slots__)
-
- def __init__(self, exact, CaseSensitive=True, **kwds):
- super(StrExactMatch, self).__init__(**kwds)
- if not CaseSensitive:
- self.flags = re.I
- self.exact = str(exact).lower()
- else:
- self.flags = 0
- self.exact = str(exact)
-
- def match(self, value):
- if self.flags & re.I: return (self.exact == str(value).lower()) ^ self.negate
- else: return (self.exact == str(value)) ^ self.negate
-
- def intersect(self, other):
- s1, s2 = self.exact, other.exact
- if other.flags and not self.flags:
- s1 = s1.lower()
- elif self.flags and not other.flags:
- s2 = s2.lower()
- if s1 == s2 and self.negate == other.negate:
- if other.flags:
- return other
- return self
- return None
-
- def __eq__(self, other):
- return self.exact == other.exact and self.negate == other.negate and self.flags == other.flags
-
- def __str__(self):
- if self.negate: return "!= "+self.exact
- return "== "+self.exact
-
-
-
-class StrGlobMatch(StrMatch):
- __slots__ = tuple(["glob"] + StrMatch.__slots__)
- def __init__(self, glob, CaseSensitive=True, **kwds):
- super(StrGlobMatch, self).__init__(**kwds)
- if not CaseSensitive:
- self.flags = re.I
- self.glob = str(glob).lower()
- else:
- self.flags = 0
- self.glob = str(glob)
-
- def match(self, value):
- if isinstance(value, (list, tuple)):
- for x in value:
- print "trying %s against %s" % (x, self.glob)
- if self.match(x):
- return not self.negate
- return self.negate
- else:
- value = str(value)
- if self.flags & re.I: value = value.lower()
- return value.startswith(self.glob) ^ self.negate
-
- def intersect(self, other):
- if self.match(other.glob):
- if self.negate == other.negate:
- return other
- elif other.match(self.glob):
- if self.negate == other.negate:
- return self
- return None
-
- def __eq__(self, other):
- return self.glob == other.glob and self.negate == other.negate and self.flags == other.flags
-
- def __str__(self):
- if self.negate: return "not "+self.glob+"*"
- return self.glob+"*"
-
-
-class PackageRestriction(base):
- """cpv data restriction. Inherit for anything that's more then cpv mangling please"""
-
- __slots__ = tuple(["attr", "restriction"] + base.__slots__)
-
- def __init__(self, attr, restriction, **kwds):
- super(PackageRestriction, self).__init__(**kwds)
- self.attr = attr.split(".")
- if not isinstance(restriction, base):
- raise TypeError("restriction must be of a restriction type")
- self.restriction = restriction
-
- def match(self, packageinstance):
- try:
- o = packageinstance
- for x in self.attr:
- o = getattr(o, x)
- return self.restriction.match(o) ^ self.negate
-
- except AttributeError,ae:
- logging.debug("failed getting attribute %s from %s, exception %s" % \
- (".".join(self.attr), str(packageinstance), str(ae)))
- return self.negate
-
- def __getitem__(self, key):
- try:
- g = self.restriction[key]
- except TypeError:
- if key == 0:
- return self.restriction
- raise IndexError("index out of range")
-
- def total_len(self):
- return len(self.restriction) + 1
-
- def intersect(self, other):
- if self.negate != other.negate or self.attr != other.attr:
- return None
- if isinstance(self.restriction, other.restriction.__class__):
- s = self.restriction.intersect(other.restriction)
- elif isinstance(other.restriction, self.restriction.__class__):
- s = other.restriction.intersect(self.restriction)
- else: return None
- if s == None:
- return None
- if s == self.restriction: return self
- elif s == other.restriction: return other
-
- # this can probably bite us in the ass self or other is a derivative, and the other isn't.
- return self.__class__(self.attr, s)
-
- def __eq__(self, other):
- return self.negate == self.negate and self.attr == other.attr and self.restriction == other.restriction
-
- def __str__(self):
- s='.'.join(self.attr)+" "
- if self.negate: s += "not "
- return s + str(self.restriction)
-
-
-class ContainmentMatch(base):
- """used for an 'in' style operation, 'x86' in ['x86','~x86'] for example"""
- __slots__ = tuple(["vals", "vals_len"] + base.__slots__)
-
- def __init__(self, *vals, **kwds):
- """vals must support a contaiment test"""
- super(ContainmentMatch, self).__init__(**kwds)
- self.vals = set(vals)
- self.vals_len = len(self.vals)
-
- def match(self, val):
- if isinstance(val, (str, unicode)):
- return val in self.vals ^ self.negate
- try:
- # assume our lookup is faster, since we don't know if val is constant lookup or not
- l = len(val)
- for x in val:
- if x in self.vals:
- return not self.negate
- return self.negate
- except TypeError:
- return val in self.vals ^ self.negate
-
-
- def __str__(self):
- if self.negate: s="not contains [%s]"
- else: s="contains [%s]"
- return s % ', '.join(map(str, self.vals))
-