changeset 136:336702f58075

completely change how sources are stored....hopefully it will break things
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 24 Jan 2011 12:27:17 -0800
parents 7ab38166e65e
children 14430c384556
files autobot/process/factory.py autobot/projects/logparser/__init__.py autobot/template/master/master.cfg
diffstat 3 files changed, 71 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/autobot/process/factory.py	Mon Jan 24 10:33:34 2011 -0800
+++ b/autobot/process/factory.py	Mon Jan 24 12:27:17 2011 -0800
@@ -16,17 +16,71 @@
   command = 'if %s; else false; fi' % '; elif '.join(args)
   return ['bash', '-c', command]
 
-class VirtualenvFactory(BuildFactory):
+class SourceFactory(BuildFactory):
+  """
+  base class for factories with VCS sources
+  """
+
+  sources = {'git': [], 'hg': []}
+  default_branches = {'git': 'master', 'hg': 'default'}
+
+  def __init__(self, git=None, hg=None):
+
+    BuildFactory.__init__(self)
+
+    # override class-level defaults
+    if git is not None:
+      self.sources['git'] = git
+    if hg is not None:
+      self.sources['hg'] = hg
+
+    # sanitize sources
+    for source_type in self.sources:
+      if isinstance(self.sources[source_type], basestring):
+        self.sources[source_type] = self.sources[source_type].split()
+      for index, source in enumerate(self.sources[source_type]):
+        if isinstance(source, basestring):
+          branch = None
+          if '#' in source:
+            source, branch = source.rsplit('#', 1)
+          
+        else:
+          source, branch = source
+        if branch is None:
+          branch = self.default_branches.get(source_type, None)
+        self.sources[source_type][index] = (source, branch)
+
+  def checkout(self, **kwargs):
+    """
+    checkout all sources
+    """
+    # TODO: do the right thing with branches (they're currently ignored)
+    # TODO: should give more fine-grained control
+
+    # clone hg repositories
+    for hg_source in self.sources.get('hg', ()):
+      self.addStep(ShellCommand(command=['hg', 'clone', hg_source],
+                                **kwargs))
+
+    # clone the git repositories
+    for git_source in self.sources.get('git', ()):
+      self.addStep(ShellCommand(command=['git', 'clone', git_source],
+                                **kwargs)
+    
+
+               
+class VirtualenvFactory(SourceFactory):
   """
   create a virtualenv and install some python packages in it
   """
 
-  def __init__(self, name='env', hg_sources=(), git_sources=()):
+  def __init__(self, name='env', hg=None, git=None):
     """
     - name : of the virtualenv
-    - hg_sources : sources of python packages with setuptools setup.pys
+    - hg: sources of python packages with setuptools setup.pys
+    - git: git sources of python package
     """
-    BuildFactory.__init__(self)
+    SourceFactory.__init__(self, hg=hg, git=git)
 
     # wipe any vesitages
     self.addStep(ShellCommand(command=['rm', '-rf', name]))
@@ -50,17 +104,10 @@
     self.addStep(ShellCommand(command=['mkdir', '-p', 'src'],
                               workdir=WithProperties('%(virtualenv)s')))
 
-    # clone hg repositories
-    for hg_source in hg_sources:
-      self.addStep(ShellCommand(command=['hg', 'clone', hg_source],
-                                workdir=WithProperties('%(virtualenv)s/src'),
-                                haltOnFailure=True))
+    # checkout sources
+    self.checkout(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):
     """
@@ -78,18 +125,18 @@
   setup several python packages
   """
 
-  def __init__(self, name='env', hg_sources=(), git_sources=()):
+  def __init__(self, name='env', hg=None, git=None):
 
     # setup the environment
-    VirtualenvFactory.__init__(self, name=name, hg_sources=hg_sources, git_sources=git_sources)
+    VirtualenvFactory.__init__(self, name=name, hg=hg, git=git)
 
     # install the packages
     sources = []
-    for hg_source in hg_sources:
+    for hg_source in self.sources.get('hg', ()):
       package = hg_source.rstrip('/').rsplit('/', 1)[-1]
       sources.append(package)
-    for git_source in git_sources:
-      package = hg_source.rstrip('/').rsplit('/', 1)[-1]
+    for git_source in self.sources.get('git', ()):
+      package = git_source.rstrip('/').rsplit('/', 1)[-1]
       if package.endswith('.git'):
         package = package[:-4]
       sources.append(package)
@@ -98,4 +145,3 @@
                                 workdir=WithProperties('%(virtualenv)s/src/' + package),
                                 description='install ' + package,
                                 haltOnFailure=True))
-        
--- a/autobot/projects/logparser/__init__.py	Mon Jan 24 10:33:34 2011 -0800
+++ b/autobot/projects/logparser/__init__.py	Mon Jan 24 12:27:17 2011 -0800
@@ -7,11 +7,13 @@
   factory to test the Mozilla log parser:
   http://hg.mozilla.org/automation/logparser/
   """
+
+  sources = {'hg': 'http://hg.mozilla.org/automation/logparser/'}
+  
   def __init__(self):
 
     # setup the environment and install the python
-    PythonSourceFactory.__init__(self, name='logparser',
-                                 hg_sources=['http://hg.mozilla.org/automation/logparser/'])
+    PythonSourceFactory.__init__(self, name='logparser')
 
     # run the tests
     self.addStep(ShellCommand(command=[WithProperties('%(python)s'), 'test_logparser.py'],
--- a/autobot/template/master/master.cfg	Mon Jan 24 10:33:34 2011 -0800
+++ b/autobot/template/master/master.cfg	Mon Jan 24 12:27:17 2011 -0800
@@ -15,10 +15,10 @@
 
 ####### BUILDERS
 
+# change sources
 sources = {'git': set(),
            'hg':  set()}
            
-
 # define builder factories
 from autobot.projects import factories as factory_dict
 builders = []