aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Harring <ferringb@gentoo.org>2005-07-27 02:26:49 +0000
committerBrian Harring <ferringb@gentoo.org>2005-07-27 02:26:49 +0000
commit7ce6e3d6b91c663d47b8bc8e98ef8ba0114b25d5 (patch)
treed23e32389bd47a7d49534166bb95596cfdd09baf /portage
parentadded description attribute (diff)
downloadportage-cvs-7ce6e3d6b91c663d47b8bc8e98ef8ba0114b25d5.tar.gz
portage-cvs-7ce6e3d6b91c663d47b8bc8e98ef8ba0114b25d5.tar.bz2
portage-cvs-7ce6e3d6b91c663d47b8bc8e98ef8ba0114b25d5.zip
restrictions updates, addition of intersects (still underway), and a lookup based restrictionset (collapsed)
Diffstat (limited to 'portage')
-rw-r--r--portage/package/atom.py17
-rw-r--r--portage/restrictions/collapsed.py62
-rw-r--r--portage/restrictions/restriction.py105
-rw-r--r--portage/restrictions/restrictionSet.py6
4 files changed, 164 insertions, 26 deletions
diff --git a/portage/package/atom.py b/portage/package/atom.py
index 03a604b..1b1ae4d 100644
--- a/portage/package/atom.py
+++ b/portage/package/atom.py
@@ -1,7 +1,7 @@
# Copyright: 2005 Gentoo Foundation
# Author(s): Jason Stubbs (jstubbs@gentoo.org), Brian Harring (ferringb@gentoo.org)
# License: GPL2
-# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/package/atom.py,v 1.2 2005/07/20 14:33:12 ferringb Exp $
+# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/package/atom.py,v 1.3 2005/07/27 02:26:49 ferringb Exp $
from portage.restrictions import restriction
from cpv import ver_cmp, CPV
@@ -25,8 +25,9 @@ class VersionMatch(restriction.base):
class atom(AndRestrictionSet):
+ __slots__ = ("glob","atom","blocks","op", "negate_vers","cpv","use","slot") + tuple(AndRestrictionSet.__slots__)
- def __init__(self, atom, slot=None, use=[]):
+ def __init__(self, atom, slot=None, use=[], negate_vers=False):
super(self.__class__, self).__init__()
pos=0
@@ -45,6 +46,7 @@ class atom(AndRestrictionSet):
self.glob = False
self.atom = atom[pos:]
+ self.negate_vers = negate_vers
self.cpv = CPV(self.atom)
self.use, self.slot = use, slot
# force jitting of it.
@@ -54,25 +56,24 @@ class atom(AndRestrictionSet):
def __getattr__(self, attr):
if attr in ("category", "package", "version", "revision", "cpvstr", "fullver", "key"):
g = getattr(self.cpv, attr)
- self.__dict__[attr] = g
+# self.__dict__[attr] = g
return g
-
elif attr == "restrictions":
- r = []
+ r = [restriction.PackageRestriction("package", restriction.StrExactMatch(self.package))]
try:
cat = self.category
r.append(restriction.PackageRestriction("category", restriction.StrExactMatch(cat)))
except AttributeError:
pass
- r.append(restriction.PackageRestriction("package", restriction.StrExactMatch(self.package)))
if self.version:
if self.glob:
r.append(restriction.PackageRestriction("fullver", restriction.StrGlobMatch(self.fullver)))
else:
- r.append(VersionMatch(self.op, self.version, self.revision))
+ r.append(VersionMatch(self.op, self.version, self.revision, negate=self.negate_vers))
if self.use or self.slot:
raise Exception("yo. I don't support use or slot yet, fix me pls kthnx")
- self.__dict__["restrictions"] = r
+# self.__dict__[attr] = r
+ setattr(self, attr, r)
return r
raise AttributeError(attr)
diff --git a/portage/restrictions/collapsed.py b/portage/restrictions/collapsed.py
new file mode 100644
index 0000000..ae60426
--- /dev/null
+++ b/portage/restrictions/collapsed.py
@@ -0,0 +1,62 @@
+# 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.1 2005/07/27 02:26:49 ferringb Exp $
+
+from restriction import base
+from inspect import isroutine
+
+class DictBased(base):
+ __slots__ = tuple(["restricts_dict", "get_key", "get_atom_key"] + base.__slots__)
+ def __init__(self, restriction_items, get_key, 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"""
+
+ if not isroutine(get_key):
+ raise TypeError(get_key)
+
+ super(LookupBase, self).__init__(*args, **kwargs)
+ restricts_dict = {}
+ for r in restrictions:
+ key, remaining = chunk_it
+ restricts_dict[key] = remaining
+ self.get_key, self.get_atom_key = get_key, get_key_from_atom
+
+
+ def match(self, pkginst):
+ try:
+ key = self.get_key(pkginst)
+ except (TypeError, AttributeError):
+ return self.negate
+ remaining = self.restricts_dict.get(key, False)
+ if remaining == False:
+ return self.negate
+ elif remaining == None:
+ return not self.negate
+ return remaining.match(pkginst) ^ self.negate
+
+ def __contains__(self, restriction):
+ if isinstance(key, base):
+ key = get_atom_key(restriction):
+ if key != None and key in self.restricts_dict:
+ return True
+ return False
+
+ def __getitem__(self, key, default=None):
+ if isinstance(key, base):
+ key = get_atom_key(restriction):
+ if key == None: return default
+ return self.restricts_dict.get(key, default)
+
+ def __setitem__(self, key, val):
+ if isinstance(key, base):
+ key = get_atom_key(restriction):
+ if key == None:
+ raise KeyError("either passed in, or converted val became None, invalid as key")
+ self.restricts_dict[key] = val
+
+ def __delitem__(self, key):
+ if isinstance(key, base):
+ key = get_atom_key(restriction):
+ if key != None and key in self.restricts_dict:
+ del self.restricts_dict[key]
diff --git a/portage/restrictions/restriction.py b/portage/restrictions/restriction.py
index 24c65b7..d0a0dd0 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.3 2005/07/21 19:50:17 ferringb Exp $
+# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/restrictions/restriction.py,v 1.4 2005/07/27 02:26:49 ferringb Exp $
import re, logging
@@ -14,25 +14,29 @@ class base(object):
def __init__(self, negate=False):
self.negate = negate
- def __setattr__(self, name, value):
- try: getattr(self, name)
-
- except AttributeError:
- object.__setattr__(self, name, value)
- else: raise AttributeError
+# def __setattr__(self, name, value):
+# import traceback;traceback.print_stack()
+# object.__setattr__(self, name, value)
+# try: getattr(self, name)
+#
+# except AttributeError:
+# object.__setattr__(self, name, value)
+# else: raise AttributeError
def match(self, *arg, **kwargs):
raise NotImplementedError
-class AlwaysTrue(base):
- __slots__ = ()
- def match(self, *a, **kw):
- return True
+ def intersect(self, other):
+ raise NotImplementedError
-class AlwaysFalse(base):
- __slots__ = ()
+class AlwaysBoolMatch(base):
+ __slots__ = base.__slots__
def match(self, *a, **kw):
- return False
+ 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"""
@@ -41,13 +45,13 @@ class VersionRestriction(base):
class StrMatch(base):
""" Base string matching restriction. all derivatives must be __slot__ based classes"""
- __slots__ = base.__slots__
+ __slots__ = ["flags"] + base.__slots__
pass
class StrRegexMatch(StrMatch):
#potentially redesign this to jit the compiled_re object
- __slots__ = tuple(["regex", "compiled_re", "flags"] + StrMatch.__slots__)
+ __slots__ = tuple(["regex", "compiled_re"] + StrMatch.__slots__)
def __init__(self, regex, CaseSensitive=True, **kwds):
super(StrRegexMatch, self).__init__(**kwds)
@@ -63,6 +67,12 @@ class StrRegexMatch(StrMatch):
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
+
+
class StrExactMatch(StrMatch):
__slots__ = tuple(["exact", "flags"] + StrMatch.__slots__)
@@ -81,6 +91,19 @@ class StrExactMatch(StrMatch):
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
+
+
class StrSubstringMatch(StrMatch):
__slots__ = tuple(["substr"] + StrMatch.__slots__)
@@ -100,6 +123,24 @@ class StrSubstringMatch(StrMatch):
return (value.find(self.substr) != -1) ^ self.negate
+ def intersect(self, other):
+ if self.negate == other.negate:
+ if self.substr == other.substr and self.flags == other.flags:
+ return self
+ else:
+ return None
+ s1, s2 = self.substr, other.substr
+ if other.flags and not self.flags:
+ s1 = s1.lower()
+ elif self.flags and not other.flags:
+ s2 = s2.lower()
+ if s1.find(s2) != -1:
+ return self
+ elif s2.find(s1) != -1:
+ return other
+ return None
+
+
class StrGlobMatch(StrMatch):
__slots__ = tuple(["glob"] + StrMatch.__slots__)
def __init__(self, glob, CaseSensitive=True, **kwds):
@@ -108,13 +149,26 @@ class StrGlobMatch(StrMatch):
self.flags = re.I
self.glob = str(glob).lower()
else:
- self.glags = 0
+ self.flags = 0
self.glob = str(glob)
+
+
def match(self, value):
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
+
+
class PackageRestriction(base):
"""cpv data restriction. Inherit for anything that's more then cpv mangling please"""
@@ -136,3 +190,20 @@ class PackageRestriction(base):
logging.debug("failed getting attribute %s from %s, exception %s" % \
(".".join(self.attr), str(packageinstance), str(ae)))
return self.negate
+
+
+ def intersect(self, other):
+ if self.negate != other.negate or self.attr != other.attr:
+ return None
+ if isinstance(self.strmatch, other.strmatch.__class__):
+ s = self.strmatch.intersect(other.strmatch)
+ elif isinstance(other.strmatch, self.strmatch.__class__):
+ s = other.strmatch.intersect(self.strmatch)
+ else: return None
+ if s == None:
+ return None
+ if s == self.strmatch: return self
+ elif s == other.strmatch: 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)
diff --git a/portage/restrictions/restrictionSet.py b/portage/restrictions/restrictionSet.py
index d204618..1c6743d 100644
--- a/portage/restrictions/restrictionSet.py
+++ b/portage/restrictions/restrictionSet.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/Attic/restrictionSet.py,v 1.5 2005/07/21 20:04:08 ferringb Exp $
+# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/restrictions/Attic/restrictionSet.py,v 1.6 2005/07/27 02:26:49 ferringb Exp $
import restriction
@@ -47,6 +47,10 @@ class AndRestrictionSet(RestrictionSet):
return not self.negate
+ def intersect(self, other):
+
+
+
class OrRestrictionSet(RestrictionSet):
__slots__ = tuple(RestrictionSet.__slots__)