# =======
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+_]+$")
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)
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:
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)