1 |
Manuel RĂ¼ger noticed that most of haskell packages's 'metadata.xml' |
2 |
contain duplicate information: |
3 |
<herd>haskell</herd> |
4 |
<maintainer><email>haskell@g.o</email></maintainer> |
5 |
|
6 |
I've added a check against 'herds.xml's email aliases. |
7 |
|
8 |
Now repoman warns about such redundancy: |
9 |
metadata.warning 1 |
10 |
dev-haskell/text/metadata.xml: use <herd>haskell</herd> instead of maintainer 'haskell@g.o' |
11 |
|
12 |
Quick scan [1] of tree revealed a lot of non-haskell packages |
13 |
having redundancy: samba, xemacs, sci, gpe, etc, etc. |
14 |
|
15 |
[1]: https://github.com/trofi/gentoo-qa/blob/master/check_herd.sh |
16 |
Run in the root tree of gentoo-x86: |
17 |
gentoo-x86 $ ~/portage/gentoo-qa/check_herd.sh | wc -l |
18 |
571 |
19 |
# some examples: |
20 |
gentoo-x86 $ ~/portage/gentoo-qa/check_herd.sh |
21 |
./app-admin/haskell-updater/metadata.xml: <email>haskell@g.o</email> |
22 |
./app-editors/xemacs/metadata.xml: <email>xemacs@g.o</email> |
23 |
./app-i18n/ibus-table-chinese/metadata.xml: <email>cjk@g.o</email> |
24 |
./app-portage/fquery/metadata.xml: <email>haskell@g.o</email> |
25 |
./app-text/glosung/metadata.xml: <email>theology@g.o</email> |
26 |
... # a lot of haskell |
27 |
./dev-lang/tcl/metadata.xml: <email>tcltk@g.o</email> |
28 |
./dev-libs/Ice/metadata.xml: <email>cpp@g.o</email> |
29 |
./dev-libs/cloog/metadata.xml: <email>toolchain@g.o</email> |
30 |
./dev-libs/cvector/metadata.xml: <email>sci@g.o</email> |
31 |
./dev-libs/iniparser/metadata.xml: <email>samba@g.o</email> |
32 |
./dev-libs/isl/metadata.xml: <email>toolchain@g.o</email> |
33 |
... |
34 |
|
35 |
Signed-off-by: Sergei Trofimovich <slyfox@g.o> |
36 |
--- |
37 |
bin/repoman | 13 +++++++++++++ |
38 |
pym/repoman/herdbase.py | 21 +++++++++++++++++---- |
39 |
pym/repoman/utilities.py | 19 +++++++++++++++++++ |
40 |
3 files changed, 49 insertions(+), 4 deletions(-) |
41 |
|
42 |
diff --git a/bin/repoman b/bin/repoman |
43 |
index c36ace1..74a4d44 100755 |
44 |
--- a/bin/repoman |
45 |
+++ b/bin/repoman |
46 |
@@ -1762,6 +1762,19 @@ for x in effective_scanlist: |
47 |
fails["metadata.bad"].append("%s/metadata.xml: %s" % (x, e)) |
48 |
del e |
49 |
|
50 |
+ # check if 'metadata.xml' contains redundant |
51 |
+ # '<maintainer><email>some-herd@g.o</email></maintainer>' |
52 |
+ # email address. Instead it should contain |
53 |
+ # '<herd>some-herd</herd>' |
54 |
+ if herd_base is not None: |
55 |
+ for m_email in utilities.get_maintainer_emails_from_metadata(_metadata_xml): |
56 |
+ herd_name = herd_base.herd_by_herd_email(m_email) |
57 |
+ if herd_name is not None: |
58 |
+ stats["metadata.warning"] += 1 |
59 |
+ fails["metadata.warning"].append("%s/metadata.xml:" |
60 |
+ " use <herd>%s</herd> instead of maintainer '%s'" % \ |
61 |
+ (x, herd_name, m_email)) |
62 |
+ |
63 |
# Only carry out if in package directory or check forced |
64 |
if xmllint_capable and not metadata_bad: |
65 |
# xmlint can produce garbage output even on success, so only dump |
66 |
diff --git a/pym/repoman/herdbase.py b/pym/repoman/herdbase.py |
67 |
index c5b88ff..ae7c4e4 100644 |
68 |
--- a/pym/repoman/herdbase.py |
69 |
+++ b/pym/repoman/herdbase.py |
70 |
@@ -34,9 +34,10 @@ def _make_email(nick_name): |
71 |
|
72 |
|
73 |
class HerdBase(object): |
74 |
- def __init__(self, herd_to_emails, all_emails): |
75 |
+ def __init__(self, herd_to_emails, all_emails, herd_email_to_herd): |
76 |
self.herd_to_emails = herd_to_emails |
77 |
self.all_emails = all_emails |
78 |
+ self.herd_email_to_herd = herd_email_to_herd |
79 |
|
80 |
def known_herd(self, herd_name): |
81 |
return herd_name in self.herd_to_emails |
82 |
@@ -47,6 +48,9 @@ class HerdBase(object): |
83 |
def maintainer_in_herd(self, nick_name, herd_name): |
84 |
return _make_email(nick_name) in self.herd_to_emails[herd_name] |
85 |
|
86 |
+ def herd_by_herd_email(self, email): |
87 |
+ return self.herd_email_to_herd.get(email) |
88 |
+ |
89 |
class _HerdsTreeBuilder(xml.etree.ElementTree.TreeBuilder): |
90 |
""" |
91 |
Implements doctype() as required to avoid deprecation warnings with |
92 |
@@ -57,6 +61,7 @@ class _HerdsTreeBuilder(xml.etree.ElementTree.TreeBuilder): |
93 |
|
94 |
def make_herd_base(filename): |
95 |
herd_to_emails = dict() |
96 |
+ herd_email_to_herd = dict() |
97 |
all_emails = set() |
98 |
|
99 |
try: |
100 |
@@ -82,6 +87,11 @@ def make_herd_base(filename): |
101 |
herd_name = _herd_name.text.strip() |
102 |
del _herd_name |
103 |
|
104 |
+ _herd_email = h.find('email') |
105 |
+ herd_email = _herd_email.text.strip() |
106 |
+ del _herd_email |
107 |
+ herd_email_to_herd[herd_email] = herd_name |
108 |
+ |
109 |
maintainers = h.findall('maintainer') |
110 |
herd_emails = set() |
111 |
for m in maintainers: |
112 |
@@ -95,7 +105,7 @@ def make_herd_base(filename): |
113 |
|
114 |
herd_to_emails[herd_name] = herd_emails |
115 |
|
116 |
- return HerdBase(herd_to_emails, all_emails) |
117 |
+ return HerdBase(herd_to_emails, all_emails, herd_email_to_herd) |
118 |
|
119 |
|
120 |
if __name__ == '__main__': |
121 |
@@ -104,12 +114,15 @@ if __name__ == '__main__': |
122 |
assert(h.known_herd('sound')) |
123 |
assert(not h.known_herd('media-sound')) |
124 |
|
125 |
- assert(h.known_maintainer('sping')) |
126 |
- assert(h.known_maintainer('sping@g.o')) |
127 |
+ assert(h.known_maintainer('slyfox')) |
128 |
+ assert(h.known_maintainer('slyfox@g.o')) |
129 |
assert(not h.known_maintainer('portage')) |
130 |
|
131 |
assert(h.maintainer_in_herd('zmedico@g.o', 'tools-portage')) |
132 |
assert(not h.maintainer_in_herd('pva@g.o', 'tools-portage')) |
133 |
|
134 |
+ assert(h.herd_by_herd_email('haskell@g.o') == 'haskell') |
135 |
+ assert(h.herd_by_herd_email('slyfox@g.o') is None) |
136 |
+ |
137 |
import pprint |
138 |
pprint.pprint(h.herd_to_emails) |
139 |
diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py |
140 |
index 415825e..2815529 100644 |
141 |
--- a/pym/repoman/utilities.py |
142 |
+++ b/pym/repoman/utilities.py |
143 |
@@ -17,6 +17,7 @@ __all__ = [ |
144 |
"get_commit_message_with_editor", |
145 |
"get_commit_message_with_stdin", |
146 |
"get_committer_name", |
147 |
+ "get_maintainer_emails_from_metadata", |
148 |
"have_ebuild_dir", |
149 |
"have_profile_dir", |
150 |
"parse_metadata_use", |
151 |
@@ -215,6 +216,24 @@ def parse_metadata_use(xml_tree): |
152 |
|
153 |
return uselist |
154 |
|
155 |
+def get_maintainer_emails_from_metadata(xml_tree): |
156 |
+ """ |
157 |
+ Returns a list of explicit emails of maintainers |
158 |
+ """ |
159 |
+ m_emails = list() |
160 |
+ |
161 |
+ maintainers = xml_tree.findall('maintainer') |
162 |
+ if maintainers is None: |
163 |
+ return m_emails |
164 |
+ |
165 |
+ for m in maintainers: |
166 |
+ _m_email = m.find('email') |
167 |
+ m_email = _m_email.text.strip() |
168 |
+ m_emails.append(m_email) |
169 |
+ |
170 |
+ return m_emails |
171 |
+ |
172 |
+ |
173 |
class UnknownHerdsError(ValueError): |
174 |
def __init__(self, herd_names): |
175 |
_plural = len(herd_names) != 1 |
176 |
-- |
177 |
1.8.5.5 |