# 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
from journeyman.buildrunner.registry import registry
# We need this because the production environment runs python2.5
from __future__ import with_statement



class InvalidRepositoryException(Exception):
    pass

def fetch_repository(build_runner, **kwargs):
    # FIXME: support multiple vcs types
    if not build_runner.build.project.repository.startswith('git+'):
        raise InvalidRepositoryException(
            'Invalid repository: %s' % build_runner.build.project.repository)

    # Generate the repo path.
    build_runner.build_src = '%s/src' % build_runner.build_ve_path

    # Execute the clone command.
    output = run('git clone --depth=1 %s %s' % (
        ''.join(build_runner.build.project.repository.split('+')[1:]),
        build_runner.build_src))

    # Pass the return code of the vcs.
    return output.return_code == 0, output.return_code

# 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/fetch_repository.py
from fabric.api import run
from journeyman.buildrunner.registry import registry

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



class InvalidRepositoryException(Exception):
    pass

def fetch_repository(build_runner, **kwargs):
    # FIXME: support multiple vcs types
    if not build_runner.build.project.repository.startswith('git+'):
        raise InvalidRepositoryException(
            'Invalid repository: %s' % build_runner.build.project.repository)

    # Generate the repo path.
    build_runner.build_src = '%s/src' % build_runner.build_ve_path

    # Execute the clone command.
    output = run('git clone --depth=1 %s %s' % (
        ''.join(build_runner.build.project.repository.split('+')[1:]),
        build_runner.build_src))

    # Pass the return code of the vcs.
    return output.return_code == 0, output.return_code

# Register the plugin

registry.add_step('fetch_repository', fetch_repository)