diff options
author | 2005-08-09 07:58:58 +0000 | |
---|---|---|
committer | 2005-08-09 07:58:58 +0000 | |
commit | e3f844e451f3abed5472c7b4a0b3612669d8a091 (patch) | |
tree | b39ef45bda1cead6d5aaf82929d40496d54fa8b1 | |
parent | updates for (diff) | |
download | portage-cvs-e3f844e451f3abed5472c7b4a0b3612669d8a091.tar.gz portage-cvs-e3f844e451f3abed5472c7b4a0b3612669d8a091.tar.bz2 portage-cvs-e3f844e451f3abed5472c7b4a0b3612669d8a091.zip |
added use deps and slot deps parsing, better exception's (and better throwing of said exceptions), dropped __str__ (so people now see the underlying portage.restrictions.restrictionSet.AndRestrictionSet.__str__ output, which is better for hashing)
and a __cmp__ function, which is of questionable use.
-rw-r--r-- | portage/package/atom.py | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/portage/package/atom.py b/portage/package/atom.py index 2962cee..5e5c65f 100644 --- a/portage/package/atom.py +++ b/portage/package/atom.py @@ -1,13 +1,22 @@ # 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.7 2005/08/03 00:24:34 ferringb Exp $ +# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/package/atom.py,v 1.8 2005/08/09 07:58:58 ferringb Exp $ from portage.restrictions import restriction from cpv import ver_cmp, CPV from portage.restrictions.restrictionSet import AndRestrictionSet from portage.util.lists import unique +class MalformedAtom(Exception): + def __init__(self, atom, err=''): self.atom, self.err = atom, err + def __str__(self): return "atom '%s' is malformed: error %s" % (self.atom, self.err) + +class InvalidVersion(Exception): + def __init__(self, ver, rev, err=''): self.ver, self.rev, self.err = ver, rev, err + def __str__(self): return "Version restriction ver='%s', rev='%s', is malformed: error %s" % (self.ver, self.rev, self.err) + + class VersionMatch(restriction.base): __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 @@ -19,7 +28,7 @@ class VersionMatch(restriction.base): self.ver, self.rev = ver, rev if operator not in ("<=","<", "=", ">", ">=", "~"): # XXX: hack - raise Exception("invalid operator, '%s'", operator) + raise InvalidVersion(self.ver, self.rev, "invalid operator, '%s'" % operator) if negate: if operator == "~": @@ -117,7 +126,7 @@ 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=[], negate_vers=False): + def __init__(self, atom, negate_vers=False): super(self.__class__, self).__init__() pos=0 @@ -129,6 +138,28 @@ class atom(AndRestrictionSet): else: self.blocks = False self.op = atom[:pos] + + u = atom.find("[") + if u != -1: + # use dep + u2 = atom.find("]", u) + if u2 == -1: + raise MalformedAtom(atom, "use restriction isn't completed") + self.use = atom[u+1:u2].split(',') + atom = atom[0:u]+atom[u2 + 1:] + else: + self.use = () + s = atom.find(":") + if s != -1: + if atom.find(":", s+1) != -1: + raise MalformedAtom(atom, "second specification of slotting") + # slot dep. + self.slot = atom[s + 1:].rstrip().split(",") + atom = atom[:s] + else: + self.slot = () + del u,s + if atom.endswith("*"): self.glob = True self.atom = atom[pos:-1] @@ -137,7 +168,6 @@ class atom(AndRestrictionSet): self.atom = atom[pos:] self.negate_vers = negate_vers self.cpv = CPV(self.atom) - self.use, self.slot = use, slot # force jitting of it. del self.restrictions @@ -160,21 +190,32 @@ class atom(AndRestrictionSet): else: 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") + raise MalformedAtom(self.atom, "yo. I don't support use or slot yet, fix me pls kthnx") # self.__dict__[attr] = r setattr(self, attr, r) return r raise AttributeError(attr) - def __str__(self): - s=self.op+self.category+"/"+self.package - if self.version: s+="-"+self.fullver - if self.glob: s+="*" - return s +# def __str__(self): +# s=self.op+self.category+"/"+self.package +# 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] + + def __cmp__(self, other): + if not isinstance(other, self.__class__): + raise TypeError("other isn't of %s type, is %s" % (self.__class__, other.__class__)) + c = cmp(self.category, other.category) + if c != 0: return c + c = cmp(self.package, other.package) + if c != 0: return c + c = ver_cmp(self.version, self.revision, other.version, other.revision) + if c != 0: return c + return cmp(self.op, other.op) |