forked from khilnani/pythonista-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch_stash.py
80 lines (72 loc) · 2.25 KB
/
launch_stash.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!python2
# coding: utf-8
"""
Launch StaSh in a more flexible and reliable way.
"""
import sys
import argparse
module_names = (
'stash',
'system.shcommon',
'system.shstreams',
'system.shscreens',
'system.shterminal',
'system.shui',
'system.shio',
'system.shiowrapper',
'system.shparsers',
'system.shruntime',
'system.shthreads',
'system.shuseractionproxy',
)
# Attempt to reload modules when startup, does not seem to work
if 'stash.stash' in sys.modules:
for name in module_names:
sys.modules.pop('stash.' + name)
from stash import stash
ap = argparse.ArgumentParser()
ap.add_argument('--no-cfgfile', action='store_true',
help='do not load external config files')
ap.add_argument('--no-rcfile', action='store_true',
help='do not load external resource file')
ap.add_argument('--no-historyfile', action='store_true',
help='do not load history file from last session')
ap.add_argument('--log-level',
choices=['DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL'],
default='INFO',
help='the logging level')
ap.add_argument('--log-file',
help='the file to send logging messages')
ap.add_argument('--debug-switch',
default='',
help='a comma separate list to turn on debug switch for components')
ns = ap.parse_args()
log_setting = {
'level': ns.log_level,
'file': ns.log_file,
}
if ns.debug_switch == '':
debug = (
# stash._DEBUG_STREAM,
# stash._DEBUG_RENDERER,
# stash._DEBUG_MAIN_SCREEN,
# stash._DEBUG_MINI_BUFFER,
# stash._DEBUG_IO,
# stash._DEBUG_UI,
# stash._DEBUG_TERMINAL,
# stash._DEBUG_TV_DELEGATE,
# stash._DEBUG_RUNTIME,
# stash._DEBUG_PARSER,
# stash._DEBUG_EXPANDER,
# stash._DEBUG_COMPLETER,
)
else:
debug = []
for ds in ns.debug_switch.split(','):
ds = getattr(stash, '_DEBUG_{}'.format(ds.upper()), None)
if ds is not None:
debug.append(ds)
_stash = stash.StaSh(debug=debug, log_setting=log_setting,
no_cfgfile=ns.no_cfgfile, no_rcfile=ns.no_rcfile,
no_historyfile=ns.no_historyfile)
_stash.launch()