Skip to content

Commit

Permalink
flake8ification
Browse files Browse the repository at this point in the history
  • Loading branch information
tswicegood committed Dec 10, 2014
1 parent 0ca5f13 commit 7e5f1eb
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions conda/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,43 @@
SYMLINK_CONDA = 'SYMLINK_CONDA'



progress_cmds = set([EXTRACT, RM_EXTRACTED, LINK, UNLINK])
action_codes = FETCH, EXTRACT, UNLINK, LINK, SYMLINK_CONDA, RM_EXTRACTED, RM_FETCHED
action_codes = (FETCH, EXTRACT, UNLINK, LINK, SYMLINK_CONDA, RM_EXTRACTED,
RM_FETCHED)


def PREFIX_CMD(state, arg):
state['prefix'] = arg


def PRINT_CMD(state, arg):
getLogger('print').info(arg)


def fetch(index, dist):
assert index is not None
fn = dist + '.tar.bz2'
fetch_pkg(index[fn])


def FETCH_CMD(state, arg):
fetch(state['index'], arg)


def PROGRESS_CMD(state, arg):
state['i'] = 0
state['maxval'] = int(arg)
getLogger('progress.start').info(state['maxval'])


def EXTRACT_CMD(state, arg):
install.extract(config.pkgs_dirs[0], arg)


def RM_EXTRACTED_CMD(state, arg):
install.rm_extracted(config.pkgs_dirs[0], arg)


def RM_FETCHED_CMD(state, arg):
install.rm_fetched(config.pkgs_dirs[0], arg)

Expand All @@ -65,45 +73,48 @@ def split_linkarg(arg):
linktype = install.LINK_HARD
return dist, pkgs_dir, int(linktype)


def link(prefix, arg, index=None):
dist, pkgs_dir, lt = split_linkarg(arg)
install.link(pkgs_dir, prefix, dist, lt, index=index)


def LINK_CMD(state, arg):
link(state['prefix'], arg, index=state['index'])


def UNLINK_CMD(state, arg):
install.unlink(state['prefix'], arg)


def SYMLINK_CONDA_CMD(state, arg):
install.symlink_conda(state['prefix'], arg)

# Map instruction to command (a python function)
commands = {
PREFIX: PREFIX_CMD,
PRINT: PRINT_CMD,
FETCH: FETCH_CMD,
PROGRESS: PROGRESS_CMD,
EXTRACT: EXTRACT_CMD,
RM_EXTRACTED: RM_EXTRACTED_CMD,
RM_FETCHED: RM_FETCHED_CMD,
LINK: LINK_CMD,
UNLINK: UNLINK_CMD,
SYMLINK_CONDA: SYMLINK_CONDA_CMD,
}
PREFIX: PREFIX_CMD,
PRINT: PRINT_CMD,
FETCH: FETCH_CMD,
PROGRESS: PROGRESS_CMD,
EXTRACT: EXTRACT_CMD,
RM_EXTRACTED: RM_EXTRACTED_CMD,
RM_FETCHED: RM_FETCHED_CMD,
LINK: LINK_CMD,
UNLINK: UNLINK_CMD,
SYMLINK_CONDA: SYMLINK_CONDA_CMD,
}


class InvaidInstruction(Exception):
pass



def execute_instructions(plan, index=None, verbose=False):
if verbose:
from conda.console import setup_verbose_handlers
setup_verbose_handlers()

state = {'i': None, 'prefix': config.root_dir, 'index':index}
state = {'i': None, 'prefix': config.root_dir, 'index': index}

for instruction, args in plan:

Expand All @@ -116,13 +127,15 @@ def execute_instructions(plan, index=None, verbose=False):
cmd = commands.get(instruction)

if cmd is None:
raise InvaidInstruction("No handler for instruction: %r" % instruction)
raise InvaidInstruction(
"No handler for instruction: %r" % instruction
)

cmd(state, *args)

if state['i'] is not None and cmd in progress_cmds and state['maxval'] == state['i']:
if (state['i'] is not None and cmd in progress_cmds
and state['maxval'] == state['i']):
state['i'] = None
getLogger('progress.stop').info(None)

install.messages(state['prefix'])

0 comments on commit 7e5f1eb

Please sign in to comment.