annotate autobot/template.py @ 132:da7af78edcb5

ensure the slaveport is an int
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 23 Jan 2011 17:02:05 -0800
parents d4452281f42a
children b10d16cdc22b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
3
1d615610e442 add a docstring
Jeff Hammel <jhammel@mozilla.com>
parents: 1
diff changeset
4 templates for the A*Team's buildbot
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 """
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
12
848569b7f91a use subdirectories for the master and slave
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
7 import os
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
8 import string
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 import sys
6
4ba6ba323871 stub out invocation of the template; this should eventually move to its own class, as we will want to subclass MakeItSoCLI, /me thinks
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
10 from makeitso.cli import MakeItSoCLI
23
a32a7055f3e6 combine variables for buildbot master+slave
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
11 from makeitso.template import assemble
4
eb289a46f4d3 make buildbot master template look close to what it should
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
12 from makeitso.template import MakeItSoTemplate
eb289a46f4d3 make buildbot master template look close to what it should
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
13 from makeitso.template import Variable
59
e66165f2f31b complete automagic imports
Jeff Hammel <jhammel@mozilla.com>
parents: 46
diff changeset
14 from projects import descriptions
16
9ad3a9e220bc get factory from command line
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
15 from projects import factories
41
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
16 from StringIO import StringIO
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17
17
baee795ad6df stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
18 try:
baee795ad6df stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
19 from subprocess import check_call as call
baee795ad6df stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
20 except ImportError:
baee795ad6df stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
21 from subprocess import call
baee795ad6df stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
22
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
23 def print_descriptions():
42
6981dcad3b2c --list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents: 41
diff changeset
24 """print factory descriptions"""
6981dcad3b2c --list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents: 41
diff changeset
25
6981dcad3b2c --list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents: 41
diff changeset
26 buffer = StringIO()
6981dcad3b2c --list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents: 41
diff changeset
27 print >> buffer, 'Factories:\n'
6981dcad3b2c --list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents: 41
diff changeset
28 for key in sorted(factories.keys()):
6981dcad3b2c --list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents: 41
diff changeset
29 print >> buffer, '%s:' % key
59
e66165f2f31b complete automagic imports
Jeff Hammel <jhammel@mozilla.com>
parents: 46
diff changeset
30 print >> buffer, descriptions[key]
42
6981dcad3b2c --list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents: 41
diff changeset
31 print >> buffer
6981dcad3b2c --list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents: 41
diff changeset
32 return buffer.getvalue()
6981dcad3b2c --list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents: 41
diff changeset
33
6981dcad3b2c --list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents: 41
diff changeset
34
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 class AutobotMasterTemplate(MakeItSoTemplate):
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 name = 'autobot-master'
4
eb289a46f4d3 make buildbot master template look close to what it should
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
37 description = 'template for the autotools buildbot master'
12
848569b7f91a use subdirectories for the master and slave
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
38 templates = [os.path.join('template', 'master')]
4
eb289a46f4d3 make buildbot master template look close to what it should
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
39 vars = [Variable('slave', 'buildslave name', 'slave'),
5
b7c521f53bda document what the passwd variable is for
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
40 Variable('passwd', 'buildslave password', default='passwd'),
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
41 Variable('slaveport', 'port to talk to slaves on', default=9010, cast=int),
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
42 Variable('htmlport', 'port for waterfall display', default=8010, cast=int)]
4
eb289a46f4d3 make buildbot master template look close to what it should
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
43
73
d033843da35a templates work again maybe
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
44 def pre(self, variables, output):
66
cbcb96142ed6 stubs towards specifying multiple factories
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
45 factory = variables.get('factories')
13
59cc21718ced select factory
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
46 if factory:
66
cbcb96142ed6 stubs towards specifying multiple factories
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
47 assert(set(factory).issubset(factories.keys())), 'Factory must be one of: ' % ', '.join(factories.keys())
13
59cc21718ced select factory
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
48 elif self.interactive:
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
49 print print_descriptions()
16
9ad3a9e220bc get factory from command line
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
50 sys.stdout.write('Enter factory: ')
13
59cc21718ced select factory
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
51 factory = raw_input()
59cc21718ced select factory
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
52 assert factory in factories, 'Factory must be one of: ' % ', '.join(factories.keys())
66
cbcb96142ed6 stubs towards specifying multiple factories
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
53 variables['factories'] = [factory]
13
59cc21718ced select factory
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
54 else:
59cc21718ced select factory
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
55 raise AssertionError("No factory provided")
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
56
87
d4452281f42a fix missing ]
Jeff Hammel <jhammel@mozilla.com>
parents: 86
diff changeset
57 # stringify for .ini file
d4452281f42a fix missing ]
Jeff Hammel <jhammel@mozilla.com>
parents: 86
diff changeset
58 variables['factories'] = ' '.join([i for i in variables['factories']])
86
2616a5f49bd3 switch to .ini files for configuration
Jeff Hammel <jhammel@mozilla.com>
parents: 74
diff changeset
59
25
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
60 def create(self, output, variables):
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
61 command = ['buildbot', 'create-master', output]
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
62 print ' '.join(command)
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
63 call(command)
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
64
18
016ffd7bfd99 can now actually make a (admittedly non-working) buildmaster
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
65 def post(self, variables):
17
baee795ad6df stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
66 """
baee795ad6df stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
67 called after the template is applied
baee795ad6df stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
68 """
26
fdddf883c19d first successful run of create-autobot script
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
69 self.create(self.output, variables)
17
baee795ad6df stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
70
66
cbcb96142ed6 stubs towards specifying multiple factories
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
71
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
72 class AutobotSlaveTemplate(MakeItSoTemplate):
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
73 name = 'autobot-slave'
4
eb289a46f4d3 make buildbot master template look close to what it should
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
74 description = 'template for the autotools buildbot slave'
12
848569b7f91a use subdirectories for the master and slave
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
75 templates = [os.path.join('template', 'slave')]
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
76 vars = [Variable('master', 'host of the master', default='localhost'),
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
77 Variable('slave', 'buildslave name', 'slave'),
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
78 Variable('passwd', 'buildslave password', default='passwd'),
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
79 Variable('slaveport', 'port to talk to slaves on', default=9010)]
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
80
25
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
81 def create(self, output, variables):
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
82 command = ['buildslave', 'create-slave', output,
132
da7af78edcb5 ensure the slaveport is an int
Jeff Hammel <jhammel@mozilla.com>
parents: 87
diff changeset
83 '%s:%d' % (variables['master'], int(variables['slaveport'])),
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
84 variables['slave'],
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
85 variables['passwd'] ]
21
6c3c6488e4a9 can has a slave now
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
86 print ' '.join(command)
6c3c6488e4a9 can has a slave now
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
87 call(command)
25
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
88
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
89
73
d033843da35a templates work again maybe
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
90 def post(self, variables, output):
d033843da35a templates work again maybe
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
91 self.create(output, variables)
25
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
92
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
93
23
a32a7055f3e6 combine variables for buildbot master+slave
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
94 class AutobotTemplate(AutobotMasterTemplate, AutobotSlaveTemplate):
22
a7e2f5b2a7e9 stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
95 name = 'autobot'
a7e2f5b2a7e9 stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
96 description = 'template for the autotools buildbot master+slave'
a7e2f5b2a7e9 stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
97 templates = ['template']
23
a32a7055f3e6 combine variables for buildbot master+slave
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
98 vars = assemble(AutobotMasterTemplate, AutobotSlaveTemplate)
37
b41f50162908 add a debug variable
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
99 vars.append(Variable('debug', default=True, cast='eval'))
22
a7e2f5b2a7e9 stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
100
73
d033843da35a templates work again maybe
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
101 def post(self, variables, output):
d033843da35a templates work again maybe
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
102 AutobotMasterTemplate.create(self, os.path.join(output, 'master'), variables)
d033843da35a templates work again maybe
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
103 AutobotSlaveTemplate.create(self, os.path.join(output, 'slave'), variables)
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
104
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
105
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
106 class ProjectTemplate(MakeItSoTemplate):
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
107 """
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
108 template for creating new autobot project stubs for testing
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
109 """
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
110 name = 'autobot-project'
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
111 templates = [os.path.join('projects', 'project.template')]
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
112 vars = [Variable('description'),
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
113 Variable('repo', 'repository location of the project')]
24
fe1bb4c667bc stub post method
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
114
44
481f0bb18787 stub out installing the packages, for hg anyway
Jeff Hammel <jhammel@mozilla.com>
parents: 43
diff changeset
115 # CLI front end class
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
116
41
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
117 class AutobotMasterCLI(MakeItSoCLI):
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
118 """
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
119 command line handler for the master
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
120 """
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
121 def parser(self):
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
122 parser = MakeItSoCLI.parser(self)
66
cbcb96142ed6 stubs towards specifying multiple factories
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
123 parser.add_option('-f', '--factory', dest='factories',
cbcb96142ed6 stubs towards specifying multiple factories
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
124 default=[], action='append',
74
d94fbaac7c2c stub out being able to find scripts cross-platform in a virtualenv
Jeff Hammel <jhammel@mozilla.com>
parents: 73
diff changeset
125 help="factory to use ('--factory -' for all)")
41
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
126 parser.add_option('--list-factories', dest='_list_factories',
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
127 default=False, action='store_true',
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
128 help="list available factories")
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
129 return parser
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
130
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
131 def parse(self, args=None, parser=None, options=None):
41
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
132
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
133 # parse the command line
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
134 if not parser or not options or not args:
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
135 parser = self.parser()
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
136 options, args = parser.parse_args()
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
137
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
138 # list the factories
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
139 if options._list_factories:
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
140 print print_descriptions()
41
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
141 parser.exit()
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
142
74
d94fbaac7c2c stub out being able to find scripts cross-platform in a virtualenv
Jeff Hammel <jhammel@mozilla.com>
parents: 73
diff changeset
143 # check for all factories
d94fbaac7c2c stub out being able to find scripts cross-platform in a virtualenv
Jeff Hammel <jhammel@mozilla.com>
parents: 73
diff changeset
144 if options.factories == ['-']:
d94fbaac7c2c stub out being able to find scripts cross-platform in a virtualenv
Jeff Hammel <jhammel@mozilla.com>
parents: 73
diff changeset
145 options.factories = factories.keys()
d94fbaac7c2c stub out being able to find scripts cross-platform in a virtualenv
Jeff Hammel <jhammel@mozilla.com>
parents: 73
diff changeset
146
41
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
147 # call the parent
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
148 return MakeItSoCLI.parse(self, args, parser, options)
41
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
149
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
150
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
151 class ProjectTemplateCLI(MakeItSoCLI):
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
152 """CLI front end for project template"""
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
153
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
154 def __init__(self):
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
155 self.usage = '%prog [options] project <output>'
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
156 MakeItSoCLI.__init__(self, ProjectTemplate)
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
157
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
158 def parse(self, args=None, parser=None, options=None):
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
159
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
160 # parse the arguments
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
161 parser = self.parser()
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
162 options, args = parser.parse_args(args=args)
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
163
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
164 if not(args):
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
165 parser.print_usage()
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
166 parser.exit()
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
167
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
168 # deploy to the correct place
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
169 if len(args) not in (1,2):
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
170 parser.error("Please provide a single project")
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
171 project = args[0].lower()
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
172
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
173 # ensure the argument is a python path
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
174 assert set(project).issubset(string.letters)
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
175
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
176 # get the variables
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
177 variables = self.get_variables(options)
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
178 variables['project'] = project
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
179
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
180 # get the output or use the location in the source
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
181 if len(args) == 2:
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
182 output = args[1]
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
183 else:
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
184 here = os.path.dirname(os.path.abspath(__file__))
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
185 projectdir = os.path.join(here, 'projects', project)
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
186 if os.path.exists(projectdir):
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
187 assert os.path.isdir(projectdir)
69
849bbc2e5572 first use of project template -> devicemanager
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
188 else:
849bbc2e5572 first use of project template -> devicemanager
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
189 os.makedirs(projectdir)
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
190 output = os.path.join(projectdir, '__init__.py')
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
191 assert not os.path.exists(output), "Project '%s' already exists" % project
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
192
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
193 return variables, output
44
481f0bb18787 stub out installing the packages, for hg anyway
Jeff Hammel <jhammel@mozilla.com>
parents: 43
diff changeset
194
481f0bb18787 stub out installing the packages, for hg anyway
Jeff Hammel <jhammel@mozilla.com>
parents: 43
diff changeset
195 ### console_script front-ends
481f0bb18787 stub out installing the packages, for hg anyway
Jeff Hammel <jhammel@mozilla.com>
parents: 43
diff changeset
196
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
197 def create_master(args=sys.argv[1:]):
41
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
198 cli = AutobotMasterCLI(AutobotMasterTemplate)
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
199 cli(*args)
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
200
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
201 def create_slave(args=sys.argv[1:]):
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
202 cli = MakeItSoCLI(AutobotSlaveTemplate)
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
203 cli(*args)
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
204
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
205 def create_autobot(args=sys.argv[1:]):
43
19d555001292 use our CLI class for the create-autobot too
Jeff Hammel <jhammel@mozilla.com>
parents: 42
diff changeset
206 cli = AutobotMasterCLI(AutobotTemplate)
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
207 cli(*args)
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
208
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
209 def create_project(args=sys.argv[1:]):
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
210 cli = ProjectTemplateCLI()
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
211 cli(*args)
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
212
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
213 if __name__ == '__main__':
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
214 create_master()