# Path: conjureup/app_config.py
# class AppConfig:
#     def __setattr__(self, name, value):
#     def _internal_state_key(self):
#     def all_steps(self):
#     def has_bundle_modifications(self):
#     async def save(self):
#     async def restore(self):
# 
# Path: conjureup/consts.py
# UNSPECIFIED_SPELL = '_unspecified_spell'
# 
# Path: conjureup/utils.py
# @contextmanager
# def chdir(directory):
#     """Change the current working directory to a different directory for a code
#     block and return the previous directory after the block exits. Useful to
#     run commands from a specificed directory.
# 
#     :param str directory: The directory path to change to for this context.
#     """
#     cur = os.getcwd()
#     try:
#         yield os.chdir(directory)
#     finally:
#         os.chdir(cur)
# 
# def run(cmd, **kwargs):
#     """ Compatibility function to support python 3.4
#     """
#     try:
#         from subprocess import run as _run
#         return _run(cmd, **kwargs)
#     except ImportError:
#         if 'check' in kwargs:
#             del kwargs['check']
#             return check_call(cmd, **kwargs)
#         else:
#             return check_output(cmd, **kwargs)


import os
import shutil
import requests
from enum import Enum
from subprocess import DEVNULL, CalledProcessError
from progressbar import (
    AnimatedMarker,
    Bar,
    Percentage,
    ProgressBar,
    UnknownLength
)
from conjureup.app_config import app
from conjureup.consts import UNSPECIFIED_SPELL
from conjureup.utils import chdir, run
    will pull the latest spells down.

    To specify a different branch to use you must set the environment variable
    CONJUREUP_REGISTRY_BRANCH=<branchname>. This should be used for testing
    new spells before they make it into the master branch.

    Arguments:
    remote_registry: git location of spells registry
    spells_dir: cache location of local spells directory
    branch: switch to branch

    """
    def clone():
        run("git clone -q --depth 1 --no-single-branch {} {}".format(
            remote_registry, spells_dir),
            shell=True, check=True, stdout=DEVNULL, stderr=DEVNULL)

    if not os.path.exists(spells_dir):
        clone()
    try:
        with chdir(spells_dir):
            run("git reset --hard HEAD", shell=True, check=True,
                stdout=DEVNULL, stderr=DEVNULL)

            run("git checkout -q {}".format(branch),
                shell=True, check=True, stdout=DEVNULL, stderr=DEVNULL)

            run("git pull", shell=True, check=True,
                stdout=DEVNULL, stderr=DEVNULL)
    except CalledProcessError:

# Path: conjureup/app_config.py
# class AppConfig:
#     def __setattr__(self, name, value):
#     def _internal_state_key(self):
#     def all_steps(self):
#     def has_bundle_modifications(self):
#     async def save(self):
#     async def restore(self):
# 
# Path: conjureup/consts.py
# UNSPECIFIED_SPELL = '_unspecified_spell'
# 
# Path: conjureup/utils.py
# @contextmanager
# def chdir(directory):
#     """Change the current working directory to a different directory for a code
#     block and return the previous directory after the block exits. Useful to
#     run commands from a specificed directory.
# 
#     :param str directory: The directory path to change to for this context.
#     """
#     cur = os.getcwd()
#     try:
#         yield os.chdir(directory)
#     finally:
#         os.chdir(cur)
# 
# def run(cmd, **kwargs):
#     """ Compatibility function to support python 3.4
#     """
#     try:
#         from subprocess import run as _run
#         return _run(cmd, **kwargs)
#     except ImportError:
#         if 'check' in kwargs:
#             del kwargs['check']
#             return check_call(cmd, **kwargs)
#         else:
#             return check_output(cmd, **kwargs)


# Path: conjureup/download.py
import os
import shutil
import requests
from enum import Enum
from subprocess import DEVNULL, CalledProcessError
from progressbar import (
    AnimatedMarker,
    Bar,
    Percentage,
    ProgressBar,
    UnknownLength
)
from conjureup.app_config import app
from conjureup.consts import UNSPECIFIED_SPELL
from conjureup.utils import chdir, run

    will pull the latest spells down.

    To specify a different branch to use you must set the environment variable
    CONJUREUP_REGISTRY_BRANCH=<branchname>. This should be used for testing
    new spells before they make it into the master branch.

    Arguments:
    remote_registry: git location of spells registry
    spells_dir: cache location of local spells directory
    branch: switch to branch

    """
    def clone():
        run("git clone -q --depth 1 --no-single-branch {} {}".format(
            remote_registry, spells_dir),
            shell=True, check=True, stdout=DEVNULL, stderr=DEVNULL)

    if not os.path.exists(spells_dir):
        clone()
    try:
        with chdir(spells_dir):
            run("git reset --hard HEAD", shell=True, check=True,
                stdout=DEVNULL, stderr=DEVNULL)

            run("git checkout -q {}".format(branch),
                shell=True, check=True, stdout=DEVNULL, stderr=DEVNULL)

            run("git pull", shell=True, check=True,
                stdout=DEVNULL, stderr=DEVNULL)
    except CalledProcessError:

        app.log.debug(