# HG changeset patch # User Jeff Hammel # Date 1294687330 28800 # Node ID 42ef457708de13543667fdf442386562c12e6df7 # Parent e6c7a4cf2b40f2326163fa09f156e93b586a2f19 stub out adding factories to our specialty CLI class diff -r e6c7a4cf2b40 -r 42ef457708de autobot/process/factory.py --- a/autobot/process/factory.py Mon Jan 10 10:57:44 2011 -0800 +++ b/autobot/process/factory.py Mon Jan 10 11:22:10 2011 -0800 @@ -41,7 +41,7 @@ workdir=name)) self.addStep(SetProperty(property='python', workdir=WithProperties('%(virtualenv)s/%(scripts)s'), - command=find('python', 'python.exe')) + command=find('python', 'python.exe'))) # clone hg repositories for hg_source in hg_sources: diff -r e6c7a4cf2b40 -r 42ef457708de autobot/template.py --- a/autobot/template.py Mon Jan 10 10:57:44 2011 -0800 +++ b/autobot/template.py Mon Jan 10 11:22:10 2011 -0800 @@ -11,6 +11,7 @@ from makeitso.template import MakeItSoTemplate from makeitso.template import Variable from projects import factories +from StringIO import StringIO try: from subprocess import check_call as call @@ -26,16 +27,21 @@ Variable('slaveport', 'port to talk to slaves on', default=9010, cast=int), Variable('htmlport', 'port for waterfall display', default=8010, cast=int)] + def factory_descriptions(self): + buffer = StringIO() + print >> buffer, 'Factories:\n' + for key in sorted(factories.keys()): + print >> buffer, '%s:' % key + print >> buffer, getattr(factories[key], '__doc__', '').strip() + print >> buffer + return buffer.getvalue() + def pre(self, variables): factory = variables.get('factory') if factory: assert factory in factories, 'Factory must be one of: ' % ', '.join(factories.keys()) elif self.interactive: - print 'Factories:\n' - for key in sorted(factories.keys()): - print '%s:' % key - print getattr(factories[key], '__doc__', '').strip() - print + print self.factory_descriptions() sys.stdout.write('Enter factory: ') factory = raw_input() assert factory in factories, 'Factory must be one of: ' % ', '.join(factories.keys()) @@ -90,8 +96,36 @@ # CLI front end functions # (console_script entry points) +class AutobotMasterCLI(MakeItSoCLI): + """ + command line handler for the master + """ + def parser(self): + parser = MakeItSoCLI.parser(self) + parser.add_option('-f', '--factory', dest='factory', + help="factory to use") + parser.add_option('--list-factories', dest='_list_factories', + default=False, action='store_true', + help="list available factories") + return parser + + def parse(self, parser=None, options=None, args=None): + + # parse the command line + if not parser or not options or not args: + parser = self.parser() + options, args = parser.parse_args() + + # list the factories + if options._list_factories: + print self.template.factory_descriptions() + parser.exit() + + # call the parent + MakeItSoCLI.parse(self, parser, options, args) + def create_master(args=sys.argv[1:]): - cli = MakeItSoCLI(AutobotMasterTemplate) + cli = AutobotMasterCLI(AutobotMasterTemplate) template = cli.parse() template.substitute()