From 4b2a404aab29298865e71333970862509a1f37e6 Mon Sep 17 00:00:00 2001 From: Tony Breeds Date: Thu, 30 Aug 2018 09:21:30 +1000 Subject: [PATCH] Add a UI to template-emails Change-Id: I334aaa453aa905b35d518e522f89a70f527f10c3 --- openstack_election/cmds/template_emails.py | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/openstack_election/cmds/template_emails.py b/openstack_election/cmds/template_emails.py index 826760dc..7000dd99 100644 --- a/openstack_election/cmds/template_emails.py +++ b/openstack_election/cmds/template_emails.py @@ -1,6 +1,9 @@ from __future__ import print_function from __future__ import unicode_literals +import argparse +import sys + from openstack_election import config from openstack_election import utils @@ -421,5 +424,30 @@ Thank you, def main(): - # FIXME(tonyb): add a command line interface + parser = argparse.ArgumentParser('Tool to generate form emails') + # Use a sub parser so we can have diffent template choices based on the + # election_type + cmd_parsers = parser.add_subparsers(dest='election_type', + help=('Type of election. Choices ' + 'tc')) + # FIXME(tonyb): Do this after the TC election is over + # parser_ptl = cmd_parsers.add_parser('ptl') + # parser_ptl.add_argument('template', choices=[]) + parser_tc = cmd_parsers.add_parser('tc') + parser_tc.add_argument('template', + choices=['election_season', 'nominations_kickoff', + 'nominations_last_days', 'end_nominations', + 'voting_kickoff', 'voting_last_days']) + + args = parser.parse_args() + if not args.election_type: + parser.print_help(sys.stderr) + sys.exit(1) + + func_name = '%(election_type)s_%(template)s' % (args.__dict__) + if func_name in globals(): + func = globals()[func_name] + if callable(func): + func() + return 0