Gentoo Archives: gentoo-commits

From: Sebastian Pipping <sping@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/metagen:master commit in: docs/, metagen/
Date: Sun, 21 Feb 2016 22:15:01
Message-Id: 1456092695.4083e1ee5e119dc278cecb499935cf366cfe8c93.sping@gentoo
1 commit: 4083e1ee5e119dc278cecb499935cf366cfe8c93
2 Author: Sebastian Pipping <sebastian <AT> pipping <DOT> org>
3 AuthorDate: Sun Feb 21 21:02:40 2016 +0000
4 Commit: Sebastian Pipping <sping <AT> gentoo <DOT> org>
5 CommitDate: Sun Feb 21 22:11:35 2016 +0000
6 URL: https://gitweb.gentoo.org/proj/metagen.git/commit/?id=4083e1ee
7
8 Add support for GLEP 67 maintainer type (bug #573136)
9
10 docs/metagen.1 | 8 ++++++++
11 metagen/main.py | 28 +++++++++++++++++++++++++++-
12 metagen/metagenerator.py | 10 ++++++++--
13 metagen/test_cli | 22 +++++++++++++---------
14 4 files changed, 56 insertions(+), 12 deletions(-)
15
16 diff --git a/docs/metagen.1 b/docs/metagen.1
17 index db9f76b..6364ece 100644
18 --- a/docs/metagen.1
19 +++ b/docs/metagen.1
20 @@ -42,6 +42,14 @@ maintainer-name
21 -m
22 Uses ECHANGELOG_USER variable. Can be used instead of -e and -n
23
24 +.B --type
25 +|
26 +.B
27 +-t
28 +type
29 + Maintainer type as of GLEP 67; valid types are: "person", "project", "unknown"
30 + (required with --email|-e and --echangelog|-m options)
31 +
32 .B --desc
33 |
34 .B
35
36 diff --git a/metagen/main.py b/metagen/main.py
37 index 671bd02..1e30a20 100755
38 --- a/metagen/main.py
39 +++ b/metagen/main.py
40 @@ -34,6 +34,12 @@ from metagen import metagenerator
41 PORTDIR = config(local_config=False)["PORTDIR"]
42 HB = herdbase.make_herd_base(os.path.sep.join([PORTDIR, 'metadata', 'herds.xml']))
43
44 +# GLEP 67
45 +_MAINTAINER_TYPE_PERSON = 'person'
46 +_MAINTAINER_TYPE_PROJECT = 'project'
47 +_MAINTAINER_TYPE_UNKNOWN = 'unknown'
48 +_VALID_MAINTAINER_TYPES = (_MAINTAINER_TYPE_PERSON, _MAINTAINER_TYPE_PROJECT, _MAINTAINER_TYPE_UNKNOWN)
49 +
50 def parse_echangelog_variable(name, email):
51 """Extract developer name and email from ECHANGELOG_USER variable"""
52 try:
53 @@ -88,9 +94,11 @@ def generate_xml(options):
54 names = options.name.split(",")
55 if options.desc:
56 descs = options.desc.split(",")
57 + maintainer_types = options.maintainer_type.split(",")
58 metadata.set_maintainer(options.email.split(","),
59 names,
60 - descs
61 + descs,
62 + maintainer_types,
63 )
64
65 if options.long:
66 @@ -109,6 +117,15 @@ def validate_xml(my_xml):
67 return getstatusoutput(cmd)[0]
68
69
70 +def _check_maintainer_type_list(text):
71 + for candidate in text.split(','):
72 + if candidate not in _VALID_MAINTAINER_TYPES:
73 + raise ValueError('"%s" not a valid maintainer type' % candidate)
74 + return text
75 +
76 +_check_maintainer_type_list.__name__ = 'maintainer type'
77 +
78 +
79 if __name__ == '__main__':
80 parser = ArgumentParser(prog='metagen')
81 parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)
82 @@ -128,6 +145,9 @@ if __name__ == '__main__':
83 "This is a shortcut for -e <email> -n <name>")
84 maintainer.add_argument("--desc", "-d", action="store",
85 help="Description of maintainership")
86 + maintainer.add_argument("--type", "-t", dest='maintainer_type', type=_check_maintainer_type_list,
87 + help="Maintainer type as of GLEP 67; valid values are: %s" \
88 + % ', '.join('"%s"' % e for e in _VALID_MAINTAINER_TYPES))
89
90 package = parser.add_argument_group(title='package arguments', description=None)
91 package.add_argument("--long", "-l", action="store",
92 @@ -159,6 +179,12 @@ if __name__ == '__main__':
93 "or maintainer's email address (-e)\n")
94 sys.exit(1)
95
96 + if (options.email or options.echangelog) and not options.maintainer_type:
97 + print red("!!! No maintainer type specified. Please pass one of the following, in addition:")
98 + for candidate in _VALID_MAINTAINER_TYPES:
99 + print red("!!! --type %s" % candidate)
100 + sys.exit(1)
101 +
102 txt = generate_xml(options)
103
104 error_status = validate_xml(txt)
105
106 diff --git a/metagen/metagenerator.py b/metagen/metagenerator.py
107 index 8b69ca0..9c513fa 100755
108 --- a/metagen/metagenerator.py
109 +++ b/metagen/metagenerator.py
110 @@ -22,12 +22,18 @@ class MyMetadata(jaxml.XML_document):
111 for my_herd in opt_herds:
112 self.herd(my_herd)
113
114 - def set_maintainer(self, emails, names, descs):
115 + def set_maintainer(self, emails, names, descs, types):
116 """Set maintainer(s)'s email, name, desc"""
117 + if len(types) != len(emails):
118 + if len(types) != 1:
119 + print red("!!! Nbr maintainer types != nbr emails")
120 + sys.exit(1)
121 + types = [types[0] for _ in emails]
122 +
123 i = 0
124 for e in emails:
125 self._push("maintainer_level")
126 - self.maintainer().email(e)
127 + self.maintainer(type=types[i]).email(e)
128 if names:
129 if len(names) > len(emails):
130 print red("!!! Nbr names > nbr emails")
131
132 diff --git a/metagen/test_cli b/metagen/test_cli
133 index 79fa443..d8b0f42 100755
134 --- a/metagen/test_cli
135 +++ b/metagen/test_cli
136 @@ -18,26 +18,30 @@ set -x
137 ########################################
138
139
140 -#Should fail if ECHANGELOG_USER not set:
141 -ECHANGELOG_USER='First Last <mail@×××××××.org>' metagen -m -Q
142 +#Should fail as -t ... is missing
143 ! metagen -m -Q
144 +! metagen -e mail@×××××××.org -Q
145 +
146 +#Should fail if ECHANGELOG_USER not set:
147 +ECHANGELOG_USER='First Last <mail@×××××××.org>' metagen -m -Q -t person
148 +! metagen -m -Q -t person
149
150 -metagen -e "someguy@g.o" -d "Maint desc" -Q
151 +metagen -e "someguy@g.o" -d "Maint desc" -Q -t person
152
153 -metagen -e "someguy@g.o" -n "Jon Doe" -d "Maint desc" -Q
154 +metagen -e "someguy@g.o" -n "Jon Doe" -d "Maint desc" -Q -t person
155
156 #Should fail if ECHANGELOG_USER not set:
157 -ECHANGELOG_USER='First Last <mail@×××××××.org>' metagen -m -H python -e "foo@×××.com" -d "Foo bar.","Chow fun" -Q
158 -! metagen -m -H python -e "foo@×××.com" -d "Foo bar.","Chow fun" -Q
159 +ECHANGELOG_USER='First Last <mail@×××××××.org>' metagen -m -H python -e "foo@×××.com" -d "Foo bar.","Chow fun" -Q -t person
160 +! metagen -m -H python -e "foo@×××.com" -d "Foo bar.","Chow fun" -Q -t person
161
162 #Should fail:
163 -! metagen -Q
164 +! metagen -Q -t person
165
166 #Should fail:
167 -! metagen -l "Long desc" -Q
168 +! metagen -l "Long desc" -Q -t person
169
170 #Should fail:
171 -! metagen -d "Maintainer desc" -Q
172 +! metagen -d "Maintainer desc" -Q -t person
173
174
175 ########################################