# Path: journeyman/builds/models.py
# class Build(models.Model):
#     project = models.ForeignKey(Project)
#     node = models.ForeignKey(BuildNode)
#     revision = models.CharField(max_length=255, blank=True)
#     short_revision = models.CharField(max_length=255, blank=True)
# 
#     started = models.DateTimeField(null=True, blank=True)
#     finished = models.DateTimeField(null=True, blank=True)
# 
#     state = models.CharField(max_length=20, default=BuildState.UNKNOWN,
#         choices=BuildState.choices())
# 
#     def state_css_class(self):
#         # Determine the correct css class
#         if self.state == BuildState.STABLE:
#             return 'success'
#         elif self.state in [BuildState.QUEUED, BuildState.RUNNING]:
#             return 'notice'
#         else: 
#             return 'error'
# 
#     def __unicode__(self):
#         return u'%s/%s/%s (%s)' % (self.project, self.node, self.state,
#             self.started)
# 
#     def queue_build(self):
#         # Create a celery task and set the state to QUEUED
#         BuildTask.delay(self.pk)
#         self.state = BuildState.QUEUED
#         self.save()
# 
#     @property
#     def build_steps(self):
#         return self.buildstep_set.all().order_by('started')
# 
# class BuildState(Options):
#     QUEUED = 'queued'
#     RUNNING = 'running'
#     FAILED = 'failed'
#     UNSTABLE = 'unstable'
#     STABLE = 'stable'
#     UNKNOWN = 'unknown'
# 
# Path: journeyman/buildrunner/registry.py
# LOADING = False
#     LOADING = True
#     LOADING = False
# class StepAlreadyRegistered(Exception):
# class StepNotFound(Exception):
# class Registry(object):
#     def add_step(self, name, func):
#     def list_steps(self):
#     def get_step(self, name):
#         def get_inner_step():
# def autodiscover():


import sys, tempfile, traceback
from StringIO import StringIO
from datetime import datetime
from fabric.state import env
from fabric.network import disconnect_all
from django.utils import simplejson as json
from journeyman.builds.models import Build, BuildState
from journeyman.buildrunner.registry import registry, StepNotFound
                ('prepare virtualenv',
                    registry.get_step('prepare_virtualenv')),
                ('fetch repository',
                    registry.get_step('fetch_repository')),
                ('fetch commit id',
                    registry.get_step('fetch_repository_commit_id')),
                ('fetch config',
                    registry.get_step('fetch_config'))
            ]
            # Execute the first round of steps
            result = _execute_steps(steps)
            # If any step failed, return the error.
            if not result:
                return result

            # Reset the step list
            steps = []

            # Every step from the config should be passed
            for step in self.config['build']:
                # We need to check for a explicit command, not none available
                # use the run_commands plugin.
                plugin = self.config['build_plugins'].get(step, None)

                # Get the real name of the step (including plugin)
                step_name = '%s[%s]' % (step, plugin) if plugin else step
                step_plugin = plugin or 'run_commands'

                # Append the step to the list of steps.
                steps.append(('execute step %s (%s)' % (step, step_plugin),

# Path: journeyman/builds/models.py
# class Build(models.Model):
#     project = models.ForeignKey(Project)
#     node = models.ForeignKey(BuildNode)
#     revision = models.CharField(max_length=255, blank=True)
#     short_revision = models.CharField(max_length=255, blank=True)
# 
#     started = models.DateTimeField(null=True, blank=True)
#     finished = models.DateTimeField(null=True, blank=True)
# 
#     state = models.CharField(max_length=20, default=BuildState.UNKNOWN,
#         choices=BuildState.choices())
# 
#     def state_css_class(self):
#         # Determine the correct css class
#         if self.state == BuildState.STABLE:
#             return 'success'
#         elif self.state in [BuildState.QUEUED, BuildState.RUNNING]:
#             return 'notice'
#         else: 
#             return 'error'
# 
#     def __unicode__(self):
#         return u'%s/%s/%s (%s)' % (self.project, self.node, self.state,
#             self.started)
# 
#     def queue_build(self):
#         # Create a celery task and set the state to QUEUED
#         BuildTask.delay(self.pk)
#         self.state = BuildState.QUEUED
#         self.save()
# 
#     @property
#     def build_steps(self):
#         return self.buildstep_set.all().order_by('started')
# 
# class BuildState(Options):
#     QUEUED = 'queued'
#     RUNNING = 'running'
#     FAILED = 'failed'
#     UNSTABLE = 'unstable'
#     STABLE = 'stable'
#     UNKNOWN = 'unknown'
# 
# Path: journeyman/buildrunner/registry.py
# LOADING = False
#     LOADING = True
#     LOADING = False
# class StepAlreadyRegistered(Exception):
# class StepNotFound(Exception):
# class Registry(object):
#     def add_step(self, name, func):
#     def list_steps(self):
#     def get_step(self, name):
#         def get_inner_step():
# def autodiscover():


# Path: journeyman/buildrunner/base.py
import sys, tempfile, traceback
from StringIO import StringIO
from datetime import datetime
from fabric.state import env
from fabric.network import disconnect_all
from django.utils import simplejson as json
from journeyman.builds.models import Build, BuildState
from journeyman.buildrunner.registry import registry, StepNotFound

                ('prepare virtualenv',
                    registry.get_step('prepare_virtualenv')),
                ('fetch repository',
                    registry.get_step('fetch_repository')),
                ('fetch commit id',
                    registry.get_step('fetch_repository_commit_id')),
                ('fetch config',
                    registry.get_step('fetch_config'))
            ]
            # Execute the first round of steps
            result = _execute_steps(steps)
            # If any step failed, return the error.
            if not result:
                return result

            # Reset the step list
            steps = []

            # Every step from the config should be passed
            for step in self.config['build']:
                # We need to check for a explicit command, not none available
                # use the run_commands plugin.
                plugin = self.config['build_plugins'].get(step, None)

                # Get the real name of the step (including plugin)
                step_name = '%s[%s]' % (step, plugin) if plugin else step
                step_plugin = plugin or 'run_commands'

                # Append the step to the list of steps.
                steps.append(('execute step %s (%s)' % (step, step_plugin),

                    registry.get_step(plugin or 'run_commands'), {