diff options
-rw-r--r-- | docs/metagen.1 | 8 | ||||
-rwxr-xr-x | metagen/main.py | 28 | ||||
-rwxr-xr-x | metagen/metagenerator.py | 10 | ||||
-rwxr-xr-x | metagen/test_cli | 22 |
4 files changed, 56 insertions, 12 deletions
diff --git a/docs/metagen.1 b/docs/metagen.1 index db9f76b..6364ece 100644 --- a/docs/metagen.1 +++ b/docs/metagen.1 @@ -42,6 +42,14 @@ maintainer-name -m Uses ECHANGELOG_USER variable. Can be used instead of -e and -n +.B --type +| +.B +-t +type + Maintainer type as of GLEP 67; valid types are: "person", "project", "unknown" + (required with --email|-e and --echangelog|-m options) + .B --desc | .B diff --git a/metagen/main.py b/metagen/main.py index 671bd02..1e30a20 100755 --- a/metagen/main.py +++ b/metagen/main.py @@ -34,6 +34,12 @@ from metagen import metagenerator PORTDIR = config(local_config=False)["PORTDIR"] HB = herdbase.make_herd_base(os.path.sep.join([PORTDIR, 'metadata', 'herds.xml'])) +# GLEP 67 +_MAINTAINER_TYPE_PERSON = 'person' +_MAINTAINER_TYPE_PROJECT = 'project' +_MAINTAINER_TYPE_UNKNOWN = 'unknown' +_VALID_MAINTAINER_TYPES = (_MAINTAINER_TYPE_PERSON, _MAINTAINER_TYPE_PROJECT, _MAINTAINER_TYPE_UNKNOWN) + def parse_echangelog_variable(name, email): """Extract developer name and email from ECHANGELOG_USER variable""" try: @@ -88,9 +94,11 @@ def generate_xml(options): names = options.name.split(",") if options.desc: descs = options.desc.split(",") + maintainer_types = options.maintainer_type.split(",") metadata.set_maintainer(options.email.split(","), names, - descs + descs, + maintainer_types, ) if options.long: @@ -109,6 +117,15 @@ def validate_xml(my_xml): return getstatusoutput(cmd)[0] +def _check_maintainer_type_list(text): + for candidate in text.split(','): + if candidate not in _VALID_MAINTAINER_TYPES: + raise ValueError('"%s" not a valid maintainer type' % candidate) + return text + +_check_maintainer_type_list.__name__ = 'maintainer type' + + if __name__ == '__main__': parser = ArgumentParser(prog='metagen') parser.add_argument('--version', action='version', version='%(prog)s ' + __version__) @@ -128,6 +145,9 @@ if __name__ == '__main__': "This is a shortcut for -e <email> -n <name>") maintainer.add_argument("--desc", "-d", action="store", help="Description of maintainership") + maintainer.add_argument("--type", "-t", dest='maintainer_type', type=_check_maintainer_type_list, + help="Maintainer type as of GLEP 67; valid values are: %s" \ + % ', '.join('"%s"' % e for e in _VALID_MAINTAINER_TYPES)) package = parser.add_argument_group(title='package arguments', description=None) package.add_argument("--long", "-l", action="store", @@ -159,6 +179,12 @@ if __name__ == '__main__': "or maintainer's email address (-e)\n") sys.exit(1) + if (options.email or options.echangelog) and not options.maintainer_type: + print red("!!! No maintainer type specified. Please pass one of the following, in addition:") + for candidate in _VALID_MAINTAINER_TYPES: + print red("!!! --type %s" % candidate) + sys.exit(1) + txt = generate_xml(options) error_status = validate_xml(txt) diff --git a/metagen/metagenerator.py b/metagen/metagenerator.py index 8b69ca0..9c513fa 100755 --- a/metagen/metagenerator.py +++ b/metagen/metagenerator.py @@ -22,12 +22,18 @@ class MyMetadata(jaxml.XML_document): for my_herd in opt_herds: self.herd(my_herd) - def set_maintainer(self, emails, names, descs): + def set_maintainer(self, emails, names, descs, types): """Set maintainer(s)'s email, name, desc""" + if len(types) != len(emails): + if len(types) != 1: + print red("!!! Nbr maintainer types != nbr emails") + sys.exit(1) + types = [types[0] for _ in emails] + i = 0 for e in emails: self._push("maintainer_level") - self.maintainer().email(e) + self.maintainer(type=types[i]).email(e) if names: if len(names) > len(emails): print red("!!! Nbr names > nbr emails") diff --git a/metagen/test_cli b/metagen/test_cli index 79fa443..d8b0f42 100755 --- a/metagen/test_cli +++ b/metagen/test_cli @@ -18,26 +18,30 @@ set -x ######################################## -#Should fail if ECHANGELOG_USER not set: -ECHANGELOG_USER='First Last <mail@example.org>' metagen -m -Q +#Should fail as -t ... is missing ! metagen -m -Q +! metagen -e mail@example.org -Q + +#Should fail if ECHANGELOG_USER not set: +ECHANGELOG_USER='First Last <mail@example.org>' metagen -m -Q -t person +! metagen -m -Q -t person -metagen -e "someguy@gentoo.org" -d "Maint desc" -Q +metagen -e "someguy@gentoo.org" -d "Maint desc" -Q -t person -metagen -e "someguy@gentoo.org" -n "Jon Doe" -d "Maint desc" -Q +metagen -e "someguy@gentoo.org" -n "Jon Doe" -d "Maint desc" -Q -t person #Should fail if ECHANGELOG_USER not set: -ECHANGELOG_USER='First Last <mail@example.org>' metagen -m -H python -e "foo@bar.com" -d "Foo bar.","Chow fun" -Q -! metagen -m -H python -e "foo@bar.com" -d "Foo bar.","Chow fun" -Q +ECHANGELOG_USER='First Last <mail@example.org>' metagen -m -H python -e "foo@bar.com" -d "Foo bar.","Chow fun" -Q -t person +! metagen -m -H python -e "foo@bar.com" -d "Foo bar.","Chow fun" -Q -t person #Should fail: -! metagen -Q +! metagen -Q -t person #Should fail: -! metagen -l "Long desc" -Q +! metagen -l "Long desc" -Q -t person #Should fail: -! metagen -d "Maintainer desc" -Q +! metagen -d "Maintainer desc" -Q -t person ######################################## |