annotate autobot/config.py @ 128:95b8fec83ad7

remove pdb
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 23 Jan 2011 10:49:36 -0800
parents 2a55644b9948
children 700693fad00a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
84
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 """
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 tools for interpolating buildbot config
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 import sys
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 from projects import factories
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 from ConfigParser import RawConfigParser
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 class BuildbotIniConfig(object):
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 """
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 class for getting a (for now, autobot-specific)
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 buildbot configuration from an .ini file
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 """
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 def __init__(self, filename):
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 self.parser = RawConfigParser()
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 self.parser.read(filename)
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 # get global information
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 master = ':master:'
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 self.master = self.section_dict(master)
88
2a55644b9948 forgot a :
Jeff Hammel <jhammel@mozilla.com>
parents: 85
diff changeset
22 for port, default in ('slaveport', 9010), ('htmlport', 8010):
85
65c91bf35a36 deal with port defaults
Jeff Hammel <jhammel@mozilla.com>
parents: 84
diff changeset
23 self.master[port] = int(self.master.get(port) or default)
65c91bf35a36 deal with port defaults
Jeff Hammel <jhammel@mozilla.com>
parents: 84
diff changeset
24
65c91bf35a36 deal with port defaults
Jeff Hammel <jhammel@mozilla.com>
parents: 84
diff changeset
25 # get section information
84
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 self.slaves = {}
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 self.args = {}
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 for section in self.parser.sections():
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 # ignore master section -- we've already dealt with that
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 if section == master:
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 continue
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 # get slave
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 if section.startswith('slave:'):
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 name = section.split('slave:', 1)[-1]
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37 slave_dict = self.master.copy()
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38 slave_dict.update(self.section_dict(section))
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 assert 'password' in slave_dict, 'Slave %s: must provide a password'
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40 factories = slave_dict.get('factories', '')
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
41 factories = factories.split()
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
42 if factories == ['']:
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43 factories = []
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 self.slaves[name] = {'password': slave_dict['password'],
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 'factories': factories }
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 continue
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
48 # get factories
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
49 self.args[section] = self.section_dict(section)
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
50
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51 # TODO: schedulers + sources ([source:<factory>])
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
52
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
53 def section_dict(self, section):
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
54 """
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
55 returns the section as a dict
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
56 """
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
57 if section in self.parser.sections():
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
58 return dict(self.parser.items(section))
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
59 else:
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
60 return {}
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
61
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
62 def main(args=sys.argv[1:]):
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
63 """parse the configuration, mostly for testing purposes"""
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
64 if len(args) != 1:
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
65 print 'Please provide an .ini file to try to parse'
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
66 sys.exit(1)
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
67 config = BuildbotIniConfig(args[0])
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
68
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
69 if __name__ == '__main__':
86e65422f31a have some sort of working configuration parser....lets roll with it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
70 main()