Merged from trunk -r14239:14242
authorFabian Groffen <grobian@gentoo.org>
Sun, 13 Sep 2009 19:05:11 +0000 (19:05 -0000)
committerFabian Groffen <grobian@gentoo.org>
Sun, 13 Sep 2009 19:05:11 +0000 (19:05 -0000)
   | 14240   | Fix docs for isjustname() since it doesn't raise InvalidAtom |
   | zmedico | now.                                                         |

   | 14241   | Make the Atom constructor use regular expression match       |
   | zmedico | groups for initialization. Thanks to Marat Radchenko         |
   |         | <marat@slonopotamus.org> for this patch.                     |

   | 14242   | Use cpv_getkey() instead of dep_getkey() where appropriate.  |
   | zmedico |                                                              |

svn path=/main/branches/prefix/; revision=14247

pym/_emerge/FakeVartree.py
pym/portage/__init__.py
pym/portage/dep.py

index c4eec6d689b1d8eeafa267fb23760af3c4563959..25bed29056de91d2f1c1aedf3545df0526fd7c34 100644 (file)
@@ -52,7 +52,7 @@ class FakeVartree(portage.vartree):
                                else:
                                        metadata = dict(izip(mykeys, real_dbapi.aux_get(cpv, mykeys)))
                                myslot = metadata["SLOT"]
-                               mycp = portage.dep_getkey(cpv)
+                               mycp = portage.cpv_getkey(cpv)
                                myslot_atom = "%s:%s" % (mycp, myslot)
                                try:
                                        mycounter = long(metadata["COUNTER"])
index 3d7b2dd3899ed24bd6afb51dc02d4d03c6805317..ef3910c44bc0447274a050f5e2f5765743dd9014 100644 (file)
@@ -2093,7 +2093,7 @@ class config(object):
                                cpv=catpkgsplit(x)
                                if not x:
                                        continue
-                               mycatpkg=dep_getkey(x)
+                               mycatpkg = cpv_getkey(x)
                                if mycatpkg in self.pprovideddict:
                                        self.pprovideddict[mycatpkg].append(x)
                                else:
@@ -2882,7 +2882,7 @@ class config(object):
                return None
 
        def _getKeywords(self, cpv, metadata):
-               cp = dep_getkey(cpv)
+               cp = cpv_getkey(cpv)
                pkg = "%s:%s" % (cpv, metadata["SLOT"])
                keywords = [[x for x in metadata["KEYWORDS"].split() if x != "-*"]]
                pos = len(keywords)
@@ -2925,7 +2925,7 @@ class config(object):
                # Repoman may modify this attribute as necessary.
                pgroups = self["ACCEPT_KEYWORDS"].split()
                match=0
-               cp = dep_getkey(cpv)
+               cp = cpv_getkey(cpv)
                pkgdict = self.pkeywordsdict.get(cp)
                matches = False
                if pkgdict:
index f2c11b23937b27e0defa64b99076bc40e5c13cca..1e27e882d9c7559465c7abd8f15268c091d7feba 100644 (file)
@@ -527,9 +527,8 @@ class Atom(object):
                def __init__(self, forbid_overlap=False):
                        self.overlap = self._overlap(forbid=forbid_overlap)
 
-       def __init__(self, s):
-               if not isvalidatom(s, allow_blockers=True):
-                       raise InvalidAtom(s)
+       def __init__(self, mypkg):
+               s = mypkg
                obj_setattr = object.__setattr__
                obj_setattr(self, '_str', s)
 
@@ -543,11 +542,29 @@ class Atom(object):
                else:
                        blocker = False
                obj_setattr(self, "blocker", blocker)
