-
Notifications
You must be signed in to change notification settings - Fork 1
/
puck_monitor_service.py
65 lines (54 loc) · 1.84 KB
/
puck_monitor_service.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
from typing import Dict, Any
from utils.devices import create_dewar_class, Dewar
import argparse
import yaml
from pathlib import Path
from import_pucks import start_app
import traceback
def init_argparse() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
usage="%(prog)s [OPTION] [FILE]...",
description="Start the puck monitor service",
)
parser.add_argument(
"-v", "--version", action="version", version=f"{parser.prog} version 1.0.0"
)
parser.add_argument("config", help="yaml file containing the configuration")
return parser
def parse_config(config_path: Path):
with config_path.open("r") as f:
config = yaml.safe_load(f)
if not all(key in config['dewar'] for key in ["suffix", "sectors", "pucks"]):
return None
return config
def main():
parser = init_argparse()
args = parser.parse_args()
if not args.config:
print("Please include the yaml file containing the app configuration")
return
config_path = Path(args.config)
if not config_path.exists():
print(
f"Configuration file {config_path} does not exist, please provide a valid config path"
)
return
print("Starting script")
config: "dict[str, Any] | None" = parse_config(config_path)
if not config:
print("Error parsing config file, missing suffix, sector or pucks")
exit()
try:
Dewar = create_dewar_class(config)
dewar = Dewar(config['dewar']["suffix"],
name="dewar",
beamline_id=config["dewar"]["beamline"],
db_host=config["dewar"]["db_host"],
)
except Exception as e:
print(f"Exception: {e}")
print(traceback.print_exc())
while True:
pass
if __name__ == "__main__":
main()