-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun.py
77 lines (59 loc) · 1.94 KB
/
run.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
77
"""
Entry point for the BlueBird app
"""
import argparse
from typing import Any
from typing import Dict
from dotenv import load_dotenv
from bluebird import BlueBird
from bluebird.settings import Settings
from bluebird.utils.properties import SimType
_ARG_BOOL_ACTION = "store_true"
def _parse_args() -> Dict[str, Any]:
"""Parse CLI arguments and override any default settings"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--sim-type",
type=SimType,
help=f"The type of simulator to connect to. Supported values are: "
f'{", ".join([x.name for x in SimType])}',
)
parser.add_argument(
"--sim-host", type=str, help="Hostname or IP of the simulator to connect to"
)
parser.add_argument(
"--reset-sim",
action=_ARG_BOOL_ACTION,
help="Resets the simulation on connection",
)
parser.add_argument("--log-rate", type=float, help="Log rate in sim-seconds")
# NOTE(RKM 2019-11-21) Disabled until we re-implement the free-run mode
# parser.add_argument(
# "--sim-mode",
# type=SimMode,
# help="Set the initial mode. Supported values are: "
# f'{", ".join([x.name for x in SimMode])}',
# )
args = parser.parse_args()
if args.sim_host:
Settings.SIM_HOST = args.sim_host
if args.log_rate:
if args.log_rate < 0:
raise ValueError("Rate must be positive")
Settings.SIM_LOG_RATE = args.log_rate
# if args.sim_mode:
# Settings.SIM_MODE = args.sim_mode
if args.sim_type:
Settings.SIM_TYPE = args.sim_type
return vars(args)
def main():
"""Main app entry point"""
args = _parse_args()
load_dotenv(verbose=True, override=True)
with BlueBird(args) as app:
app.pre_connection_setup()
if app.connect_to_sim():
# Runs the Flask app. Blocks here until it exits
app.run()
if __name__ == "__main__":
main()