Mercurial > hg > autobot
view autobot/process/factory.py @ 74:d94fbaac7c2c
stub out being able to find scripts cross-platform in a virtualenv
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 11 Jan 2011 15:04:31 -0800 |
parents | a2fc7a08ec5c |
children | a7ee8eacf605 |
line wrap: on
line source
from autobot.steps import find from autobot.steps import CreateVirtualenv from buildbot.process.factory import BuildFactory from buildbot.steps.shell import SetProperty from buildbot.steps.shell import ShellCommand from buildbot.steps.shell import WithProperties """ generic factories """ def find(*args): """ returns a command to echo the found file cross-platform """ args = ['[ -e "%s" ]; then echo "%s"' % (arg, arg) for arg in args] command = 'if %s; else false; fi' % '; elif '.join(args) return ['bash', '-c', command] class VirtualenvFactory(BuildFactory): """ create a virtualenv """ def __init__(self, name='env', hg_sources=(), git_sources=()): """ - name : of the virtualenv - hg_sources : sources of python packages with setuptools setup.pys """ BuildFactory.__init__(self) self.addStep(CreateVirtualenv(name)) self.addStep(ShellCommand(command=['mkdir', '-p', 'src'], workdir=name)) # TODO: set properities: # - virtualenv location # - scripts location # - python location self.addStep(SetProperty(property='virtualenv', command=['pwd'], workdir='build/'+name)) self.addStep(SetProperty(property='scripts', command=find('Scripts', 'bin'), workdir=WithProperties('%(virtualenv)s'))) self.addStep(SetProperty(property='python', workdir=WithProperties('%(virtualenv)s/%(scripts)s'), command=find('python', 'python.exe'))) # clone hg repositories for hg_source in hg_sources: self.addStep(ShellCommand(command=['hg', 'clone', hg_source], workdir=WithProperties('%(virtualenv)s/src'), haltOnFailure=True)) # clone the git repositories for git_source in git_sources: self.addStep(ShellCommand(command=['git', 'clone', git_source], workdir=WithProperties('%(virtualenv)s/src'), haltOnFailure=True)) def findScript(self, script): """ find the name of the script cross-platform - script: unix-style name of the script """ self.addStep(SetProperty(property=script, command=find(script, script + '.exe'), workdir=WithProperties('%(virtualenv)s/%(script)s'))) class PythonSourceFactory(VirtualenvFactory): """ setup several python packages """ def __init__(self, name='env', hg_sources=(), git_sources=()): # setup the environment VirtualenvFactory.__init__(self, name=name, hg_sources=hg_sources, git_sources=git_sources) # install the packages sources = [] for hg_source in hg_sources: package = hg_source.rstrip('/').rsplit('/', 1)[-1] sources.append(package) for git_source in git_sources: package = hg_source.rstrip('/').rsplit('/', 1)[-1] if package.endswith('.git'): package = package[:-4] sources.append(package) for package in sources: self.addStep(ShellCommand(command=[WithProperties('%(python)s'), 'setup.py', 'install'], workdir=WithProperties('%(virtualenv)s/src/' + package), haltOnFailure=True))