Esempio n. 1
0
def prepare_workflow_execution(recursive=False, **kwargs):
    """Set parameters for the workflow execution
    and run the workflow."""

    # Set the logging levels.
    level = 'ACTION_INFO'
    if kwargs['quiet']:
        level = 'INFO'
    if kwargs['debug']:
        level = 'DEBUG'
    log.setLevel(level)
    if kwargs['log_file']:
        logging.add_log(log, kwargs['log_file'])

    # Remove the unnecessary kwargs.
    kwargs.pop('quiet')
    kwargs.pop('debug')
    kwargs.pop('log_file')

    # Run the workflow accordingly as recursive/CI and Non-CI.
    if recursive:
        for wfile in pu.find_recursive_wfile():
            kwargs['wfile'] = wfile
            run_workflow(**kwargs)
    else:
        run_workflow(**kwargs)
Esempio n. 2
0
def cli(ctx, wfile, recursive):
    """
    Creates a graph in the .dot format representing the workflow
    """
    wfile_list = list()
    if recursive:
        wfile_list = pu.find_recursive_wfile()
    else:
        wfile_list.append(pu.find_default_wfile(wfile))

    for wfile in wfile_list:
        pipeline = Workflow(wfile, False, False, False, False)

        graph = list()

        wf = pipeline.wf
        workflow_name = list(wf['workflow'].keys())[0]

        action = wf['resolves'][0]
        last_action = get_first_action(wf)

        for act in last_action:
            graph.append("\t{} -> {};\n".format(
                workflow_name.replace(' ', '_').replace('-', '_'),
                act.replace(' ', '_').replace('-', '_')))

        parent_action = cur_action = action
        graph = add(parent_action, cur_action, wf['action'], graph)
        graph = ''.join(list(set(graph)))
        graph = "digraph G {\n" + graph + "}\n"
        pu.info(graph)
Esempio n. 3
0
def cli(ctx, wfile, recursive):
    """
    Creates a graph in the .dot format representing the workflow.
    """
    def add_to_graph(graph_str, wf, parent, children):
        """Recursively goes through "next" and adds corresponding actions
        """
        _parent = parent.replace(' ', '_').replace('-', '_')
        for n in children:
            _n = n.replace(' ', '_').replace('-', '_')
            graph_str += "  {} -> {};\n".format(_parent, _n)
            for M in wf.get_action(n).get('next', []):
                graph_str = add_to_graph(graph_str, wf, n, [M])

        return graph_str

    wfile_list = list()

    if recursive:
        wfile_list = pu.find_recursive_wfile()
    else:
        wfile_list.append(pu.find_default_wfile(wfile))

    for wfile in wfile_list:
        pipeline = WorkflowRunner(wfile, False, False, False, False, True)
        wf = pipeline.wf
        workflow_name = wf.name.replace(' ', '_').replace('-', '_')
        graph_str = add_to_graph("", wf, workflow_name, wf.root)
        log.info("digraph G {\n" + graph_str + "}\n")
Esempio n. 4
0
def cli(ctx, action, wfile, skip_clone, skip_pull, skip, workspace, reuse,
        recursive, quiet, debug, dry_run, parallel, log_file,
        with_dependencies, on_failure):
    """Executes one or more pipelines and reports on their status.
    """
    popper.scm.get_git_root_folder()
    level = 'ACTION_INFO'
    if quiet:
        level = 'INFO'
    if debug:
        level = 'DEBUG'
    log.setLevel(level)
    if log_file:
        logging.add_log(log, log_file)

    if os.environ.get('CI') == 'true':
        log.info("Running in CI environment.")
        if recursive:
            log.warning('When CI variable is set, --recursive is ignored.')
        wfile_list = pu.find_recursive_wfile()
        wfile_list = workflows_from_commit_message(wfile_list)
    else:
        if recursive:
            if action:
                log.fail(
                    "An 'action' argument and the --recursive flag cannot be "
                    "both given.")
            wfile_list = pu.find_recursive_wfile()
        else:
            wfile_list = [wfile]

    if not wfile_list:
        log.fail("No workflow to execute.")

    for wfile in wfile_list:
        wfile = pu.find_default_wfile(wfile)
        log.info("Found and running workflow at " + wfile)
        run_pipeline(action, wfile, skip_clone, skip_pull, skip, workspace,
                     reuse, dry_run, parallel, with_dependencies, on_failure)
