Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/smc_pyutil/smc_pyutil/start_smc.py
Views: 285
1
#!/usr/bin/python
2
from __future__ import print_function, absolute_import
3
4
import os, sys, time
5
6
if not 'SMC' in os.environ:
7
os.environ['SMC'] = os.path.join(os.environ['HOME'], '.smc')
8
9
SMC = os.environ['SMC']
10
if not os.path.exists(SMC):
11
os.makedirs(SMC)
12
13
# ensure that PATH starts with ~/bin, so user can customize what gets run
14
os.environ['PATH'] = "%s:%s" % (os.path.join(os.environ['HOME'],
15
'bin'), os.environ['PATH'])
16
17
18
def cmd(s):
19
print(s)
20
if os.system(s):
21
sys.exit(1)
22
23
24
def started():
25
return os.path.exists("%s/local_hub/local_hub.port" % SMC)
26
27
28
def main():
29
# concatenate all additional arguments and pass them to the node.js server
30
port_args = ' '.join(sys.argv[2:])
31
32
# Start local hub server
33
cmd("smc-local-hub start " + port_args)
34
35
i = 0
36
while not started():
37
time.sleep(0.1)
38
i += 1
39
print(i, end=" ")
40
sys.stdout.flush()
41
if i >= 100:
42
sys.exit(1)
43
44
45
if __name__ == "__main__":
46
main()
47
48