示例#1
0
def script(configuration, script_path, script_args):
    """Run a script managed by claw with the provided configuration
       as context."""
    conf = Configuration(configuration)
    if not conf.exists():
        raise NO_INIT
    if not os.path.isfile(script_path):
        for scripts_dir in settings.scripts:
            possible_script_path = scripts_dir / script_path
            possible_script_path2 = scripts_dir / '{0}.py'.format(script_path)
            if possible_script_path.isfile():
                script_path = possible_script_path
                break
            if possible_script_path2.isfile():
                script_path = possible_script_path2
                break
        else:
            raise argh.CommandError('Could not locate {0}'.format(script_path))
    exec_globs = exec_env.exec_globals(script_path)
    execfile(script_path, exec_globs)
    if script_args and script_args[0] in exec_globs:
        func = script_args[0]
        script_args = script_args[1:]
    else:
        func = 'script'
    script_func = exec_globs.get(func)
    if not script_func:
        raise argh.CommandError('Cannot find a function to execute. Did you '
                                'add a default "script" function?')
    try:
        current_configuration.set(conf)
        argh.dispatch_command(script_func, argv=script_args)
    finally:
        current_configuration.clear()
示例#2
0
def script(configuration, script_path, script_args):
    """Run a script managed by claw with the provided configuration
       as context."""
    conf = Configuration(configuration)
    if not conf.exists():
        raise NO_INIT
    if not os.path.isfile(script_path):
        for scripts_dir in settings.scripts:
            possible_script_path = scripts_dir / script_path
            possible_script_path2 = scripts_dir / '{0}.py'.format(script_path)
            if possible_script_path.isfile():
                script_path = possible_script_path
                break
            if possible_script_path2.isfile():
                script_path = possible_script_path2
                break
        else:
            raise argh.CommandError('Could not locate {0}'.format(script_path))
    exec_globs = exec_env.exec_globals(script_path)
    execfile(script_path, exec_globs)
    if script_args and script_args[0] in exec_globs:
        func = script_args[0]
        script_args = script_args[1:]
    else:
        func = 'script'
    script_func = exec_globs.get(func)
    if not script_func:
        raise argh.CommandError('Cannot find a function to execute. Did you '
                                'add a default "script" function?')
    try:
        current_configuration.set(conf)
        argh.dispatch_command(script_func, argv=script_args)
    finally:
        current_configuration.clear()
示例#3
0
def exec_tasks_file(tasks_file=None):
    tasks_file = tasks_file or 'tasks.py'
    exec_globals = exec_env.exec_globals(tasks_file)
    try:
        execfile(tasks_file, exec_globals)
    except Exception, e:
        raise CloudifyCliError('Failed evaluating {0} ({1}:{2}'
                               .format(tasks_file, type(e).__name__, e))
示例#4
0
文件: dev.py 项目: wksw/cloudify-cli
def exec_tasks_file(tasks_file=None):
    tasks_file = tasks_file or 'tasks.py'
    exec_globals = exec_env.exec_globals(tasks_file)
    try:
        execfile(tasks_file, exec_globals)
    except Exception as e:
        raise CloudifyCliError('Failed evaluating {0} ({1}:{2}'
                               .format(tasks_file, type(e).__name__, e))

    return dict([(task_name, task) for task_name, task in exec_globals.items()
                 if callable(task) and not task_name.startswith('_')])