-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.py
executable file
·76 lines (63 loc) · 2.39 KB
/
start.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
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
from r0b0.rigs.rig import Rig
from r0b0.utils import loaders
from r0b0.cables import msg_funcs
from r0b0.config import LOCALHOST, SERVER_PORT
from r0b0 import logging, \
gadgets as gadget_shelf
from functools import partial
import os, sys
import argparse
import ssl
# ssl._create_default_https_context = ssl._create_unverified_context
def create_gadget(gadget_name):
"""Create the gadget
"""
config = loaders.load_yaml(os.path.join(os.path.dirname(__file__), 'config','gadgets', f'{gadget_name}.yaml'))
gadget_cls = getattr(
gadget_shelf, config['type'], None)
assert gadget_cls is not None, f"Gadget type {config['type']} does not exist"
return gadget_cls(config)
def main(rig_config):
config = loaders.load_yaml(rig_config)
logging.warning(config)
rig = Rig(
hostname=config.get('hostname',LOCALHOST),
port=config.get('port',SERVER_PORT),
certfile=os.path.join(os.path.dirname(__file__), 'examples', 'csr.pem'),
keyfile=os.path.join(os.path.dirname(__file__), 'examples', 'key.pem'),
# TODO - get rid of this by adding to rig.add_gadget
# namespaces=[f'/{gadget}' for gadget in config['gadgets']],
)
# breakpoint()
# add gadgets
gadgets = {}
for gadget_name in config['gadgets']:
gadget_obj = create_gadget(gadget_name)
rig.add_gadget(gadget_obj)
gadgets.update({gadget_name:gadget_obj})
# connect cables
for cable in config.get('cables',[]):
rig.add_cable_func(**cable)
logging.debug('Powering rig')
rig.power_on()
return rig, gadgets
if __name__=="__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--logging',type=str,default='warning')
parser.add_argument('--config',type=str,default=None)
args = parser.parse_args()
logging.basicConfig(
encoding='utf-8',
level=getattr(logging,args.logging.upper())
)
rig_config = args.config if args.config is not None else sys.argv[1]
assert rig_config is not None, "No rig config provided, either as sys.argv[1] or with --config"
rig,gadgets = main(rig_config)
globals().update(**gadgets)
try:
if rig.is_pygame_rig:
rig.pygame_event_handler()
else:
breakpoint(header="Starting command-line interface, (Ctrl+D) to exit")
except KeyboardInterrupt:
rig.power_off('','')