Mercurial > hg > autobot
annotate autobot/template.py @ 44:481f0bb18787
stub out installing the packages, for hg anyway
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 10 Jan 2011 11:33:19 -0800 |
parents | 19d555001292 |
children | ddcc1f5491aa |
rev | line source |
---|---|
1 | 1 #!/usr/bin/env python |
2 | |
3 """ | |
3 | 4 templates for the A*Team's buildbot |
1 | 5 """ |
6 | |
12
848569b7f91a
use subdirectories for the master and slave
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
7 import os |
1 | 8 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
|
9 from makeitso.cli import MakeItSoCLI |
23
a32a7055f3e6
combine variables for buildbot master+slave
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
10 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
|
11 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
|
12 from makeitso.template import Variable |
16
9ad3a9e220bc
get factory from command line
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
13 from projects import factories |
41
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
14 from StringIO import StringIO |
1 | 15 |
17
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
16 try: |
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
17 from subprocess import check_call as call |
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
18 except ImportError: |
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
19 from subprocess import call |
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
20 |
42
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
21 def factory_descriptions(): |
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
22 """print factory descriptions""" |
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
23 |
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
24 buffer = StringIO() |
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
25 print >> buffer, 'Factories:\n' |
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
26 for key in sorted(factories.keys()): |
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
27 print >> buffer, '%s:' % key |
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
28 print >> buffer, getattr(factories[key], '__doc__', '').strip() |
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
29 print >> buffer |
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
30 return buffer.getvalue() |
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
31 |
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
32 |
1 | 33 class AutobotMasterTemplate(MakeItSoTemplate): |
34 name = 'autobot-master' | |
4
eb289a46f4d3
make buildbot master template look close to what it should
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
35 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
|
36 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
|
37 vars = [Variable('slave', 'buildslave name', 'slave'), |
5
b7c521f53bda
document what the passwd variable is for
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
38 Variable('passwd', 'buildslave password', default='passwd'), |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
39 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
|
40 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
|
41 |
9
c06441767a2a
now interpolates correctly; just doesnt do much
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
42 def pre(self, variables): |
16
9ad3a9e220bc
get factory from command line
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
43 factory = variables.get('factory') |
13 | 44 if factory: |
45 assert factory in factories, 'Factory must be one of: ' % ', '.join(factories.keys()) | |
46 elif self.interactive: | |
42
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
47 print factory_descriptions() |
16
9ad3a9e220bc
get factory from command line
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
48 sys.stdout.write('Enter factory: ') |
13 | 49 factory = raw_input() |
50 assert factory in factories, 'Factory must be one of: ' % ', '.join(factories.keys()) | |
16
9ad3a9e220bc
get factory from command line
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
51 variables['factory'] = factory |
13 | 52 else: |
53 raise AssertionError("No factory provided") | |
1 | 54 |
25
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
55 def create(self, output, variables): |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
56 command = ['buildbot', 'create-master', output] |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
57 print ' '.join(command) |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
58 call(command) |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
59 |
18
016ffd7bfd99
can now actually make a (admittedly non-working) buildmaster
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
60 def post(self, variables): |
17
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
61 """ |
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
62 called after the template is applied |
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
63 """ |
26
fdddf883c19d
first successful run of create-autobot script
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
64 self.create(self.output, variables) |
17
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
65 |
1 | 66 class AutobotSlaveTemplate(MakeItSoTemplate): |
67 name = 'autobot-slave' | |
4
eb289a46f4d3
make buildbot master template look close to what it should
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
68 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
|
69 templates = [os.path.join('template', 'slave')] |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
70 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
|
71 Variable('slave', 'buildslave name', 'slave'), |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
72 Variable('passwd', 'buildslave password', default='passwd'), |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
73 Variable('slaveport', 'port to talk to slaves on', default=9010)] |
1 | 74 |
25
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
75 def create(self, output, variables): |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
76 command = ['buildslave', 'create-slave', output, |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
77 '%s:%d' % (variables['master'], variables['slaveport']), |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
78 variables['slave'], |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
79 variables['passwd'] ] |
21 | 80 print ' '.join(command) |
81 call(command) | |
25
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
82 |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
83 |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
84 def post(self, variables): |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
85 self.create(self.output, variables) |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
86 |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
87 |
23
a32a7055f3e6
combine variables for buildbot master+slave
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
88 class AutobotTemplate(AutobotMasterTemplate, AutobotSlaveTemplate): |
22
a7e2f5b2a7e9
stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
89 name = 'autobot' |
a7e2f5b2a7e9
stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
90 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
|
91 templates = ['template'] |
23
a32a7055f3e6
combine variables for buildbot master+slave
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
92 vars = assemble(AutobotMasterTemplate, AutobotSlaveTemplate) |
37 | 93 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
|
94 |
24 | 95 def post(self, variables): |
26
fdddf883c19d
first successful run of create-autobot script
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
96 AutobotMasterTemplate.create(self, os.path.join(self.output, 'master'), variables) |
fdddf883c19d
first successful run of create-autobot script
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
97 AutobotSlaveTemplate.create(self, os.path.join(self.output, 'slave'), variables) |
24 | 98 |
44
481f0bb18787
stub out installing the packages, for hg anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
43
diff
changeset
|
99 # CLI front end class |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
100 |
41
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
101 class AutobotMasterCLI(MakeItSoCLI): |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
102 """ |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
103 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
|
104 """ |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
105 def parser(self): |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
106 parser = MakeItSoCLI.parser(self) |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
107 parser.add_option('-f', '--factory', dest='factory', |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
108 help="factory to use") |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
109 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
|
110 default=False, action='store_true', |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
111 help="list available factories") |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
112 return parser |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
113 |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
114 def parse(self, parser=None, options=None, args=None): |
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 # parse the command line |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
117 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
|
118 parser = self.parser() |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
119 options, args = parser.parse_args() |
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 # list the factories |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
122 if options._list_factories: |
42
6981dcad3b2c
--list-factories now works
Jeff Hammel <jhammel@mozilla.com>
parents:
41
diff
changeset
|
123 print factory_descriptions() |
41
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
124 parser.exit() |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
125 |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
126 # call the parent |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
127 MakeItSoCLI.parse(self, parser, options, args) |
42ef457708de
stub out adding factories to our specialty CLI class
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
128 |
44
481f0bb18787
stub out installing the packages, for hg anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
43
diff
changeset
|
129 |
481f0bb18787
stub out installing the packages, for hg anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
43
diff
changeset
|
130 ### console_script front-ends |
481f0bb18787
stub out installing the packages, for hg anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
43
diff
changeset
|
131 |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
132 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
|
133 cli = AutobotMasterCLI(AutobotMasterTemplate) |
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
|
134 template = cli.parse() |
8 | 135 template.substitute() |
1 | 136 |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
137 def create_slave(args=sys.argv[1:]): |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
138 cli = MakeItSoCLI(AutobotSlaveTemplate) |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
139 template = cli.parse() |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
140 template.substitute() |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
141 |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
142 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
|
143 cli = AutobotMasterCLI(AutobotTemplate) |
22
a7e2f5b2a7e9
stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
144 template = cli.parse() |
a7e2f5b2a7e9
stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
145 template.substitute() |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
146 |
1 | 147 if __name__ == '__main__': |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
148 create_master() |