# 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 yaml, tempfile
from fabric.api import run, cd, get
from fabric.contrib.files import exists
from journeyman.buildrunner.registry import registry


class InvalidConfigFileException(Exception):
    pass

class InvalidConfigException(Exception):
    pass

def fetch_config(build_runner, **kwargs):
    # Check if we have a config file in the repository
    if build_runner.build.project.config_file:
        # Move to the directory
        with cd(build_runner.build_src):
            # Check if the file really exists.
            if not exists(build_runner.build.project.config_file):
                # No file found, error!
                raise InvalidConfigFileException(
                    'Journey.conf not found: %s' % 
                        build_runner.build.project.config_file)

            # We need the current directory for the download
            pwd = run('pwd')
            # .. and a local file to temp. store the config
            config_file = tempfile.NamedTemporaryFile()
            # Download!
            get('%s/%s' % (pwd, build_runner.build.project.config_file),
                config_file.name)

            try:
                # Try to parse the config

# 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_config.py
import yaml, tempfile
from fabric.api import run, cd, get
from fabric.contrib.files import exists
from journeyman.buildrunner.registry import registry



class InvalidConfigFileException(Exception):
    pass

class InvalidConfigException(Exception):
    pass

def fetch_config(build_runner, **kwargs):
    # Check if we have a config file in the repository
    if build_runner.build.project.config_file:
        # Move to the directory
        with cd(build_runner.build_src):
            # Check if the file really exists.
            if not exists(build_runner.build.project.config_file):
                # No file found, error!
                raise InvalidConfigFileException(
                    'Journey.conf not found: %s' % 
                        build_runner.build.project.config_file)

            # We need the current directory for the download
            pwd = run('pwd')
            # .. and a local file to temp. store the config
            config_file = tempfile.NamedTemporaryFile()
            # Download!
            get('%s/%s' % (pwd, build_runner.build.project.config_file),
                config_file.name)

            try:
                # Try to parse the config

                build_runner.config = yaml.load(config_file)