Exemplo n.º 1
0
def history_main(args=None, stdin=None, stdout=None, stderr=None):
    """This is the history command entry point."""
    hist = builtins.__xonsh_history__
    ns = _xh_parse_args(args)
    if not ns or not ns.action:
        return
    if ns.action == 'show':
        _xh_show_history(hist, ns, stdout=stdout, stderr=stderr)
    elif ns.action == 'info':
        data = hist.info()
        if ns.json:
            s = json.dumps(data)
            print(s, file=stdout)
        else:
            lines = ['{0}: {1}'.format(k, v) for k, v in data.items()]
            print('\n'.join(lines), file=stdout)
    elif ns.action == 'id':
        if not hist.sessionid:
            return
        print(str(hist.sessionid), file=stdout)
    elif ns.action == 'file':
        if not hist.filename:
            return
        print(str(hist.filename), file=stdout)
    elif ns.action == 'gc':
        hist.run_gc(size=ns.size, blocking=ns.blocking)
    elif ns.action == 'diff':
        if isinstance(hist, JsonHistory):
            xdh.dh_main_action(ns)
    elif ns.action == 'replay':
        if isinstance(hist, JsonHistory):
            import xonsh.replay as xrp
            xrp.replay_main_action(hist, ns, stdout=stdout, stderr=stderr)
    else:
        print('Unknown history action {}'.format(ns.action), file=sys.stderr)
Exemplo n.º 2
0
def history_main(args=None, stdin=None, stdout=None, stderr=None):
    """This is the history command entry point."""
    hist = builtins.__xonsh_history__
    ns = _xh_parse_args(args)
    if not ns or not ns.action:
        return
    if ns.action == 'show':
        _xh_show_history(hist, ns, stdout=stdout, stderr=stderr)
    elif ns.action == 'info':
        data = hist.info()
        if ns.json:
            s = json.dumps(data)
            print(s, file=stdout)
        else:
            lines = ['{0}: {1}'.format(k, v) for k, v in data.items()]
            print('\n'.join(lines), file=stdout)
    elif ns.action == 'id':
        if not hist.sessionid:
            return
        print(str(hist.sessionid), file=stdout)
    elif ns.action == 'file':
        if not hist.filename:
            return
        print(str(hist.filename), file=stdout)
    elif ns.action == 'gc':
        hist.run_gc(size=ns.size, blocking=ns.blocking)
    elif ns.action == 'diff':
        if isinstance(hist, JsonHistory):
            xdh.dh_main_action(ns)
    elif ns.action == 'replay':
        if isinstance(hist, JsonHistory):
            import xonsh.replay as xrp
            xrp.replay_main_action(hist, ns, stdout=stdout, stderr=stderr)
    else:
        print('Unknown history action {}'.format(ns.action), file=sys.stderr)
Exemplo n.º 3
0
def history_main(
    args=None, stdin=None, stdout=None, stderr=None, spec=None, stack=None
):
    """This is the history command entry point."""
    hist = builtins.__xonsh__.history
    ns = _xh_parse_args(args)
    if not ns or not ns.action:
        return
    if ns.action == "show":
        _xh_show_history(hist, ns, stdout=stdout, stderr=stderr)
    elif ns.action == "info":
        data = hist.info()
        if ns.json:
            s = json.dumps(data)
            print(s, file=stdout)
        else:
            lines = ["{0}: {1}".format(k, v) for k, v in data.items()]
            print("\n".join(lines), file=stdout)
    elif ns.action == "id":
        if not hist.sessionid:
            return
        print(str(hist.sessionid), file=stdout)
    elif ns.action == "file":
        if not hist.filename:
            return
        print(str(hist.filename), file=stdout)
    elif ns.action == "gc":
        hist.run_gc(size=ns.size, blocking=ns.blocking, force=ns.force_gc)
    elif ns.action == "diff":
        if isinstance(hist, JsonHistory):
            xdh.dh_main_action(ns)
    elif ns.action == "flush":
        hf = hist.flush()
        if isinstance(hf, threading.Thread):
            hf.join()
    elif ns.action == "off":
        if hist.remember_history:
            hist.clear()
            hist.remember_history = False
            print("History off", file=sys.stderr)
    elif ns.action == "on":
        if not hist.remember_history:
            hist.remember_history = True
            print("History on", file=sys.stderr)
    elif ns.action == "clear":
        hist.clear()
        print("History cleared", file=sys.stderr)
    else:
        print("Unknown history action {}".format(ns.action), file=sys.stderr)
Exemplo n.º 4
0
def history_main(
    args=None, stdin=None, stdout=None, stderr=None, spec=None, stack=None
):
    """This is the history command entry point."""
    hist = builtins.__xonsh__.history
    ns = _xh_parse_args(args)
    if not ns or not ns.action:
        return
    if ns.action == "show":
        _xh_show_history(hist, ns, stdout=stdout, stderr=stderr)
    elif ns.action == "info":
        data = hist.info()
        if ns.json:
            s = json.dumps(data)
            print(s, file=stdout)
        else:
            lines = ["{0}: {1}".format(k, v) for k, v in data.items()]
            print("\n".join(lines), file=stdout)
    elif ns.action == "id":
        if not hist.sessionid:
            return
        print(str(hist.sessionid), file=stdout)
    elif ns.action == "file":
        if not hist.filename:
            return
        print(str(hist.filename), file=stdout)
    elif ns.action == "gc":
        hist.run_gc(size=ns.size, blocking=ns.blocking)
    elif ns.action == "diff":
        if isinstance(hist, JsonHistory):
            xdh.dh_main_action(ns)
    elif ns.action == "replay":
        if isinstance(hist, JsonHistory):
            import xonsh.replay as xrp

            xrp.replay_main_action(hist, ns, stdout=stdout, stderr=stderr)
    else:
        print("Unknown history action {}".format(ns.action), file=sys.stderr)