From 414daa3dcb127aa7bea5baaf921fbf6f76fa9482 Mon Sep 17 00:00:00 2001 From: fuzzyray Date: Wed, 22 Sep 2010 20:37:14 +0000 Subject: [PATCH] Merge from genscripts r456: douglasjanderson 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 | 29 ++++++++--------- pym/gentoolkit/test/test_cpv.py | 57 +++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/pym/gentoolkit/cpv.py b/pym/gentoolkit/cpv.py index 663afea..6e85767 100644 --- a/pym/gentoolkit/cpv.py +++ b/pym/gentoolkit/cpv.py @@ -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: diff --git a/pym/gentoolkit/test/test_cpv.py b/pym/gentoolkit/test/test_cpv.py index 3ce4dee..3749404 100644 --- a/pym/gentoolkit/test/test_cpv.py +++ b/pym/gentoolkit/test/test_cpv.py @@ -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) -- 2.26.2