Merge from genscripts r456: douglasjanderson
authorfuzzyray <fuzzyray@gentoo.org>
Wed, 22 Sep 2010 20:37:14 +0000 (20:37 -0000)
committerfuzzyray <fuzzyray@gentoo.org>
Wed, 22 Sep 2010 20:37:14 +0000 (20:37 -0000)
Revert r430 and fix the problem within the existing code without relying on
pkgsplit (it's slow); adds test case to catch the problem and future
regressions. Bug #316961

Merge from genscripts r433: brian.dolbec
fix a regression due to pkgsplit returning '-r0'.

Merge from genscripts r430: brian.dolbec
fix bug 316961. commented out the pkgname validation due to a false result. Why
is it necessary anyway?

svn path=/trunk/gentoolkit/; revision=801

pym/gentoolkit/cpv.py
pym/gentoolkit/test/test_cpv.py

index 663afea31d4c6543028aa986a2f6af8fd6ae1b14..6e85767d48c5be69afe266a0880499eaf5ace6a6 100644 (file)
@@ -31,7 +31,7 @@ from gentoolkit import errors
 # =======
 
 isvalid_version_re = re.compile("^(?:cvs\\.)?(?:\\d+)(?:\\.\\d+)*[a-z]?"
-    "(?:_(p(?:re)?|beta|alpha|rc)\\d*)*$")
+       "(?:_(p(?:re)?|beta|alpha|rc)\\d*)*$")
 isvalid_cat_re = re.compile("^(?:[a-zA-Z0-9][-a-zA-Z0-9+._]*(?:/(?!$))?)+$")
 _pkg_re = re.compile("^[a-zA-Z0-9+_]+$")
 
@@ -225,9 +225,8 @@ def split_cpv(cpv, validate=True):
                if rev:
                        revision = rev
 
-       if validate and not isvalid_version_re.match(pkg_chunks[-1]):
-               raise errors.GentoolkitInvalidCPV(cpv)
-       version = pkg_chunks.pop(-1)
+       if isvalid_version_re.match(pkg_chunks[-1]):
+               version = pkg_chunks.pop(-1)
 
        if not isvalid_pkg_name(pkg_chunks):
                raise errors.GentoolkitInvalidCPV(cpv)
@@ -237,19 +236,19 @@ def split_cpv(cpv, validate=True):
 
 
 def isvalid_pkg_name(chunks):
-    if not chunks[0]:
-        # this means a leading -
-        return False
-    mf = _pkg_re.match
-    if not all(not s or mf(s) for s in chunks):
-        return False
-    if chunks[-1].isdigit() or not chunks[-1]:
-        # not allowed.
-        return False
-    return True
+       if not chunks[0]:
+               # this means a leading -
+               return False
+       mf = _pkg_re.match
+       if not all(not s or mf(s) for s in chunks):
+               return False
+       if chunks[-1].isdigit() or not chunks[-1]:
+               # not allowed.
+               return False
+       return True
 
 
 def isvalid_rev(s):
-    return s and s[0] == 'r' and s[1:].isdigit()
+       return s and s[0] == 'r' and s[1:] != '0' and s[1:].isdigit() 
 
 # vim: set ts=4 sw=4 tw=79:
index 3ce4dee01123a77c87cb9f1cac5193efbd84d515..374940449f95b8267a6ee775fb5c6b5759db8f3a 100644 (file)
@@ -77,6 +77,63 @@ class TestGentoolkitCPV(unittest.TestCase):
                vt = ('sys-auth/pambase-20080318', 'sys-auth/pambase-20080318')
                self.failUnless(compare_strs(vt[0], vt[1]) == 0)
 
+       def test_chunk_splitting(self):
+               all_tests = [
+                       # simple
+                       ('sys-apps/portage-2.2', {
+                               'category': 'sys-apps',
+                               'name': 'portage',
+                               'cp': 'sys-apps/portage',
+                               'version': '2.2',
+                               'revision': '',
+                               'fullversion': '2.2'
+                       }),
+                       # with rc
+                       ('sys-apps/portage-2.2_rc10', {
+                               'category': 'sys-apps',
+                               'name': 'portage',
+                               'cp': 'sys-apps/portage',
+                               'version': '2.2_rc10',
+                               'revision': '',
+                               'fullversion': '2.2_rc10'
+                       }),
+                       # with revision
+                       ('sys-apps/portage-2.2_rc10-r1', {
+                               'category': 'sys-apps',
+                               'name': 'portage',
+                               'cp': 'sys-apps/portage',
+                               'version': '2.2_rc10',
+                               'revision': 'r1',
+                               'fullversion': '2.2_rc10-r1'
+                       }),
+                       # with dash (-) in name (Bug #316961)
+                       ('c-portage', {
+                               'category': '',
+                               'name': 'c-portage',
+                               'cp': 'c-portage',
+                               'version': '',
+                               'revision': '',
+                               'fullversion': ''
+                       }),
+                       # with dash (-) in name (Bug #316961)
+                       ('sys-apps/c-portage-2.2_rc10-r1', {
+                               'category': 'sys-apps',
+                               'name': 'c-portage',
+                               'cp': 'sys-apps/c-portage',
+                               'version': '2.2_rc10',
+                               'revision': 'r1',
+                               'fullversion': '2.2_rc10-r1'
+                       }),
+               ]
+
+               for test in all_tests:
+                       cpv = CPV(test[0])
+                       keys = ('category', 'name', 'cp', 'version', 'revision', 'fullversion')
+                       for k in keys:
+                               self.failUnlessEqual(
+                                       getattr(cpv, k), test[1][k]
+                               )
+
 
 def test_main():
        test_support.run_unittest(TestGentoolkitCPV)