view autobot/config.py @ 151:700693fad00a

cleanup a few things found in testing multiple builders
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 25 Jan 2011 08:23:33 -0800
parents 95b8fec83ad7
children cb9ad0b04140
line wrap: on
line source

"""
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, default in ('slaveport', 9010), ('htmlport', 8010):
            self.master[port] = int(self.master.get(port) or default)

        # get section information
        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 = []
                if _factories == ['*']:
                    _factories = factories.keys()
                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])

if __name__ == '__main__':
    main()