annotate autobot/template.py @ 73:d033843da35a

templates work again maybe
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 11 Jan 2011 14:23:39 -0800
parents 849bbc2e5572
children d94fbaac7c2c
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
25
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
57 def create(self, output, variables):
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
58 command = ['buildbot', 'create-master', output]
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
59 print ' '.join(command)
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
60 call(command)
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
61
18
016ffd7bfd99 can now actually make a (admittedly non-working) buildmaster
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
62 def post(self, variables):
17
baee795ad6df stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
63 """
baee795ad6df stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
64 called after the template is applied
baee795ad6df stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
65 """
26
fdddf883c19d first successful run of create-autobot script
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
66 self.create(self.output, variables)
17
baee795ad6df stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
67
66
cbcb96142ed6 stubs towards specifying multiple factories
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
68
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
69 class AutobotSlaveTemplate(MakeItSoTemplate):
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
70 name = 'autobot-slave'
4
eb289a46f4d3 make buildbot master template look close to what it should
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
71 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
72 templates = [os.path.join('template', 'slave')]
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
73 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
74 Variable('slave', 'buildslave name', 'slave'),
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
75 Variable('passwd', 'buildslave password', default='passwd'),
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
76 Variable('slaveport', 'port to talk to slaves on', default=9010)]
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
77
25
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
78 def create(self, output, variables):
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
79 command = ['buildslave', 'create-slave', output,
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
80 '%s:%d' % (variables['master'], variables['slaveport']),
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
81 variables['slave'],
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
82 variables['passwd'] ]
21
6c3c6488e4a9 can has a slave now
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
83 print ' '.join(command)
6c3c6488e4a9 can has a slave now
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
84 call(command)
25
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
85
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
86
73
d033843da35a templates work again maybe
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
87 def post(self, variables, output):
d033843da35a templates work again maybe
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
88 self.create(output, variables)
25
785b075be979 post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
89
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
90
23
a32a7055f3e6 combine variables for buildbot master+slave
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
91 class AutobotTemplate(AutobotMasterTemplate, AutobotSlaveTemplate):
22
a7e2f5b2a7e9 stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
92 name = 'autobot'
a7e2f5b2a7e9 stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
93 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
94 templates = ['template']
23
a32a7055f3e6 combine variables for buildbot master+slave
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
95 vars = assemble(AutobotMasterTemplate, AutobotSlaveTemplate)
37
b41f50162908 add a debug variable
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
96 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
97
73
d033843da35a templates work again maybe
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
98 def post(self, variables, output):
d033843da35a templates work again maybe
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
99 AutobotMasterTemplate.create(self, os.path.join(output, 'master'), variables)
d033843da35a templates work again maybe
Jeff Hammel <jhammel@mozilla.com>
parents: 69
diff changeset
100 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
101
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
102
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
103 class ProjectTemplate(MakeItSoTemplate):
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 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
106 """
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
107 name = 'autobot-project'
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
108 templates = [os.path.join('projects', 'project.template')]
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
109 vars = [Variable('description'),
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
110 Variable('repo', 'repository location of the project')]
24
fe1bb4c667bc stub post method
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
111
44
481f0bb18787 stub out installing the packages, for hg anyway
Jeff Hammel <jhammel@mozilla.com>
parents: 43
diff changeset
112 # CLI front end class
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
113
41
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
114 class AutobotMasterCLI(MakeItSoCLI):
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
115 """
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
116 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
117 """
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
118 def parser(self):
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
119 parser = MakeItSoCLI.parser(self)
66
cbcb96142ed6 stubs towards specifying multiple factories
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
120 parser.add_option('-f', '--factory', dest='factories',
cbcb96142ed6 stubs towards specifying multiple factories
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
121 default=[], action='append',
41
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
122 help="factory to use")
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
123 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
124 default=False, action='store_true',
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
125 help="list available factories")
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
126 return parser
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
127
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
128 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
129
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
130 # parse the command line
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
131 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
132 parser = self.parser()
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
133 options, args = parser.parse_args()
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
134
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
135 # list the factories
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
136 if options._list_factories:
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
137 print print_descriptions()
41
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
138 parser.exit()
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
139
42ef457708de stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
140 # call the parent
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
141 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
142
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
143
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
144 class ProjectTemplateCLI(MakeItSoCLI):
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
145 """CLI front end for project template"""
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
146
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
147 def __init__(self):
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
148 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
149 MakeItSoCLI.__init__(self, ProjectTemplate)
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 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
152
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
153 # parse the arguments
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
154 parser = self.parser()
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
155 options, args = parser.parse_args(args=args)
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
156
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
157 if not(args):
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
158 parser.print_usage()
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
159 parser.exit()
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
160
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
161 # deploy to the correct place
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
162 if len(args) not in (1,2):
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
163 parser.error("Please provide a single project")
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
164 project = args[0].lower()
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
165
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
166 # ensure the argument is a python path
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
167 assert set(project).issubset(string.letters)
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
168
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
169 # get the variables
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
170 variables = self.get_variables(options)
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
171 variables['project'] = project
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 # 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
174 if len(args) == 2:
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
175 output = args[1]
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
176 else:
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
177 here = os.path.dirname(os.path.abspath(__file__))
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
178 projectdir = os.path.join(here, 'projects', project)
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
179 if os.path.exists(projectdir):
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
180 assert os.path.isdir(projectdir)
69
849bbc2e5572 first use of project template -> devicemanager
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
181 else:
849bbc2e5572 first use of project template -> devicemanager
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
182 os.makedirs(projectdir)
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
183 output = os.path.join(projectdir, '__init__.py')
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
184 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
185
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
186 return variables, output
44
481f0bb18787 stub out installing the packages, for hg anyway
Jeff Hammel <jhammel@mozilla.com>
parents: 43
diff changeset
187
481f0bb18787 stub out installing the packages, for hg anyway
Jeff Hammel <jhammel@mozilla.com>
parents: 43
diff changeset
188 ### console_script front-ends
481f0bb18787 stub out installing the packages, for hg anyway
Jeff Hammel <jhammel@mozilla.com>
parents: 43
diff changeset
189
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
190 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
191 cli = AutobotMasterCLI(AutobotMasterTemplate)
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
192 cli(*args)
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
193
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
194 def create_slave(args=sys.argv[1:]):
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
195 cli = MakeItSoCLI(AutobotSlaveTemplate)
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
196 cli(*args)
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
197
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
198 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
199 cli = AutobotMasterCLI(AutobotTemplate)
62
2a5fa6876e48 update template to conform to the new CLI
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
200 cli(*args)
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
201
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
202 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
203 cli = ProjectTemplateCLI()
68
fbd4a34d8e42 make project creation template work
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
204 cli(*args)
67
e8dabfd24c42 stub for a template to create new autobot factories; unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
205
1
3bd7f767d74a more stubbing of template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
206 if __name__ == '__main__':
20
30ec24255ce9 stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
207 create_master()