-
Notifications
You must be signed in to change notification settings - Fork 0
/
nutaq
executable file
·59 lines (52 loc) · 2 KB
/
nutaq
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
#!/usr/bin/env python
from NuPost import NuPost
import sys, time
import socket
import os
def main(host, port):
post = NuPost(host, port)
cmd = sys.argv[1]
if cmd == "start":
comment = sys.argv[2] if len(sys.argv) == 3 else ""
post.go("Run", comment)
elif cmd == "stop":
comment = sys.argv[2] if len(sys.argv) == 3 else ""
post.stop(comment)
elif cmd == "setrun":
post.set_run_num(int(sys.argv[2]))
elif cmd == "status":
post.status()
elif cmd == "monitor":
while 1:
rate = post.get_tape_rate()
sys.stdout.write("%d kB (%d blocks)\r" % (rate['kbytes'], rate['block']))
sys.stdout.flush()
time.sleep(1)
elif cmd == "help":
print "\n\t Commands for controlling NUTAQ: \n"
print "\t start \"comment\" \t -> starts a file named Run_X. The \"comment\" is optional."
print "\t stop \"comment\" \t -> stops the file, increments X"
print "\t status \t\t -> displays the running/stopped status"
print "\t monitor \t\t -> shows the current file size in realtime"
print "\t setrun X \t\t -> changes the run number to X"
print "\t The start and stop times of the runs and optional comments are displayed in the 'nutaq.log' file"
print "\n"
else:
print "Unknown command: %s" % cmd
if __name__ == "__main__":
# If we run on pcids03 then we do not need to make a tunnel
if socket.gethostname().startswith("pcids03"):
main("nnids1", 8015)
else:
from sshtunnel import SSHTunnelForwarder
password = os.environ.get('NUTAQ_PASS')
if password is None:
print "Missing password for pcids03"
exit(1)
with SSHTunnelForwarder(
('pcids03', 22),
ssh_username="upcids03",
ssh_password=password,
remote_bind_address=('nnids1', 8015)
) as server:
main("localhost", server.local_bind_port)