Esempio n. 5
0
def cli(ctx, action, wfile, workspace, reuse, recursive, quiet, debug, dry_run,
        parallel):
    """Executes one or more pipelines and reports on their status.
    """
    if recursive:
        wfile_list = pu.find_recursive_wfile()
        for wfile in wfile_list:
            pu.info("Found and running workflow at " + wfile + "\n")
            run_pipeline(action, wfile, workspace, reuse, quiet, debug,
                         dry_run, parallel)
    else:
        run_pipeline(action, wfile, workspace, reuse, quiet, debug, dry_run,
                     parallel)
    def test_find_recursive_wfile(self):
        os.chdir('/tmp')
        os.makedirs('/tmp/one/two/three')
        self.touch_file('/tmp/one/a.workflow')
        self.touch_file('/tmp/one/two/b.workflow')
        self.touch_file('/tmp/one/two/three/c.workflow')

        wfiles = pu.find_recursive_wfile()
        self.assertListEqual(wfiles, [
            '/tmp/one/a.workflow', '/tmp/one/two/b.workflow',
            '/tmp/one/two/three/c.workflow'
        ])

        shutil.rmtree('/tmp/one')
Esempio n. 7
0
def cli(ctx, wfile, skip, recursive, colors):
    """
    Creates a graph in the .dot format representing the workflow.
    """
    def add_to_graph(dot_str, wf, parent, children, node_attrs, stage_edges):
        """Recursively goes over the children ("next" attribute) of the given
        parent, adding an edge from parent to children
        """
        for n in children:
            edge = '  "{}" -> "{}";\n'.format(parent, n)
            if edge in stage_edges:
                continue
            dot_str += edge + '  "{}" [{}];\n'.format(n, node_attrs)

            stage_edges.add(edge)

            for M in wf.get_action(n).get('next', []):
                dot_str = add_to_graph(dot_str, wf, n, [M], node_attrs,
                                       stage_edges)
        return dot_str

    wfile_list = list()

    if recursive:
        wfile_list = pu.find_recursive_wfile()
    else:
        wfile_list.append(pu.find_default_wfile(wfile))

    for wfile in wfile_list:
        wf = Workflow(wfile)
        wf.parse()
        wf = Workflow.skip_actions(wf, skip)
        wf.check_for_unreachable_actions()

        node_attrs = ('shape=box, style="filled{}", fillcolor=transparent{}')
        wf_attr = node_attrs.format(',rounded', ',color=red' if colors else '')
        act_attr = node_attrs.format('', ',color=cyan' if colors else '')
        dot_str = add_to_graph("", wf, wf.name, wf.root, act_attr, set())
        dot_str += '  "{}" [{}];\n'.format(wf.name, wf_attr)
        log.info("digraph G { graph [bgcolor=transparent];\n" + dot_str +
                 "}\n")
Esempio n. 8
0
def cli(ctx, action, wfile, workspace, reuse, recursive, quiet, debug, dry_run,
        parallel, log_file):
    """Executes one or more pipelines and reports on their status.
    """
    popper.scm.get_git_root_folder()
    level = 'ACTION_INFO'
    if quiet:
        level = 'INFO'
    if debug:
        level = 'DEBUG'
    log.setLevel(level)
    if log_file:
        logging.add_log(log, log_file)
    if recursive:
        wfile_list = pu.find_recursive_wfile()
        if not wfile_list:
            log.fail("Recursive search couldn't find any .workflow files ")
        for wfile in wfile_list:
            log.info("Found and running workflow at " + wfile)
            run_pipeline(action, wfile, workspace, reuse, dry_run, parallel)
    else:
        run_pipeline(action, wfile, workspace, reuse, dry_run, parallel)