1 |
Validate Display-If-Installed with EAPI 0 or 5. |
2 |
Add support for trailing wildcard matching for Display-If-Profile. |
3 |
|
4 |
Bug: https://bugs.gentoo.org/577372 |
5 |
--- |
6 |
pym/portage/news.py | 42 ++++++++++++++++++++++++++++++------------ |
7 |
1 file changed, 30 insertions(+), 12 deletions(-) |
8 |
|
9 |
diff --git a/pym/portage/news.py b/pym/portage/news.py |
10 |
index 177f9db..fa6fb00 100644 |
11 |
--- a/pym/portage/news.py |
12 |
+++ b/pym/portage/news.py |
13 |
@@ -266,14 +266,24 @@ class NewsItem(object): |
14 |
f.close() |
15 |
self.restrictions = {} |
16 |
invalids = [] |
17 |
+ news_format = None |
18 |
+ |
19 |
+ # Look for News-Item-Format |
20 |
for i, line in enumerate(lines): |
21 |
- # Optimization to ignore regex matchines on lines that |
22 |
- # will never match |
23 |
format_match = _formatRE.match(line) |
24 |
- if (format_match is not None and |
25 |
- not fnmatch.fnmatch(format_match.group(1), '1.*')): |
26 |
+ if format_match is not None: |
27 |
+ news_format = format_match.group(1) |
28 |
+ if fnmatch.fnmatch(news_format, '[12].*'): |
29 |
+ break |
30 |
invalids.append((i + 1, line.rstrip('\n'))) |
31 |
- break |
32 |
+ |
33 |
+ if news_format is None: |
34 |
+ invalids.append((0, 'News-Item-Format unspecified')) |
35 |
+ |
36 |
+ # Parse the rest |
37 |
+ for i, line in enumerate(lines): |
38 |
+ # Optimization to ignore regex matchines on lines that |
39 |
+ # will never match |
40 |
if not line.startswith('D'): |
41 |
continue |
42 |
restricts = { _installedRE : DisplayInstalledRestriction, |
43 |
@@ -282,13 +292,14 @@ class NewsItem(object): |
44 |
for regex, restriction in restricts.items(): |
45 |
match = regex.match(line) |
46 |
if match: |
47 |
- restrict = restriction(match.groups()[0].strip()) |
48 |
+ restrict = restriction(match.groups()[0].strip(), news_format) |
49 |
if not restrict.isValid(): |
50 |
invalids.append((i + 1, line.rstrip("\n"))) |
51 |
else: |
52 |
self.restrictions.setdefault( |
53 |
id(restriction), []).append(restrict) |
54 |
continue |
55 |
+ |
56 |
if invalids: |
57 |
self._valid = False |
58 |
msg = [] |
59 |
@@ -321,13 +332,14 @@ class DisplayProfileRestriction(DisplayRestriction): |
60 |
if the user is running a specific profile. |
61 |
""" |
62 |
|
63 |
- def __init__(self, profile): |
64 |
+ def __init__(self, profile, news_format): |
65 |
self.profile = profile |
66 |
+ self.format = news_format |
67 |
|
68 |
def checkRestriction(self, **kwargs): |
69 |
- if self.profile == kwargs['profile']: |
70 |
- return True |
71 |
- return False |
72 |
+ if fnmatch.fnmatch(self.format, '2.*') and self.profile.endswith('/*'): |
73 |
+ return (kwargs['profile'].startswith(self.profile[:-1])) |
74 |
+ return (kwargs['profile'] == self.profile) |
75 |
|
76 |
class DisplayKeywordRestriction(DisplayRestriction): |
77 |
""" |
78 |
@@ -335,8 +347,9 @@ class DisplayKeywordRestriction(DisplayRestriction): |
79 |
if the user is running a specific keyword. |
80 |
""" |
81 |
|
82 |
- def __init__(self, keyword): |
83 |
+ def __init__(self, keyword, news_format): |
84 |
self.keyword = keyword |
85 |
+ self.format = news_format |
86 |
|
87 |
def checkRestriction(self, **kwargs): |
88 |
if kwargs['config'].get('ARCH', '') == self.keyword: |
89 |
@@ -349,10 +362,15 @@ class DisplayInstalledRestriction(DisplayRestriction): |
90 |
if the user has that item installed. |
91 |
""" |
92 |
|
93 |
- def __init__(self, atom): |
94 |
+ def __init__(self, atom, news_format): |
95 |
self.atom = atom |
96 |
+ self.format = news_format |
97 |
|
98 |
def isValid(self): |
99 |
+ if fnmatch.fnmatch(self.format, '1.*'): |
100 |
+ return isvalidatom(self.atom, eapi='0') |
101 |
+ if fnmatch.fnmatch(self.format, '2.*'): |
102 |
+ return isvalidatom(self.atom, eapi='5') |
103 |
return isvalidatom(self.atom) |
104 |
|
105 |
def checkRestriction(self, **kwargs): |
106 |
-- |
107 |
2.10.0 |