view autobot/process/factory.py @ 50:a39959f8c0a5

now properties get set correctly and all that
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 10 Jan 2011 12:24:00 -0800
parents 5e14fe86bc52
children de3d2320df90
line wrap: on
line source

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
  """
  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=name+'/src',
                                haltOnFailure=True))

    # clone the git repositories
    for git_source in git_sources:
      self.addStep(ShellCommand(command=['git', 'clone', git_source],
                                workdir=name+'/src',
                                haltOnFailure=True))

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 
    for hg_source in hg_sources:
      package = hg_source.rstrip('/').rsplit('/', 1)[-1]
      self.addStep(ShellCommand(command=[WithProperties('%(python)s'), 'setup.py', 'install'],
                                workdir=WithProperties('%(virtualenv)s/src/' + package),
                                haltOnFailure=True))
    for git_source in git_sources:
      pass # [TODO]

# python sources:
# [{'source': 'http://hg.mozilla.org/....',
#   'type': 'hg', # or git,
#  }]