-
-               obj_setattr(self, "cp", dep_getkey(s))
-               obj_setattr(self, "cpv", dep_getcpv(s))
-               obj_setattr(self, "slot", dep_getslot(s))
-               obj_setattr(self, "operator", get_operator(s))
+               m = _atom_re.match(s)
+               if m is None:
+                       raise InvalidAtom(mypkg)
+               if m.group('op'):
+                       op = m.group(_atom_re.groupindex['op'] + 1)
+                       cpv = m.group(_atom_re.groupindex['op'] + 2)
+                       cp = m.group(_atom_re.groupindex['op'] + 3)
+                       slot = m.group(_atom_re.groupindex['star'] - 2)
+               elif m.group('star'):
+                       op = '=*'
+                       cpv = m.group(_atom_re.groupindex['star'] + 1)
+                       cp = m.group(_atom_re.groupindex['star'] + 2)
+                       slot = m.group(_atom_re.groupindex['simple'] - 2)
+               elif m.group('simple'):
+                       op = None
+                       cpv = cp = m.group(_atom_re.groupindex['simple'] + 1)
+                       slot = m.group(_atom_re.groups - 1)
+               else:
+                       raise AssertionError("required group not found in atom: '%s'" % s)
+               obj_setattr(self, "cp", cp)
+               obj_setattr(self, "cpv", cpv)
+               obj_setattr(self, "slot", slot)
+               obj_setattr(self, "operator", op)
 
                use = dep_getusedeps(s)
                if use:
@@ -852,30 +869,32 @@ _cat = r'[\w+][\w+.-]*'
 # It must not begin with a hyphen,
 # and must not end in a hyphen followed by one or more digits.
 _pkg = \
-r'''([\w+](
-       -?                    # All other 2-char are handled by next
-       |[\w+]*               # No hyphens - no problems
-       |[\w+-]+(             # String with a hyphen...
-               [A-Za-z+_-]       # ... must end in nondigit
-               |[A-Za-z+_][\w+]+ # ... or in nondigit and then nonhyphens
+r'''[\w+](?:
+       -?                     # All other 2-char are handled by next
+       |[\w+]*?               # No hyphens - no problems
+       |[\w+-]+?(?:           # String with a hyphen...
+               [A-Za-z+_-]        # ... must end in nondigit
+               |[A-Za-z+_][\w+]+? # ... or in nondigit and then nonhyphens
        )
-))'''
+)'''
 
 # 2.1.3 A slot name may contain any of the characters [A-Za-z0-9+_.-].
 # It must not begin with a hyphen or a dot.
-_slot = r'(:[\w+][\w+.-]*)?'
+_slot = r':([\w+][\w+.-]*)'
+_optional_slot = '(?:' + _slot + ')?'
 
 _use = r'(\[.*\])?'
 _op = r'([=~]|[><]=?)'
-_cp = _cat + '/' + _pkg
-_cpv = _cp + '-' + _version
+_cp = '(' + _cat + '/' + _pkg + ')'
+_cpv = '(' + _cp + '-' + _version + ')'
 
 _cpv_re = re.compile('^' + _cpv + '$', re.VERBOSE)
-_atom_re = re.compile(r'^(' +
-       '(' + _op + _cpv + _slot + _use + ')|' +
-       '(=' + _cpv + r'\*' + _slot + _use + ')|' +
-       '(' + _cp + _slot + _use + ')' +
+_atom_re = re.compile('^(?:' +
+       '(?P<op>' + _op + _cpv + _optional_slot + _use + ')|' +
+       '(?P<star>=' + _cpv + r'\*' + _optional_slot + _use + ')|' +
+       '(?P<simple>' + _cp + _optional_slot + _use + ')' +
        ')$', re.VERBOSE)
+_key_re = re.compile(_cp + '(?:-' + _version + '|' + _slot + '|$)', re.VERBOSE)
 
 def isvalidatom(atom, allow_blockers=False):
        """
@@ -919,7 +938,6 @@ def isvalidatom(atom, allow_blockers=False):
 def isjustname(mypkg):
        """
        Checks to see if the atom is only the package name (no version parts).
-       Raises InvalidAtom if the input is invalid.
 
        Example usage:
                >>> isjustname('=media-libs/test-3.0')