Repository navigation
Expand file tree
/
Copy path__main__.py
More file actions
127 lines (113 loc) · 3.35 KB
/
Copy path__main__.py
File metadata and controls
127 lines (113 loc) · 3.35 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""
Launch StaSh in a more flexible and reliable way.
"""
import argparse
import sys
# fix from https://github.com/ywangd/stash/pull/499
if hasattr(sys, "_exit"):
sys.exit = sys._exit
module_names = (
"stash",
"system.shcommon",
"system.shstreams",
"system.shscreens",
"system.shui",
"system.shui.base",
"system.shio",
"system.shiowrapper",
"system.shparsers",
"system.shruntime",
"system.shthreads",
"system.shuseractionproxy",
"system.shhistory",
)
# 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",
)
ap.add_argument("-c", "--command", default=None, dest="command", help="command to run")
ap.add_argument(
"args", # the editor shortcuts may pass additional arguments
nargs="*",
help="additional arguments (ignored)",
)
def main():
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,
)
elif ns.debug_switch == "all":
debug = []
for key in dir(stash):
if key.startswith("_DEBUG_"):
value = getattr(stash, key, None)
if value is not None:
debug.append(value)
else:
debug = []
for ds in ns.debug_switch.split(","):
ds = getattr(stash, f"_DEBUG_{ds.upper()}", None)
if ds is not None:
debug.append(ds)
if ns.command:
# tell StaSh not to run any command if command is passed
# (we will call the command manually later)
ctp = False
else:
# tell StaSh to run the default command (totd.py)
ctp = None
_stash = stash.StaSh(
debug=debug,
log_setting=log_setting,
no_cfgfile=ns.no_cfgfile,
no_rcfile=ns.no_rcfile,
no_historyfile=ns.no_historyfile,
command=ctp,
)
_stash.launch(ns.command)
if ns.command is not None:
# TODO: _stash.launch() may block, which prevents this from being executed
_stash(ns.command, add_to_history=False, persistent_level=0)
if __name__ == "__main__":
main()