File: history.pyx

package info (click to toggle)
obitools 3.0.1~b26%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,756 kB
  • sloc: ansic: 24,299; python: 657; sh: 27; makefile: 21
file content (58 lines) | stat: -rwxr-xr-x 1,819 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#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))
        else:
            raise Exception("ASCII history only available for views")
    
    input[0].close(force=True)