forked from sagemath/cloud
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatus
executable file
·51 lines (39 loc) · 1.17 KB
/
status
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
#!/usr/bin/env python
import json, os, sys
SMC = os.path.join(os.environ['HOME'], '.sagemathcloud/')
os.chdir(SMC)
status = {}
def done():
print json.dumps(status)
sys.exit(0)
def set(prop, val):
status[prop] = val
if val is False:
done()
def read(prop, filename, strip=False):
try:
s = open(filename).read()
if strip:
s = s.strip()
status[prop] = s
except:
status[prop] = False
done()
read('version', os.path.join(SMC, "version"), strip=True)
# a simple test that the node modules are probably installed.
set('installed', os.path.exists(os.path.join(SMC, 'installed')))
for name in ['secret_token', 'local_hub.port']:
read(name, os.path.join(SMC, 'data', name))
## set('disk_usage', int(os.popen('du -s "%s"'%project_path).read().split()[0]))
for daemon in ['local_hub', 'sage_server', 'console_server']:
pidfile = os.path.join(SMC, 'data', daemon) + '.pid'
if os.path.exists(pidfile):
try:
pid = int(open(pidfile).read())
os.kill(pid, 0)
set(daemon, pid)
except:
set(daemon, False)
else:
set(daemon, False)
done()