changeset 84:86e65422f31a

have some sort of working configuration parser....lets roll with it
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 12 Jan 2011 11:13:52 -0800
parents 42cdcb431462
children 65c91bf35a36
files autobot/config.py autobot/template/master/master.cfg
diffstat 2 files changed, 71 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autobot/config.py	Wed Jan 12 11:13:52 2011 -0800
@@ -0,0 +1,70 @@
+"""
+tools for interpolating buildbot config
+"""
+
+import sys
+from projects import factories
+from ConfigParser import RawConfigParser
+
+class BuildbotIniConfig(object):
+    """
+    class for getting a (for now, autobot-specific)
+    buildbot configuration from an .ini file
+    """
+
+    def __init__(self, filename):
+        self.parser = RawConfigParser()
+        self.parser.read(filename)
+        
+        # get global information
+        master = ':master:'
+        self.master = self.section_dict(master)
+        for port in 'slaveport', 'htmlport':
+            self.master[port] = int(self.master.get(port) or 9010)
+        
+        self.slaves = {}
+        self.args = {}
+        for section in self.parser.sections():
+
+            # ignore master section -- we've already dealt with that
+            if section == master:
+                continue
+
+            # get slave
+            if section.startswith('slave:'):
+                name = section.split('slave:', 1)[-1]
+                slave_dict = self.master.copy()
+                slave_dict.update(self.section_dict(section))
+                assert 'password' in slave_dict, 'Slave %s: must provide a password'
+                factories = slave_dict.get('factories', '')
+                factories = factories.split()
+                if factories == ['']:
+                    factories = []
+                self.slaves[name] = {'password': slave_dict['password'],
+                                     'factories': factories }
+                continue
+            
+            # get factories
+            self.args[section] = self.section_dict(section)
+
+        # TODO: schedulers + sources ([source:<factory>])
+
+    def section_dict(self, section):
+        """
+        returns the section as a dict
+        """
+        if section in self.parser.sections():
+            return dict(self.parser.items(section))
+        else:
+            return {}
+
+def main(args=sys.argv[1:]):
+    """parse the configuration, mostly for testing purposes"""
+    if len(args) != 1:
+        print 'Please provide an .ini file to try to parse'
+        sys.exit(1)
+    config = BuildbotIniConfig(args[0])
+    import pdb; pdb.set_trace()
+
+if __name__ == '__main__':
+    main()
--- a/autobot/template/master/master.cfg	Tue Jan 11 17:43:09 2011 -0800
+++ b/autobot/template/master/master.cfg	Wed Jan 12 11:13:52 2011 -0800
@@ -48,6 +48,6 @@
 c['status'].append(html.WebStatus(http_port={{htmlport}}, authz=authz))
 
 ####### PROJECT IDENTITY
-c['projectName'] = "Buildbot"
+c['projectName'] = "autobot"
 c['projectURL'] = "http://buildbot.sourceforge.net/"
 c['buildbotURL'] = "http://localhost:{{htmlport}}/"