diff options
author | 2005-08-03 00:24:34 +0000 | |
---|---|---|
committer | 2005-08-03 00:24:34 +0000 | |
commit | 9d95d8f879248eb40b3f5ac072c41452a28b4872 (patch) | |
tree | 3d818ea9441d4652ca704dddc641cdcbcc26048d | |
parent | pref_curry is now pre_curry (diff) | |
download | portage-cvs-9d95d8f879248eb40b3f5ac072c41452a28b4872.tar.gz portage-cvs-9d95d8f879248eb40b3f5ac072c41452a28b4872.tar.bz2 portage-cvs-9d95d8f879248eb40b3f5ac072c41452a28b4872.zip |
__str__ , and cleanup/bug fixing of versionmatch
-rw-r--r-- | portage/package/atom.py | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/portage/package/atom.py b/portage/package/atom.py index 45918ce..2962cee 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.6 2005/07/28 23:52:50 ferringb Exp $ +# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/package/atom.py,v 1.7 2005/08/03 00:24:34 ferringb Exp $ from portage.restrictions import restriction from cpv import ver_cmp, CPV @@ -9,7 +9,7 @@ from portage.restrictions.restrictionSet import AndRestrictionSet from portage.util.lists import unique class VersionMatch(restriction.base): - __slots__ = tuple(["ver","rev", "vals"] + restriction.StrMatch.__slots__) + __slots__ = tuple(["ver","rev", "vals", "droprev"] + restriction.StrMatch.__slots__) """any overriding of this class *must* maintain numerical order of self.vals, see intersect for reason why vals also must be a tuple""" @@ -17,23 +17,30 @@ class VersionMatch(restriction.base): kwd["negate"] = False super(self.__class__, self).__init__(**kwd) self.ver, self.rev = ver, rev - if operator not in ("<=","<", "=", ">", ">="): + if operator not in ("<=","<", "=", ">", ">=", "~"): # XXX: hack raise Exception("invalid operator, '%s'", operator) if negate: + if operator == "~": + raise Exception("Cannot negate '~' operator") if "=" in operator: operator = operator.strip("=") else: operator += "=" for x,v in (("<",">"),(">","<")): if x in operator: operator = operator.strip(x) + v break - - l=[] - if "<" in operator: l.append(-1) - if "=" in operator: l.append(0) - if ">" in operator: l.append(1) - self.vals = tuple(l) + + if operator == "~": + self.droprev = True + self.vals = (0,) + else: + self.droprev = False + l=[] + if "<" in operator: l.append(-1) + if "=" in operator: l.append(0) + if ">" in operator: l.append(1) + self.vals = tuple(l) def intersect(self, other, allow_hand_off=True): if not isinstance(other, self.__class__): @@ -41,7 +48,11 @@ class VersionMatch(restriction.base): return other.intersect(self, allow_hand_off=False) return None - vc = ver_cmp(self.ver, self.rev, other.ver, other.ver) + if self.droprev or other.droprev: + vc = ver_cmp(self.ver, None, other.ver, None) + else: + vc = ver_cmp(self.ver, self.rev, other.ver, other.rev) + # ick. 28 possible valid combinations. if vc == 0: if 0 in self.vals and 0 in other.vals: @@ -86,8 +97,22 @@ class VersionMatch(restriction.base): return None def match(self, pkginst): - return (ver_cmp(self.ver, self.rev, pkginst.version, pkginst.revision) in self.vals) ^ self.negate + if self.droprev: r1, r2 = None, None + else: r1, r2 = self.rev, pkginst.revision + return (ver_cmp(pkginst.version, r2, self.ver, r1) in self.vals) ^ self.negate + + def __str__(self): + l = [] + for x in self.vals: + if x == -1: l.append("<") + elif x == 0: l.append("=") + elif x == 1: l.append(">") + l.sort() + l = ''.join(l) + if self.droprev or self.rev == None: + return "ver %s %s" % (l, self.ver) + return "fullver %s %s-r%s" % (l, self.ver, self.rev) class atom(AndRestrictionSet): __slots__ = ("glob","atom","blocks","op", "negate_vers","cpv","use","slot") + tuple(AndRestrictionSet.__slots__) @@ -110,7 +135,6 @@ class atom(AndRestrictionSet): else: self.glob = False self.atom = atom[pos:] - self.negate_vers = negate_vers self.cpv = CPV(self.atom) self.use, self.slot = use, slot @@ -148,3 +172,9 @@ class atom(AndRestrictionSet): if self.version: s+="-"+self.fullver if self.glob: s+="*" return s + + def __iter__(self): + return iter(self.restrictions) + + def __getitem__(self, index): + return self.restrictions[index] |