-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
42 lines (35 loc) · 1.22 KB
/
server.py
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
#!/usr/bin/env python2
import lib.pub
import argparse
import logging
import sys
import decimal
import time
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Headset server")
parser.add_argument("-b", action="store", type=str, default="tcp://127.0.0.1:1234", help="Bind to address")
parser.add_argument("-c", action="store", type=str, default="h", help="Publish to channel")
parser.add_argument('-r', dest='record', action='store_true', help="Read recording from stdin")
parser.add_argument('--nodebug', dest='debug', action='store_false')
args = parser.parse_args()
if args.debug:
logging.basicConfig(level=logging.DEBUG)
if args.record:
last = None
server = lib.pub.Publisher(**{
"bind": args.b,
"chan": args.c
})
for line in sys.stdin:
tstamp, line = line.rstrip("\n").split(":", 1)
tstamp = float(decimal.Decimal(tstamp))
if last is not None:
time.sleep(tstamp-last)
server.put(line)
last = tstamp
else:
server = lib.pub.HeadsetRelay(**{
"bind": args.b,
"chan": args.c
})
server.run()