Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r14466 - main/trunk/pym/portage
Date: Wed, 30 Sep 2009 05:19:09
Message-Id: E1Msral-00023x-Iw@stork.gentoo.org
1 Author: zmedico
2 Date: 2009-09-30 05:19:06 +0000 (Wed, 30 Sep 2009)
3 New Revision: 14466
4
5 Modified:
6 main/trunk/pym/portage/__init__.py
7 main/trunk/pym/portage/dep.py
8 main/trunk/pym/portage/versions.py
9 Log:
10 Take regular expressions from portage.dep and use them to reimplement
11 portage.versions.pkgsplit(). This simplifies the code and helps
12 guarantee consistency package name/version validation.
13
14
15 Modified: main/trunk/pym/portage/__init__.py
16 ===================================================================
17 --- main/trunk/pym/portage/__init__.py 2009-09-29 23:25:19 UTC (rev 14465)
18 +++ main/trunk/pym/portage/__init__.py 2009-09-30 05:19:06 UTC (rev 14466)
19 @@ -8154,7 +8154,7 @@
20 return None
21 return deplist
22
23 -_cpv_key_re = re.compile('^' + dep._cpv + '$', re.VERBOSE)
24 +_cpv_key_re = re.compile('^' + versions._cpv + '$', re.VERBOSE)
25 def cpv_getkey(mycpv):
26 """Calls pkgsplit on a cpv and returns only the cp."""
27 m = _cpv_key_re.match(mycpv)
28
29 Modified: main/trunk/pym/portage/dep.py
30 ===================================================================
31 --- main/trunk/pym/portage/dep.py 2009-09-29 23:25:19 UTC (rev 14465)
32 +++ main/trunk/pym/portage/dep.py 2009-09-30 05:19:06 UTC (rev 14466)
33 @@ -24,7 +24,7 @@
34 from portage.exception import InvalidData, InvalidAtom
35 from portage.localization import _
36 from portage.versions import catpkgsplit, catsplit, \
37 - pkgcmp, pkgsplit, ververify, _version
38 + pkgcmp, pkgsplit, ververify, _cp, _cpv
39 import portage.cache.mappings
40
41 if sys.hexversion >= 0x3000000:
42 @@ -806,23 +806,12 @@
43
44 # \w is [a-zA-Z0-9_]
45
46 -# 2.1.1 A category name may contain any of the characters [A-Za-z0-9+_.-].
47 -# It must not begin with a hyphen or a dot.
48 -_cat = r'[\w+][\w+.-]*'
49 -
50 -# 2.1.2 A package name may contain any of the characters [A-Za-z0-9+_-].
51 -# It must not begin with a hyphen,
52 -# and must not end in a hyphen followed by one or more digits.
53 -_pkg = r'[\w+][\w+-]*?'
54 -
55 # 2.1.3 A slot name may contain any of the characters [A-Za-z0-9+_.-].
56 # It must not begin with a hyphen or a dot.
57 _slot = r':([\w+][\w+.-]*)'
58
59 _use = r'\[.*\]'
60 _op = r'([=~]|[><]=?)'
61 -_cp = '(' + _cat + '/' + _pkg + '(-' + _version + ')?)'
62 -_cpv = '(' + _cp + '-' + _version + ')'
63
64 _atom_re = re.compile('^(?P<without_use>(?:' +
65 '(?P<op>' + _op + _cpv + ')|' +
66
67 Modified: main/trunk/pym/portage/versions.py
68 ===================================================================
69 --- main/trunk/pym/portage/versions.py 2009-09-29 23:25:19 UTC (rev 14465)
70 +++ main/trunk/pym/portage/versions.py 2009-09-30 05:19:06 UTC (rev 14466)
71 @@ -5,9 +5,27 @@
72
73 import re
74
75 -_version = r'(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+))?'
76
77 -ver_regexp = re.compile("^" + _version + "$")
78 +# \w is [a-zA-Z0-9_]
79 +
80 +# 2.1.1 A category name may contain any of the characters [A-Za-z0-9+_.-].
81 +# It must not begin with a hyphen or a dot.
82 +_cat = r'[\w+][\w+.-]*'
83 +
84 +# 2.1.2 A package name may contain any of the characters [A-Za-z0-9+_-].
85 +# It must not begin with a hyphen,
86 +# and must not end in a hyphen followed by one or more digits.
87 +_pkg = r'[\w+][\w+-]*?'
88 +
89 +_v = r'(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)'
90 +_rev = r'\d+'
91 +_vr = _v + '(-r(' + _rev + '))?'
92 +
93 +_cp = '(' + _cat + '/' + _pkg + '(-' + _vr + ')?)'
94 +_cpv = '(' + _cp + '-' + _vr + ')'
95 +_pv = '(?P<pn>' + _pkg + '(?P<pn_inval>-' + _vr + ')?)' + '-(?P<ver>' + _v + ')(-r(?P<rev>' + _rev + '))?'
96 +
97 +ver_regexp = re.compile("^" + _vr + "$")
98 suffix_regexp = re.compile("^(alpha|beta|rc|pre|p)(\\d*)$")
99 suffix_value = {"pre": -2, "p": 0, "alpha": -4, "beta": -3, "rc": -1}
100 endversion_keys = ["pre", "p", "alpha", "beta", "rc"]
101 @@ -208,51 +226,25 @@
102 return None
103 return vercmp("-".join(pkg1[1:]), "-".join(pkg2[1:]))
104
105 -pkgcache={}
106 +_pv_re = re.compile('^' + _pv + '$', re.VERBOSE)
107
108 def pkgsplit(mypkg,silent=1):
109 - try:
110 - if not pkgcache[mypkg]:
111 - return None
112 - return pkgcache[mypkg]
113 - except KeyError:
114 - pass
115 - myparts=mypkg.split("-")
116 -
117 - if len(myparts)<2:
118 - if not silent:
119 - print(_("!!! Name error in %s: missing a version or name part.") % mypkg)
120 - pkgcache[mypkg]=None
121 +
122 + m = _pv_re.match(mypkg)
123 + if m is None:
124 return None
125
126 - #verify rev
127 - revok=0
128 - myrev=myparts[-1]
129 - if len(myrev) and myrev[0]=="r":
130 - try:
131 - int(myrev[1:])
132 - revok=1
133 - except ValueError: # from int()
134 - pass
135 - if revok:
136 - verPos = -2
137 - revision = myparts[-1]
138 - else:
139 - verPos = -1
140 - revision = "r0"
141 -
142 - if ververify(myparts[verPos]):
143 - if len(myparts)== (-1*verPos):
144 - pkgcache[mypkg]=None
145 - return None
146 - else:
147 - myval=("-".join(myparts[:verPos]),myparts[verPos],revision)
148 - pkgcache[mypkg]=myval
149 - return myval
150 - else:
151 - pkgcache[mypkg]=None
152 + if m.group('pn_inval') is not None:
153 + # package name appears to have a version-like suffix
154 return None
155
156 + rev = m.group('rev')
157 + if rev is None:
158 + rev = '0'
159 + rev = 'r' + rev
160 +
161 + return (m.group('pn'), m.group('ver'), rev)
162 +
163 catcache={}
164 def catpkgsplit(mydata,silent=1):
165 """