Mercurial > hg > autobot
annotate autobot/template.py @ 37:b41f50162908
add a debug variable
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sat, 08 Jan 2011 11:06:57 -0800 |
parents | fdddf883c19d |
children | 42ef457708de |
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 |
1 | 14 |
17
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
15 try: |
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
16 from subprocess import check_call as call |
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
17 except ImportError: |
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
18 from subprocess import call |
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
19 |
1 | 20 class AutobotMasterTemplate(MakeItSoTemplate): |
21 name = 'autobot-master' | |
4
eb289a46f4d3
make buildbot master template look close to what it should
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
22 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
|
23 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
|
24 vars = [Variable('slave', 'buildslave name', 'slave'), |
5
b7c521f53bda
document what the passwd variable is for
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
25 Variable('passwd', 'buildslave password', default='passwd'), |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
26 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
|
27 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
|
28 |
9
c06441767a2a
now interpolates correctly; just doesnt do much
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
29 def pre(self, variables): |
16
9ad3a9e220bc
get factory from command line
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
30 factory = variables.get('factory') |
13 | 31 if factory: |
32 assert factory in factories, 'Factory must be one of: ' % ', '.join(factories.keys()) | |
33 elif self.interactive: | |
16
9ad3a9e220bc
get factory from command line
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
34 print 'Factories:\n' |
13 | 35 for key in sorted(factories.keys()): |
36 print '%s:' % key | |
37 print getattr(factories[key], '__doc__', '').strip() | |
38 print | |
16
9ad3a9e220bc
get factory from command line
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
39 sys.stdout.write('Enter factory: ') |
13 | 40 factory = raw_input() |
41 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
|
42 variables['factory'] = factory |
13 | 43 else: |
44 raise AssertionError("No factory provided") | |
1 | 45 |
25
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
46 def create(self, output, variables): |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
47 command = ['buildbot', 'create-master', output] |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
48 print ' '.join(command) |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
49 call(command) |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
50 |
18
016ffd7bfd99
can now actually make a (admittedly non-working) buildmaster
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
51 def post(self, variables): |
17
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
52 """ |
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
53 called after the template is applied |
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
54 """ |
26
fdddf883c19d
first successful run of create-autobot script
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
55 self.create(self.output, variables) |
17
baee795ad6df
stub out actually calling buildbot
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
56 |
1 | 57 class AutobotSlaveTemplate(MakeItSoTemplate): |
58 name = 'autobot-slave' | |
4
eb289a46f4d3
make buildbot master template look close to what it should
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
59 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
|
60 templates = [os.path.join('template', 'slave')] |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
61 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
|
62 Variable('slave', 'buildslave name', 'slave'), |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
63 Variable('passwd', 'buildslave password', default='passwd'), |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
64 Variable('slaveport', 'port to talk to slaves on', default=9010)] |
1 | 65 |
25
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
66 def create(self, output, variables): |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
67 command = ['buildslave', 'create-slave', output, |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
68 '%s:%d' % (variables['master'], variables['slaveport']), |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
69 variables['slave'], |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
70 variables['passwd'] ] |
21 | 71 print ' '.join(command) |
72 call(command) | |
25
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
73 |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
74 |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
75 def post(self, variables): |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
76 self.create(self.output, variables) |
785b075be979
post method should work now [untested]
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
77 |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
78 |
23
a32a7055f3e6
combine variables for buildbot master+slave
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
79 class AutobotTemplate(AutobotMasterTemplate, AutobotSlaveTemplate): |
22
a7e2f5b2a7e9
stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
80 name = 'autobot' |
a7e2f5b2a7e9
stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
81 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
|
82 templates = ['template'] |
23
a32a7055f3e6
combine variables for buildbot master+slave
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
83 vars = assemble(AutobotMasterTemplate, AutobotSlaveTemplate) |
37 | 84 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
|
85 |
24 | 86 def post(self, variables): |
26
fdddf883c19d
first successful run of create-autobot script
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
87 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
|
88 AutobotSlaveTemplate.create(self, os.path.join(self.output, 'slave'), variables) |
24 | 89 |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
90 # CLI front end functions |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
91 # (console_script entry points) |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
92 |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
93 def create_master(args=sys.argv[1:]): |
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
|
94 cli = MakeItSoCLI(AutobotMasterTemplate) |
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
|
95 template = cli.parse() |
8 | 96 template.substitute() |
1 | 97 |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
98 def create_slave(args=sys.argv[1:]): |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
99 cli = MakeItSoCLI(AutobotSlaveTemplate) |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
100 template = cli.parse() |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
101 template.substitute() |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
102 |
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
103 def create_autobot(args=sys.argv[1:]): |
23
a32a7055f3e6
combine variables for buildbot master+slave
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
104 cli = MakeItSoCLI(AutobotTemplate) |
22
a7e2f5b2a7e9
stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
105 template = cli.parse() |
a7e2f5b2a7e9
stub out a combined template for the master + slave
Jeff Hammel <jhammel@mozilla.com>
parents:
21
diff
changeset
|
106 template.substitute() |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
107 |
1 | 108 if __name__ == '__main__': |
20
30ec24255ce9
stub out having a slave template too
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
109 create_master() |