From e31c8ea57a0b32c1688b1fcbf84db9f30a93ab94 Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Sun, 7 Oct 2018 19:11:36 +0200 Subject: [PATCH] New command: obi history to print DMS or view history in bash, dot or ascii formats --- python/obitools3/commands/history.pyx | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 python/obitools3/commands/history.pyx diff --git a/python/obitools3/commands/history.pyx b/python/obitools3/commands/history.pyx new file mode 100644 index 0000000..6a65734 --- /dev/null +++ b/python/obitools3/commands/history.pyx @@ -0,0 +1,57 @@ +#cython: language_level=3 + +from obitools3.apps.optiongroups import addMinimalInputOption +from obitools3.uri.decode import open_uri +from obitools3.dms import DMS +from obitools3.dms.view import View +from obitools3.utils cimport bytes2str + + +__title__="Command line histories and view history graphs" + + +def addOptions(parser): + + addMinimalInputOption(parser) + + group=parser.add_argument_group('obi history specific options') + + group.add_argument('--bash', '-b', + action="store_const", dest="history:format", + default="bash", + const="bash", + help="Print history in bash format") + + group.add_argument('--dot', '-d', + action="store_const", dest="history:format", + default="bash", + const="dot", + help="Print history in DOT format (default: bash format)") + + group.add_argument('--ascii', '-a', + action="store_const", dest="history:format", + default="bash", + const="ascii", + help="Print history in ASCII format (only for views; default: bash format)") + + +def run(config): + + cdef object entries + + DMS.obi_atexit() + + input = open_uri(config['obi']['inputURI']) + + entries = input[1] + + if config['history']['format'] == "bash" : + print(bytes2str(entries.bash_history)) + elif config['history']['format'] == "dot" : + print(bytes2str(entries.dot_history_graph)) + elif config['history']['format'] == "ascii" : + if isinstance(entries, View): + print(bytes2str(entries.ascii_history_graph)) + else: + raise Exception("ASCII history only available for views") +