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