示例#1
0
文件: cli.py 项目: pv-bull/sequencer
def depmake(db, config, args):
    """
    Parse the CLI arguments and invoke the 'makedepgraph' function.
    """
    (options, req_ruleset, components_lists) = _parse_depmake_cmdline(config,
                                                                      args)

    rules = db.get_rules_for(req_ruleset)
    dag = None
    depgraph = None
    # Provide the graphing capability even in the case of a
    # CycleDetectedError. Graph can be used to visualize such cycles.
    try:
        depgraph = makedepgraph(config, rules, components_lists, options)
        dag = depgraph.dag
    except CyclesDetectedError as cde:
        # A cycle leads to an error, since it prevents the normal
        # execution.
        _LOGGER.critical(str(cde))
        dag = cde.graph

    # Only execute when the depgraph is available (no cycle detected)
    if depgraph is not None:
        dst = options.out
        _LOGGER.debug("Writing to: %s", dst)

        strgraph = convert_uni_graph_to_str(depgraph.dag)
        output = write(strgraph)
        if dst == '-':
            _LOGGER.output(output)
        else:
            print(output, file=open(dst, "w"))


    # The DOT graph is written afterwards for two reasons:
    #
    # 1. since the XML graph has already been written out, we can
    # modify the model for vizualisation (removing attributes, see
    # 'write_graph_to');
    #
    # 2. if an error occurs in next steps, it does not prevent the XML
    # graph from being used.
    if options.depgraphto is not None:
        write_graph_to(dag, options.depgraphto)

    return os.EX_OK if depgraph is not None else os.EX_DATAERR
示例#2
0
文件: cli.py 项目: af-bull/sequencer
def graphrules(db, config, args):
    """
    This action fetch the rules from the DB sequencer table and call
    the DGM stage for the computation of the related graph.
    This graph is then given to the user in the DOT format.
    """
    usage = "Usage: %prog [global_options] " + GRAPHRULES_ACTION_NAME + \
        " [action_options] ruleset"
    doc = GRAPHRULES_DOC + \
        " The graph is given in DOT format."
    parser = optparse.OptionParser(usage, description=doc)
    add_options_to(parser, ['--out'], config)
    (options, action_args) = parser.parse_args(args)
    if len(action_args) != 1:
        parser.error(GRAPHRULES_ACTION_NAME + ": ruleSet is missing.")

    req_ruleset = action_args[0]
    rules = db.get_rules_for(req_ruleset)
    ruleset = RuleSet(rules.values())
    write_graph_to(ruleset.get_rules_graph(), options.out)
示例#3
0
文件: cli.py 项目: pv-bull/sequencer
def chain(db, config, chain_args):
    """
    Execute the chainer CLI
    """
    (options, action_args) = _parse(config, chain_args)
    req_ruleset = action_args[0]
    components_lists = dgm_cli.parse_components_lists(action_args[1:])

    rules = db.get_rules_for(req_ruleset)
    depdag = None
    seqdag = None
    depgraph = None
    execution = None
    # Provide the graphing capability even in the case of a
    # CycleDetectedError. Graph can be used to visualize such cycles.
    try:
        depmake_start = time.time()
        depgraph = dgm_cli.makedepgraph(config,
                                        rules,
                                        components_lists,
                                        options)
        depmake_stop = time.time()
        if options.depgraphto is not None:
            # Deep copy is required since the ISM modify the original
            # graph. This is mandatory so the graph can be written
            # afterwards. However, deepcopy has an obvious cost: we
            #  only make a deepcopy when it is required:hence the
            #  condition.
            depdag = copy.deepcopy(depgraph.dag)
        else:
            depdag = depgraph.dag
    except CyclesDetectedError as cde:
        # Output an error here since we can't continue
        _LOGGER.critical(str(cde))
        depdag = cde.graph

    # A cycle has not been detected, we can continue.
    if depgraph is not None:
        seqmake_start = time.time()
        (ise_model, xml_result, error) = ism_cli.makesequence(depgraph.dag,
                                                              options.algo)
        seqmake_stop = time.time()
        if ise_model is None:
            assert error is not None
            _LOGGER.critical(str(error))
            seqdag = error.graph
        else:
            seqdag = ise_model.dag
            seqexec_start = time.time()
            execution = ise_cli.execute(ise_model, options)
            seqexec_stop = time.time()

            ise_cli.report(options.report, ise_model, execution)
            if getattr(options, 'dostats', 'no') == 'yes':
                stats = ise_cli.get_header(" STATS ",
                                           "=",
                                           ise_cli.REPORT_HEADER_SIZE)
                _LOGGER.output(stats)
                lines = ise_cli.report_stats(execution,
                                             ('DepMake',
                                              depmake_start, depmake_stop),
                                             ('SeqMake',
                                              seqmake_start, seqmake_stop),
                                             ('SeqExec',
                                              seqexec_start, seqexec_stop))
                for line in lines:
                    _LOGGER.output(line)


    # The DOT format graphs are written out at the end for various reasons:
    #
    # - graph models are modified by the 'write_graph_to' function.
    #
    # - the time required to make that graph should not be taken into
    # account (since it can be produced without execution using
    # --doexec option)
    #
    # - if an error occurs in next steps it does not prevent the
    # execution of anything useful
    if options.depgraphto is not None:
        write_graph_to(depdag, options.depgraphto)


    if options.actionsgraphto is not None and seqdag is not None:
        write_graph_to(seqdag, options.actionsgraphto)

    return execution.rc if execution is not None else os.EX_DATAERR
示例#4
0
def seqexec(db, config, args):
    """
    Parse the CLI arguments and invoke the 'seqexec' function.
    """
    (options, action_args) = _parse(db.basedir, config, args)

    _LOGGER.debug("Reading from: %s", options.src)
    src = options.src
    if src == '-':
        src = sys.stdin

    parser_start = time.time()
    the_parser = parser.ISEParser(src)
    parser_stop = time.time()

    # Provide the graphing capability even in the case of a
    # CycleDetectedError. Graph can be used to visualize such cycles.
    the_model = None
    dag = None
    try:
        model_start = time.time()
        the_model = model.Model(the_parser.root)
        dag = the_model.dag
        model_stop = time.time()
    except CyclesDetectedError as cde:
        # A cycle leads to an error, since it prevents the normal
        # execution.
        _LOGGER.critical(str(cde))
        dag = cde.graph

    if the_model is not None:
        exec_start = time.time()
        execution = execute(the_model, options)
        exec_stop = time.time()

        report(options.report, the_model, execution)

        if getattr(options, 'dostats', 'no') == 'yes':
            _LOGGER.output(get_header(" STATS ", "=", REPORT_HEADER_SIZE))
            for line in report_stats(execution,
                                     ('Parsing', parser_start, parser_stop),
                                     ('Modelling', model_start, model_stop),
                                     ('Execution', exec_start, exec_stop)):
                _LOGGER.output(line)




    # The DOT format graph is written out at the end for various reasons:
    #
    # - the graph model is modified by the 'write_graph_to' function.
    #
    # - the time required to make that graph should not be taken into
    # account (since it can be produced without execution using
    # --doexec option)
    #
    # - if an error occurs in next steps it does not prevent the
    # execution of anything useful
    if options.actionsgraphto is not None:
        write_graph_to(dag, options.actionsgraphto)

    return execution.rc if the_model is not None else os.EX_DATAERR