-
Notifications
You must be signed in to change notification settings - Fork 7
/
cas
executable file
·83 lines (69 loc) · 2.56 KB
/
cas
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
#!/usr/bin/env python3
import sys
import os
if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1] == "bash_complete":
from client.argparser import get_bash_complete
print(get_bash_complete())
exit(0)
cas_dir = os.path.dirname(os.path.realpath(__file__))
# this should bypas problems with execve of etrace_parser
if cas_dir not in os.environ["PATH"]:
os.environ["PATH"] = os.environ["PATH"] + f":{cas_dir}"
try:
import libetrace as _
except ModuleNotFoundError:
print("CAS libetrace not found - provide libetrace.so in directory or export directory with library to PYTHONPATH")
print("eg. export PYTHONPATH=/home/j.doe/CAS/:$PYTHONPATH")
sys.exit(2)
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE, SIG_DFL)
args = sys.argv[1:]
if "--proc-tree" in args or "--deps-tree" in args:
import webbrowser
import threading
try:
browser = webbrowser.get()
except webbrowser.Error:
print ("NO BROWSER")
from cas_server import app, translate_to_url
port = 8383
try:
port_idx = list(map(lambda x: x.startswith("--port"), args)).index(True)
port = int(args[port_idx].split('=')[1])
args.pop(port_idx)
except Exception:
pass
host = "0.0.0.0"
try:
host_idx = list(map(lambda x: x.startswith("--host"), args)).index(True)
host = args[host_idx].split('=')[1]
args.pop(host_idx)
except Exception:
pass
url_args = translate_to_url(args)
def browser_spawn():
browser.open(f"http://{host}:{port}/{url_args}", new=2)
threading.Thread(target=browser_spawn).start()
app.run(host, port)
else:
import os
from typing import Generator, Iterator
import libcas
from libft_db import FTDatabase
from client.cmdline import process_commandline
from client.exceptions import MessageException
cas_db = libcas.CASDatabase()
ft_db = FTDatabase()
try:
ret = process_commandline(cas_db, ft_db=ft_db)
if ret:
if isinstance(ret, Iterator):
print(*ret, sep=os.linesep)
elif isinstance(ret, Generator):
print(*ret, sep=os.linesep)
else:
print(ret, flush=True)
except MessageException as e :
print("ERROR: " + e.message)
sys.exit(2)