1
1
"""An Atom."""
2
2
3
+ import re
4
+
3
5
4
6
class AtomException (Exception ):
5
7
"""An exception in this class."""
6
8
pass
7
9
8
10
11
+ # from lib/portage/version.py
12
+ # PMS 3.1.3: A slot name may contain any of the characters [A-Za-z0-9+_.-].
13
+ # It must not begin with a hyphen or a dot.
14
+ _slot = r"([\w+][\w+.-]*)"
15
+
16
+ # 2.1.1 A category name may contain any of the characters [A-Za-z0-9+_.-].
17
+ # It must not begin with a hyphen or a dot.
18
+ _cat = r"[\w+][\w+.-]*"
19
+
20
+ # 2.1.2 A package name may contain any of the characters [A-Za-z0-9+_-].
21
+ # It must not begin with a hyphen,
22
+ # and must not end in a hyphen followed by one or more digits.
23
+ _pkg = r"[\w+][\w+-]*?"
24
+
25
+ _v = r"(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)"
26
+ _rev = r"\d+"
27
+ _vr = _v + "(-r(" + _rev + "))?"
28
+
29
+ _cp = "(" + _cat + "/" + _pkg + "(-" + _vr + ")?)"
30
+ _cpv = "(" + _cp + "-" + _vr + ")"
31
+ _pv = (
32
+ "(?P<pn>"
33
+ + _pkg
34
+ + "(?P<pn_inval>-"
35
+ + _vr
36
+ + ")?)"
37
+ + "-(?P<ver>"
38
+ + _v
39
+ + ")(-r(?P<rev>"
40
+ + _rev
41
+ + "))?"
42
+ )
43
+
44
+ _pv_re = None
45
+
46
+
47
+ def _get_pv_re ():
48
+ global _pv_re
49
+ if _pv_re is not None :
50
+ return _pv_re
51
+
52
+ _pv_re = re .compile (r"^" + _pv + r"$" , re .VERBOSE | re .UNICODE )
53
+
54
+ return _pv_re
55
+
56
+
57
+ def _pkgsplit (mypkg : str ):
58
+ """
59
+ @param mypkg: pv
60
+ @return:
61
+ 1. None if input is invalid.
62
+ 2. (pn, ver, rev) if input is pv
63
+ """
64
+ m = _get_pv_re ().match (mypkg )
65
+ if m is None :
66
+ return None
67
+
68
+ if m .group ("pn_inval" ) is not None :
69
+ # package name appears to have a version-like suffix
70
+ return None
71
+
72
+ rev = m .group ("rev" )
73
+ if rev is None :
74
+ rev = "0"
75
+ rev = "r" + rev
76
+
77
+ return (m .group ("pn" ), m .group ("ver" ), rev )
78
+
79
+
9
80
class Atom (object ):
10
81
11
82
def __init__ (self , atom ):
@@ -26,10 +97,10 @@ def __init__(self, atom):
26
97
27
98
# Split off version.
28
99
try :
29
- temp = self . package . index ( "-" )
30
- if temp > - 1 :
31
- self .version = self .package [ temp + 1 :]
32
- self .package = self .package [: temp ]
100
+ # If atom don't start with "=" we assume there is no version
101
+ if '=' in atom :
102
+ self .package , self . version , rev = _pkgsplit ( self .package )
103
+ self .version = f" { self .version } - { rev } "
33
104
except ValueError :
34
105
pass
35
106
0 commit comments