This repository was archived by the owner on Jun 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathncoda_script
96 lines (80 loc) · 2.57 KB
/
ncoda_script
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
#!/usr/bin/env python2
"""
Run nCoda.
Copyright 2018 Christopher Antila
"""
import os.path
import subprocess
import time
APP_NAME = 'nCoda'
APP_RELEASE = '???'
FUJIAN_RELEASE = '???'
JULIUS_RELEASE = '???'
LYCHEE_RELEASE = '???'
# Number of seconds between checking whether Fujian or Julius has exited.
_POLL_TIMEOUT = 1
_STARTUP_TEXT = """\
{app_name} v{app_release} (Fujian {fjn_r}, Julius {jls_r}, Lychee {lyc_r})
Copyright 2015 to 2018, nCoda Contributors.
\tThis program comes with ABSOLUTELY NO WARRANTY. In addition,
\tnCoda is free software, and you are welcome to redistribute it
\tunder certain conditions. For more information, please refer
\tto the GNU General Public Licence 3.0, available on the Web:
\thttps://www.gnu.org/licenses/gpl-3.0.html
""".format(
app_name=APP_NAME,
app_release=APP_RELEASE,
fjn_r=FUJIAN_RELEASE,
jls_r=JULIUS_RELEASE,
lyc_r=LYCHEE_RELEASE,
)
_FUJIAN_PATH = './fujian.pex'
_JULIUS_PATH = './julius'
_PYTHON_PATH = 'python'
def main():
"""
Run nCoda.
"""
if not os.path.exists(_FUJIAN_PATH):
print('ERROR: Fujian is not at the expected path. Cannot start nCoda.')
raise SystemExit(1)
if os.path.exists(_JULIUS_PATH):
julius_command = [_JULIUS_PATH]
else:
print('To exit, type Ctrl + c\n')
julius_command = [_PYTHON_PATH, '-m', 'SimpleHTTPServer']
exit_code = 0
procs = []
try:
procs.append(subprocess.Popen([_FUJIAN_PATH]))
procs.append(subprocess.Popen(julius_command))
while True:
for proc in procs:
proc.poll()
if any([proc.returncode is not None for proc in procs]):
break
time.sleep(_POLL_TIMEOUT)
except Exception as exc:
print('ERROR: Unknown problem; description is below. Cannot start nCoda.')
print(str(exc))
exit_code += 1
finally:
for proc in procs:
try:
proc.terminate()
proc.wait()
if proc.returncode is None:
proc.kill()
except OSError as exc:
if 'No such process' not in str(exc):
print('ERROR: Problem while shutting down; description is below.')
print(str(exc))
exit_code += 1
except Exception as exc:
print('ERROR: Problem while shutting down; description is below.')
print(str(exc))
exit_code += 1
raise SystemExit(exit_code)
if __name__ == '__main__':
print(_STARTUP_TEXT)
main()