-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent.py
More file actions
71 lines (62 loc) · 1.9 KB
/
component.py
File metadata and controls
71 lines (62 loc) · 1.9 KB
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
import json
class Component(object):
def __init__(self, path, name, logger):
self.cfg = self._getConfigFromFile(path, name)
# Assemble logger.
#
if logger is None:
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter("(" + str(os.getpid()) + \
") %(asctime)s:%(levelname)s: %(message)s")
ch.setFormatter(formatter)
logger.addHandler(ch)
self.logger = logger
def _getConfigFromFile(self, path, name):
'''
Return config with name [name] from a JSON file at path [path].
'''
with open(path) as fp:
cfg = json.load(fp)
config = None
for c in cfg:
if c['name'] == name:
config = c
break;
else:
continue
return config
class Preoptics(Component):
def __init__(self, path, name, logger):
super(Preoptics, self).__init__(path, name, logger)
try:
assert self.cfg is not None
except AssertionError:
logger.critical("Pre-optics config not found.")
exit(0)
class IFU(Component):
def __init__(self, path, name, logger):
super(IFU, self).__init__(path, name, logger)
try:
assert self.cfg is not None
except AssertionError:
logger.critical("IFU config not found.")
exit(0)
class Spectrograph(Component):
def __init__(self, path, name, logger):
super(Spectrograph, self).__init__(path, name, logger)
try:
assert self.cfg is not None
except AssertionError:
logger.critical("Spectrograph config not found.")
exit(0)
class Detector(Component):
def __init__(self, path, name, logger):
super(Detector, self).__init__(path, name, logger)
try:
assert self.cfg is not None
except AssertionError:
logger.critical("Detector config not found.")
exit(0)