# 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():


from fabric.api import run, cd, prefix
from journeyman.buildrunner.registry import registry
# We need this because the production environment runs python2.5
from __future__ import with_statement



def run_commands(build_runner, **kwargs):
    # Move to the repo directory
    with cd(build_runner.build_src):
        # Every command should get executed within the virtualenv.
        with prefix('source ../bin/activate'):
            for command in kwargs.get('lines', []):
                #  Execute every command.
                output = run(command)

                # We assume that everything works, if not. Abort the step
                if output.return_code != 0:
                    return False, output.return_code

    # Done.
    return True, 0

# Register the plugin

# 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/build_steps/run_commands.py
from fabric.api import run, cd, prefix
from journeyman.buildrunner.registry import registry

# We need this because the production environment runs python2.5
from __future__ import with_statement



def run_commands(build_runner, **kwargs):
    # Move to the repo directory
    with cd(build_runner.build_src):
        # Every command should get executed within the virtualenv.
        with prefix('source ../bin/activate'):
            for command in kwargs.get('lines', []):
                #  Execute every command.
                output = run(command)

                # We assume that everything works, if not. Abort the step
                if output.return_code != 0:
                    return False, output.return_code

    # Done.
    return True, 0

# Register the plugin

registry.add_step('run_commands', run_commands)