-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqmsk-e2-client
executable file
·103 lines (80 loc) · 2.69 KB
/
qmsk-e2-client
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
97
98
99
100
101
102
103
#!/usr/bin/env python3
import argparse
import asyncio
import qmsk.cli
import qmsk.e2.client
import qmsk.e2.presets
import qmsk.net.tcp
import logging; log = logging.getLogger('qmsk-e2-client')
class Client:
def __init__(self, loop):
self.loop = loop
@asyncio.coroutine
def start (self, args):
try:
self.client = yield from qmsk.e2.client.apply(args)
except qmsk.net.tcp.Error as error:
log.error("%s: failed to connect: %s", args.e2_host, error)
return 1
self.presets = qmsk.e2.presets.apply(args)
if not self.presets.presets:
log.error("no presets given")
return 1
return 0
@asyncio.coroutine
def run (self, args):
if args.preset is not None:
try:
yield from self.client.PRESET_recall(args.preset)
except qmsk.e2.client.CommandError as error:
log.error("%s: PRESET_recall(%s): %s", self.client, args.preset, error)
return 1
if args.transition is not None:
try:
yield from self.client.ATRN(args.transition)
except qmsk.e2.client.CommandError as error:
log.error("%s: ATRN(%s): %s", self.client, args.transition, error)
return 1
return 0
def main (argv):
parser = qmsk.cli.parser()
qmsk.e2.client.parser(parser)
qmsk.e2.presets.parser(parser)
parser.add_argument('--preset', metavar='PRESET', type=int,
help="Recall preset")
parser.add_argument('--cut', dest='transition', action='store_const', const=0,
help="Cut transition")
parser.add_argument('--autotrans', dest='transition', action='store_true',
help="Auto transition")
parser.add_argument('--transition', dest='transition', metavar='FRAMES', type=int,
help="Timed transition")
# start
args = qmsk.cli.parse(parser, argv)
loop = asyncio.get_event_loop()
# start
client = Client(loop)
do_start = asyncio.async(client.start(args))
try:
log.info("start event loop")
out = loop.run_until_complete(do_start)
except Exception as error:
log.exception("Failed to start")
return 1
else:
if out:
return out
# run
do_start = asyncio.async(client.run(args))
try:
log.info("run event loop")
out = loop.run_until_complete(do_run)
except Exception as error:
log.exception("Failed to run")
return 1
else:
if out:
return out
log.info("exit")
return 0
if __name__ == '__main__':
qmsk.cli.main(main)