Exemple #1
0
def _generic_command(sin, sout, serr, argv, efx):
    """
    The associated path is a directory of files in some obvious order.

    Under the hood; we create a temporary directory, init it as a git
    repository, add the first file snapshot, commit it, copy the second
    file snapshot over to the file, add it, commit it and so on until
    all the snapshots have been written in to the repository.

    There will be tons of other metadata stored in a recfile probably.

    The end result is we write to STDOUT the results of going `git log`
    (with particular options stored in the parameters recfile probably)
    on the respository.
    """

    bash_argv = list(reversed(argv))
    prog_name = bash_argv.pop()
    foz = _foz_via(_formals_for_generic_command(), lambda: prog_name)
    vals, rc = foz.terminal_parse(serr, bash_argv)
    if vals is None:
        return None, rc
    if vals.get('help'):
        return foz.write_help_into(sout, _generic_command.__doc__)

    source_path = efx['fixture_source_path']

    from script_lib.magnetics.error_monitor_via_stderr import func
    mon = func(serr)

    from . import real_system_response_via_story_source_path_ as func
    lines = func(source_path, mon.listener)
    sout.writelines(lines)
    return mon.returncode
Exemple #2
0
def _common_execute(serr, argv, efx, doc, formals, functioner):
    bash_argv = list(reversed(argv))
    long_prog_name = bash_argv.pop()
    prog_name = _prog_name_function_via(long_prog_name)
    foz = _foz_via(formals, prog_name)

    vals, es = foz.terminal_parse(serr, bash_argv)
    if vals is None:
        return es

    if vals.get('help'):
        serr.writelines(foz.help_lines(doc=doc))
        return 0

    mon = efx.produce_monitor()
    listener = mon.listener

    coll_path, rc = efx.require_collection_path(listener, vals)
    if not coll_path:
        return rc

    func = functioner()
    res = func(coll_path, listener=listener, **vals)
    assert res is None

    return mon.returncode
def query_parser():
    from .tagging_subtree_via_string import grammar_path_ as func
    _grammar_path = func('the-query-grammar.ebnf')

    with open(_grammar_path) as fh:
        ebnf_grammar_big_string = fh.read()

    import tatsu
    return tatsu.compile(ebnf_grammar_big_string, asmodel=True)
def EXPERIMENTAL_NEW_WAY(tokens, listener):
    """ 33 months later we think we can do better than tatsu

    for our use case anyway. #history-B.4
    """

    sx = _recursive_sexp_via(tokens, listener)
    if sx is None:
        return
    from tag_lyfe.the_query_model import simplified_matcher_via_sexp_ as func
    return func(sx)
Exemple #5
0
def _execute_command_now__no_daemonize(sout, serr, cmd, config, mon):
    if config is None:
        serr.write("-c option needs a <config-path> argument\n")
        return 123

    def recv_output_line(line):
        sout.write(line)
        sout.write('\n')
    from pho.config_component_ import capture_output_lines_ as func
    listener = func(recv_output_line, mon.listener)
    rc = config.EXECUTE_COMMAND(cmd, listener)
    if not isinstance(rc, int):  # #todo
        raise RuntimeError(f"oops: {type(rc)}")
    return rc
def RUMSKALLA(serr, query_s):
    def my_pprint(x):
        from pprint import pprint
        pprint(x, stream=serr, width=20, indent=4)

    itr = MAKE_CRAZY_ITERATOR_THING(query_s)
    print('the model:')
    my_pprint(next(itr))

    print('the unsani:')
    unsani = next(itr)

    from script_lib.magnetics.error_monitor_via_stderr import func
    monitor = func(serr)

    wat = unsani.sanitize(monitor.listener)

    print('the sani:')
    my_pprint(wat)

    return monitor.exitstatus
def _build_simplified_tag_parser_and_stop(cstacker, listener):
    # EXPERIMENTAL does check only for now

    def parse_tag(token):
        try:
            return main(token)
        except stop:
            pass

    def main(token):
        scn = build_string_scanner(token)
        scn.skip_required(leading_octothorpe)
        scn.skip_required(tag_body)
        scn.skip_required(the_end)

    from text_lib.magnetics.string_scanner_via_string import \
        build_throwing_string_scanner_and_friends as func
    o, build_string_scanner, stop = func(listener, cstacker)

    leading_octothorpe = o("'#'", '#')
    tag_body = o('tag body ([-a-z]..)', '[a-z]+(?:-[a-z]+)*')
    the_end = o('end of tag', r'\Z')

    return parse_tag, stop
Exemple #8
0
def _load_commonly(mod_tail):
    from importlib import import_module as func
    return func(f'pho.cli.commands.{mod_tail}').CLI
Exemple #9
0
def _foz_via(defs, pner, x=None):
    from script_lib.cheap_arg_parse import formals_via_definitions as func
    return func(defs, pner, x)
Exemple #10
0
def _cheap_arg_parse_branch(sin, sout, serr, argv, cx, doc, efx):
    from script_lib.cheap_arg_parse import cheap_arg_parse_branch as func
    return func(sin, sout, serr, argv, cx, doc, efx)
Exemple #11
0
 def produce_monitor(_):
     from script_lib.magnetics.error_monitor_via_stderr import func
     return func(stderr, default_error_exitstatus=5678)
Exemple #12
0
def _load_the_connect_COMMAND():
    from pho.cli.commands.connect import build_CLI_command_ as func
    return func(_port, _foz_via)
Exemple #13
0
def _CLI(sin, sout, serr, argv, efx):  # efx = external functions
    def line_contents():
        yield 'experiments in generating documents from "notecards"'
    func = _cheap_arg_parse_branch
    return func(sin, sout, serr, argv, _commands(), line_contents, efx)
Exemple #14
0
    config_path = vals.pop('config_path', None)
    cmd = vals.pop('command', None)
    port = vals.pop('port')
    assert not vals

    kw = {}
    mon = efx.produce_monitor()

    # Process the config option if it was passed (processing it can fail)
    config = None
    if config_path:
        use_environ = efx.produce_environ()
        from pho.generation_service_.generation_config_via_definition import \
            via_path as func
        config = func(config_path, use_environ, mon.listener)

        if config is None:
            return mon.returncode

        kw['config'] = config

    # The --command option requires a config
    if cmd:
        return _execute_command_now__no_daemonize(sout, serr, cmd, config, mon)

    from pho.generation_service_.run_message_broker_via_config import func
    func(mon.listener, port, **kw)  # run forever or until interrupt
    return mon.returncode