view autobot/template.py @ 23:a32a7055f3e6

combine variables for buildbot master+slave
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 07 Jan 2011 18:19:04 -0800
parents a7e2f5b2a7e9
children fe1bb4c667bc
line wrap: on
line source

#!/usr/bin/env python

"""
templates for the A*Team's buildbot
"""

import os
import sys
from makeitso.cli import MakeItSoCLI
from makeitso.template import assemble
from makeitso.template import MakeItSoTemplate
from makeitso.template import Variable
from projects import factories

try:
    from subprocess import check_call as call
except ImportError:
    from subprocess import call

class AutobotMasterTemplate(MakeItSoTemplate):
    name = 'autobot-master'
    description = 'template for the autotools buildbot master'
    templates = [os.path.join('template', 'master')]
    vars = [Variable('slave', 'buildslave name', 'slave'),
            Variable('passwd', 'buildslave password', default='passwd'),
            Variable('slaveport', 'port to talk to slaves on', default=9010, cast=int),
            Variable('htmlport', 'port for waterfall display', default=8010, cast=int)]

    def pre(self, variables):
        factory = variables.get('factory')
        if factory:
            assert factory in factories, 'Factory must be one of: ' % ', '.join(factories.keys())
        elif self.interactive:
            print 'Factories:\n'
            for key in sorted(factories.keys()):
                print '%s:' % key
                print getattr(factories[key], '__doc__', '').strip()
                print
            sys.stdout.write('Enter factory: ')
            factory = raw_input()
            assert factory in factories, 'Factory must be one of: ' % ', '.join(factories.keys())
            variables['factory'] = factory
        else:
            raise AssertionError("No factory provided")

    def post(self, variables):
        """
        called after the template is applied
        """
        command = ['buildbot', 'create-master', self.output]
        print ' '.join(command)
        call(command)

class AutobotSlaveTemplate(MakeItSoTemplate):
    name = 'autobot-slave'
    description = 'template for the autotools buildbot slave'
    templates = [os.path.join('template', 'slave')]
    vars = [Variable('master', 'host of the master', default='localhost'),
            Variable('slave', 'buildslave name', 'slave'),
            Variable('passwd', 'buildslave password', default='passwd'),
            Variable('slaveport', 'port to talk to slaves on', default=9010)]

    def post(self, variables):
        command = ['buildslave', 'create-slave', self.output,
                   'localhost:%d' % variables['slaveport'],
                   variables['slave'],
                   variables['passwd'] ]
        print ' '.join(command)
        call(command)

class AutobotTemplate(AutobotMasterTemplate, AutobotSlaveTemplate):
    name = 'autobot'
    description = 'template for the autotools buildbot master+slave'
    templates = ['template']
    vars = assemble(AutobotMasterTemplate, AutobotSlaveTemplate)

# CLI front end functions
# (console_script entry points)

def create_master(args=sys.argv[1:]):
    cli = MakeItSoCLI(AutobotMasterTemplate)
    template = cli.parse()
    template.substitute()

def create_slave(args=sys.argv[1:]):
    cli = MakeItSoCLI(AutobotSlaveTemplate)
    template = cli.parse()
    template.substitute()

def create_autobot(args=sys.argv[1:]):
    cli = MakeItSoCLI(AutobotTemplate)
    template = cli.parse()
    template.substitute()

if __name__ == '__main__':
    create_master()