cgse-common 2023.1.4__py3-none-any.whl → 2024.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cgse_common-2023.1.4.dist-info → cgse_common-2024.1.4.dist-info}/METADATA +28 -25
- cgse_common-2024.1.4.dist-info/RECORD +36 -0
- {cgse_common-2023.1.4.dist-info → cgse_common-2024.1.4.dist-info}/WHEEL +1 -1
- cgse_common-2024.1.4.dist-info/entry_points.txt +2 -0
- egse/bits.py +266 -41
- egse/calibration.py +250 -0
- egse/command.py +10 -29
- egse/config.py +17 -12
- egse/control.py +0 -81
- egse/decorators.py +8 -8
- egse/device.py +3 -1
- egse/env.py +411 -106
- egse/hk.py +794 -0
- egse/metrics.py +106 -0
- egse/monitoring.py +1 -0
- egse/resource.py +70 -2
- egse/response.py +101 -0
- egse/settings.py +33 -31
- egse/settings.yaml +0 -973
- egse/setup.py +116 -81
- egse/system.py +33 -14
- cgse_common-2023.1.4.dist-info/RECORD +0 -32
- cgse_common-2023.1.4.dist-info/entry_points.txt +0 -3
egse/env.py
CHANGED
|
@@ -1,139 +1,440 @@
|
|
|
1
1
|
"""
|
|
2
|
-
This module provides functionality to work with and check your
|
|
3
|
-
"""
|
|
4
|
-
from pathlib import Path
|
|
2
|
+
This module provides functionality to work with and check your environment variables.
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
from
|
|
4
|
+
The module provides functions to get/set the location of the data storage, the configuration data, and the log files.
|
|
5
|
+
The locations are determined from the environment variables that are set for the project.
|
|
6
|
+
|
|
7
|
+
Two important and mandatory environment variables are PROJECT and SITE_ID. The PROJECT environment variable is
|
|
8
|
+
used to construct the names of the other environment variables that are specific to the project. The SITE_ID
|
|
9
|
+
environment variable is used in the value that is returned for some the of project specific environment variables.
|
|
10
|
+
|
|
11
|
+
Mandatory environment variables:
|
|
12
|
+
|
|
13
|
+
- PROJECT: the name of the project, e.g. PLATO, ARIEL. [shall be UPPER case]
|
|
14
|
+
- SITE_ID: the site identifier, e.g. the lab name or organisation acronym. [shall be UPPER case]
|
|
15
|
+
|
|
16
|
+
The following environment variables are used by the project:
|
|
17
|
+
|
|
18
|
+
- <PROJECT>_DATA_STORAGE_LOCATION: the root of the data storage location.
|
|
19
|
+
- <PROJECT>_CONF_DATA_LOCATION: the location of the configuration data.
|
|
20
|
+
- <PROJECT>_CONF_REPO_LOCATION: the location of the configuration data GitHub repository.
|
|
21
|
+
- <PROJECT>_LOG_FILE_LOCATION: the location of the log files.
|
|
22
|
+
- <PROJECT>_LOCAL_SETTINGS: the YAML file that contains site specific local settings.
|
|
23
|
+
|
|
24
|
+
Do not use the environment variables directly, but use the functions provided by this module to get the locations.
|
|
8
25
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
ENV_PLATO_LOG_DATA = "PLATO_LOG_FILE_LOCATION"
|
|
15
|
-
ENV_PLATO_LOCAL_SETTINGS = "PLATO_LOCAL_SETTINGS"
|
|
26
|
+
- get_data_storage_location(): returns the full path of the data storage location.
|
|
27
|
+
- get_conf_data_location(): returns the full path of the location of the configuration data.
|
|
28
|
+
- get_conf_repo_location(): returns the full path of the location of the configuration data repository.
|
|
29
|
+
- get_log_file_location(): returns the full path of the location of the log files.
|
|
30
|
+
- get_local_settings(): returns the fully qualified filename of the local settings YAML file.
|
|
16
31
|
|
|
17
|
-
|
|
32
|
+
WARNING:
|
|
33
|
+
|
|
34
|
+
These environment variables shall not be changed outside the processes that use them and also not using the
|
|
35
|
+
`os.environ` within the code. For the known environment variables, use the dedicated 'setters' that are provided
|
|
36
|
+
by this module. If there is a need to change the environment variables, e.g. in unit tests, make sure to call the
|
|
37
|
+
`egse.env.initialize()` to reset the proper state.
|
|
38
|
+
|
|
39
|
+
"""
|
|
40
|
+
from __future__ import annotations
|
|
18
41
|
|
|
19
42
|
__all__ = [
|
|
20
43
|
"get_data_storage_location",
|
|
44
|
+
"set_data_storage_location",
|
|
45
|
+
"get_data_storage_location_env_name",
|
|
21
46
|
"get_conf_data_location",
|
|
47
|
+
"set_conf_data_location",
|
|
48
|
+
"get_conf_data_location_env_name",
|
|
49
|
+
"get_conf_repo_location",
|
|
50
|
+
"set_conf_repo_location",
|
|
51
|
+
"get_conf_repo_location_env_name",
|
|
22
52
|
"get_log_file_location",
|
|
23
|
-
|
|
53
|
+
"set_log_file_location",
|
|
54
|
+
"get_log_file_location_env_name",
|
|
55
|
+
"get_local_settings",
|
|
56
|
+
"set_local_settings",
|
|
57
|
+
"get_local_settings_env_name",
|
|
24
58
|
]
|
|
25
59
|
|
|
60
|
+
import os
|
|
61
|
+
import warnings
|
|
62
|
+
from pathlib import Path
|
|
63
|
+
|
|
64
|
+
from egse.system import all_logging_disabled
|
|
65
|
+
from egse.system import ignore_m_warning
|
|
66
|
+
|
|
67
|
+
# Every project shall have a PROJECT and a SITE_ID environment variable set. This variable will be used to
|
|
68
|
+
# create the other environment variables that are specific to the project.
|
|
69
|
+
|
|
70
|
+
MANDATORY_ENVIRONMENT_VARIABLES = [
|
|
71
|
+
"PROJECT",
|
|
72
|
+
"SITE_ID",
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
# The environment variables that are known to be used by the project. These environment variables shall be set
|
|
76
|
+
# as ${PROJECT}_<variable name>, e.g. PLATO_DATA_STORAGE_LOCATION. For each of these variables, there is a
|
|
77
|
+
# corresponding function that will return the value of the environment variable. The environment variable is not
|
|
78
|
+
# mandatory and if not set, a LookupError will be raised.
|
|
79
|
+
|
|
80
|
+
KNOWN_PROJECT_ENVIRONMENT_VARIABLES = [
|
|
81
|
+
"DATA_STORAGE_LOCATION",
|
|
82
|
+
"CONF_DATA_LOCATION",
|
|
83
|
+
"CONF_REPO_LOCATION",
|
|
84
|
+
"LOG_FILE_LOCATION",
|
|
85
|
+
"LOCAL_SETTINGS",
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def initialize():
|
|
90
|
+
"""
|
|
91
|
+
Initialize the environment variables that are required for the CGSE to function properly.
|
|
92
|
+
This function will print a warning if any of the mandatory environment variables is not set.
|
|
93
|
+
|
|
94
|
+
This function is automatically called on import and can be called whenever the environment
|
|
95
|
+
variables have been changed, e.g. in unit tests.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
global _env
|
|
99
|
+
|
|
100
|
+
for name in MANDATORY_ENVIRONMENT_VARIABLES:
|
|
101
|
+
try:
|
|
102
|
+
_env.set(name, os.environ[name])
|
|
103
|
+
except KeyError:
|
|
104
|
+
warnings.warn(
|
|
105
|
+
f"The environment variable {name} is not set. {name} is required to define the project settings and "
|
|
106
|
+
f"environment variables. Please set the environment variable {name} before proceeding."
|
|
107
|
+
)
|
|
108
|
+
_env.set(name, NoValue())
|
|
109
|
+
|
|
110
|
+
project = _env.get("PROJECT")
|
|
111
|
+
|
|
112
|
+
for gen_var_name in KNOWN_PROJECT_ENVIRONMENT_VARIABLES:
|
|
113
|
+
env_var = f"{project}_{gen_var_name}"
|
|
114
|
+
_env.set(gen_var_name, os.environ.get(env_var, NoValue()))
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class _Env:
|
|
118
|
+
"""Internal class that keeps track of the environment variables."""
|
|
119
|
+
|
|
120
|
+
def __init__(self):
|
|
121
|
+
self._env = {}
|
|
122
|
+
|
|
123
|
+
def set(self, key, value):
|
|
124
|
+
self._env[key] = value
|
|
26
125
|
|
|
27
|
-
def
|
|
126
|
+
def get(self, key) -> str:
|
|
127
|
+
return self._env.get(key, NoValue())
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
_env = _Env()
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class NoValue:
|
|
134
|
+
"""
|
|
135
|
+
Represents a no value object, an environment variable that was not set.
|
|
136
|
+
|
|
137
|
+
The truth value of this object is always False, and it is equal to any other NoValue object.
|
|
28
138
|
"""
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
139
|
+
|
|
140
|
+
def __eq__(self, other):
|
|
141
|
+
if isinstance(other, NoValue):
|
|
142
|
+
return True
|
|
143
|
+
return False
|
|
144
|
+
|
|
145
|
+
def __bool__(self):
|
|
146
|
+
return False
|
|
147
|
+
|
|
148
|
+
def __repr__(self):
|
|
149
|
+
return f"{self.__class__.__name__}"
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
# The module needs to be initialized before it can be used.
|
|
153
|
+
initialize()
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _check_no_value(var_name, value):
|
|
157
|
+
"""Raise a ValueError when the value for the variable is NoValue."""
|
|
158
|
+
if value == NoValue():
|
|
159
|
+
project = _env.get("PROJECT")
|
|
160
|
+
env_name = var_name if var_name == "SITE_ID" else f"{project}_{var_name}"
|
|
161
|
+
raise ValueError(
|
|
162
|
+
f"The environment variable {env_name} is not set. "
|
|
163
|
+
f"Please set the environment variable before proceeding."
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def get_data_storage_location_env_name() -> str:
|
|
168
|
+
"""Returns the name of the environment variable for the project."""
|
|
169
|
+
project = _env.get("PROJECT")
|
|
170
|
+
return f"{project}_DATA_STORAGE_LOCATION"
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def set_data_storage_location(location: str | Path):
|
|
174
|
+
"""
|
|
175
|
+
Sets the environment variable and the internal representation to the given value.
|
|
176
|
+
|
|
177
|
+
Warnings:
|
|
178
|
+
Issues a warning when the given location doesn't exist.
|
|
179
|
+
"""
|
|
180
|
+
env_name = get_data_storage_location_env_name()
|
|
181
|
+
|
|
182
|
+
# Check if location exists and is readable
|
|
183
|
+
if not Path(location).exists():
|
|
184
|
+
warnings.warn(
|
|
185
|
+
f"The location you provided for the environment variable {env_name} doesn't exist: {location}."
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
os.environ[env_name] = location
|
|
189
|
+
_env.set('DATA_STORAGE_LOCATION', location)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def get_data_storage_location(site_id: str = None) -> str:
|
|
193
|
+
"""
|
|
194
|
+
Returns the full path of the data storage location for the given site_id.
|
|
195
|
+
|
|
196
|
+
If the site_id is None, it is determined from the environment variable SITE_ID.
|
|
197
|
+
|
|
198
|
+
If the ${PROJECT}_DATA_STORAGE_LOCATION environment variable does not end with
|
|
199
|
+
the site_id, the site_id will be appended to the path on return. That means
|
|
200
|
+
the actual data storage location will always be site specific.
|
|
32
201
|
|
|
33
202
|
Note: when you specify the `site_id` as an argument, it takes precedence
|
|
34
|
-
over the
|
|
203
|
+
over the SITE_ID environment variable.
|
|
35
204
|
|
|
36
205
|
Args:
|
|
37
|
-
|
|
38
|
-
site_id: the site identifier (to be used instead of the site_id in the Setup)
|
|
206
|
+
site_id: the site identifier (to be used instead of the SITE_ID environment variable)
|
|
39
207
|
|
|
40
208
|
Returns:
|
|
41
209
|
The full path of data storage location as a string.
|
|
42
210
|
|
|
43
211
|
Raises:
|
|
44
|
-
A ValueError when
|
|
212
|
+
A ValueError when the SITE_ID or the ${PROJECT}_DATA_STORAGE_LOCATION is not set.
|
|
45
213
|
"""
|
|
214
|
+
global _env
|
|
215
|
+
|
|
216
|
+
site_id = site_id or _env.get("SITE_ID")
|
|
217
|
+
_check_no_value("SITE_ID", site_id)
|
|
46
218
|
|
|
47
|
-
|
|
219
|
+
data_root = _env.get("DATA_STORAGE_LOCATION")
|
|
220
|
+
_check_no_value("DATA_STORAGE_LOCATION", data_root)
|
|
48
221
|
|
|
49
|
-
|
|
222
|
+
data_root = data_root.rstrip('/')
|
|
50
223
|
|
|
51
|
-
|
|
224
|
+
return data_root if data_root.endswith(site_id) else f"{data_root}/{site_id}"
|
|
52
225
|
|
|
53
|
-
if site_id is None:
|
|
54
226
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
227
|
+
def get_conf_data_location_env_name() -> str:
|
|
228
|
+
"""Returns the name of the environment variable for the project."""
|
|
229
|
+
project = _env.get("PROJECT")
|
|
230
|
+
return f"{project}_CONF_DATA_LOCATION"
|
|
58
231
|
|
|
59
|
-
if setup is None:
|
|
60
|
-
raise ValueError(
|
|
61
|
-
"Could not determine Setup, which is None, even after loading from the configuration manager."
|
|
62
|
-
)
|
|
63
232
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
233
|
+
def set_conf_data_location(location: str | Path):
|
|
234
|
+
"""
|
|
235
|
+
Sets the environment variable and the internal representation to the given value.
|
|
67
236
|
|
|
68
|
-
|
|
69
|
-
|
|
237
|
+
Warnings:
|
|
238
|
+
Issues a warning when the given location doesn't exist.
|
|
239
|
+
"""
|
|
240
|
+
|
|
241
|
+
env_name = get_conf_data_location_env_name()
|
|
70
242
|
|
|
71
|
-
|
|
243
|
+
# Check if location exists and is readable
|
|
244
|
+
if not Path(location).exists():
|
|
245
|
+
warnings.warn(
|
|
246
|
+
f"The location you provided for the environment variable {env_name} doesn't exist: {location}."
|
|
247
|
+
)
|
|
72
248
|
|
|
249
|
+
os.environ[env_name] = location
|
|
250
|
+
_env.set('CONF_DATA_LOCATION', location)
|
|
73
251
|
|
|
74
|
-
|
|
252
|
+
|
|
253
|
+
def get_conf_data_location(site_id: str = None) -> str:
|
|
75
254
|
"""
|
|
76
|
-
Returns the full path of the location of the
|
|
77
|
-
|
|
255
|
+
Returns the full path of the location of the configuration data for the Site.
|
|
256
|
+
|
|
257
|
+
If the site_id is None, it is determined from the environment variable SITE_ID.
|
|
258
|
+
|
|
259
|
+
When the ${PROJECT}_CONF_DATA_LOCATION environment variable is not set, the configuration data
|
|
260
|
+
location will be the ${PROJECT}_DATA_STORAGE_LOCATION + '/conf'.
|
|
78
261
|
|
|
79
262
|
Args:
|
|
80
|
-
|
|
263
|
+
site_id: the site identifier (to be used instead of the SITE_ID environment variable)
|
|
81
264
|
|
|
82
265
|
Returns:
|
|
83
|
-
The full path of location of the
|
|
266
|
+
The full path of location of the configuration data as a string.
|
|
84
267
|
|
|
85
268
|
Raises:
|
|
86
|
-
A ValueError when
|
|
269
|
+
A ValueError when the SITE_ID or the ${PROJECT}_DATA_STORAGE_LOCATION is not set.
|
|
87
270
|
"""
|
|
88
271
|
|
|
89
|
-
|
|
272
|
+
conf_data_root = _env.get("CONF_DATA_LOCATION")
|
|
273
|
+
|
|
274
|
+
if not conf_data_root:
|
|
275
|
+
try:
|
|
276
|
+
data_root = get_data_storage_location(site_id=site_id)
|
|
277
|
+
except ValueError:
|
|
278
|
+
raise ValueError(
|
|
279
|
+
f"Could not determine the location of the configuration files. "
|
|
280
|
+
f"The environment variable {get_conf_data_location_env_name()} is not set and also the "
|
|
281
|
+
f"data storage location is unknown."
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
data_root = data_root.rstrip('/')
|
|
285
|
+
conf_data_root = f"{data_root}/conf"
|
|
286
|
+
|
|
287
|
+
return conf_data_root
|
|
90
288
|
|
|
91
|
-
return f"{data_root}/conf"
|
|
92
289
|
|
|
290
|
+
def get_log_file_location_env_name():
|
|
291
|
+
"""Returns the name of the environment variable for the project."""
|
|
292
|
+
project = _env.get("PROJECT")
|
|
293
|
+
return f"{project}_LOG_FILE_LOCATION"
|
|
93
294
|
|
|
94
|
-
|
|
295
|
+
|
|
296
|
+
def set_log_file_location(location: str | Path):
|
|
297
|
+
"""
|
|
298
|
+
Sets the environment variable and the internal representation to the given value.
|
|
299
|
+
|
|
300
|
+
Warnings:
|
|
301
|
+
Issues a warning when the given location doesn't exist.
|
|
302
|
+
"""
|
|
303
|
+
|
|
304
|
+
env_name = get_log_file_location_env_name()
|
|
305
|
+
|
|
306
|
+
# Check if location exists and is readable
|
|
307
|
+
if not Path(location).exists():
|
|
308
|
+
warnings.warn(
|
|
309
|
+
f"The location you provided for the environment variable {env_name} doesn't exist: {location}."
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
os.environ[env_name] = location
|
|
313
|
+
_env.set('LOG_FILE_LOCATION', location)
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def get_log_file_location(site_id: str = None) -> str:
|
|
95
317
|
"""
|
|
96
318
|
Returns the full path of the location of the log files. The log file location is read from the environment
|
|
97
|
-
variable
|
|
98
|
-
setting that is subject to change.
|
|
319
|
+
variable ${PROJECT}_LOG_FILE_LOCATION. The location shall be independent of any setting that is subject to change.
|
|
99
320
|
|
|
100
321
|
If the environment variable is not set, a default log file location is created from the data storage location as
|
|
101
|
-
follows:
|
|
322
|
+
follows: <PROJECT>_DATA_STORAGE_LOCATION/<SITE_ID>/log.
|
|
323
|
+
|
|
324
|
+
Args:
|
|
325
|
+
site_id: the site identifier
|
|
102
326
|
|
|
103
327
|
Returns:
|
|
104
328
|
The full path of location of the log files as a string.
|
|
105
|
-
"""
|
|
106
329
|
|
|
107
|
-
|
|
108
|
-
|
|
330
|
+
Raises:
|
|
331
|
+
A ValueError when the SITE_ID or the ${PROJECT}_DATA_STORAGE_LOCATION is not set.
|
|
109
332
|
|
|
110
|
-
|
|
333
|
+
"""
|
|
111
334
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
335
|
+
log_data_root = _env.get("LOG_FILE_LOCATION")
|
|
336
|
+
|
|
337
|
+
if not log_data_root:
|
|
338
|
+
try:
|
|
339
|
+
data_root = get_data_storage_location(site_id=site_id)
|
|
340
|
+
except ValueError:
|
|
341
|
+
raise ValueError(
|
|
342
|
+
f"Could not determine the location of the log files. "
|
|
343
|
+
f"The environment variable {get_log_file_location_env_name()} is not set and also the "
|
|
344
|
+
f"data storage location is unknown."
|
|
345
|
+
)
|
|
116
346
|
data_root = data_root.rstrip('/')
|
|
347
|
+
log_data_root = f"{data_root}/log"
|
|
117
348
|
|
|
118
|
-
|
|
119
|
-
site = get_site_id()
|
|
349
|
+
return log_data_root
|
|
120
350
|
|
|
121
|
-
log_data_root = f"{data_root}/{site}/log"
|
|
122
351
|
|
|
123
|
-
|
|
352
|
+
def get_local_settings_env_name() -> str:
|
|
353
|
+
"""Returns the name of the environment variable for the project."""
|
|
354
|
+
project = _env.get("PROJECT")
|
|
355
|
+
return f"{project}_LOCAL_SETTINGS"
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def set_local_settings(path: str | Path):
|
|
359
|
+
"""
|
|
360
|
+
Sets the environment variable and the internal representation to the given value.
|
|
361
|
+
|
|
362
|
+
Warnings:
|
|
363
|
+
Issues a warning when the given path doesn't exist.
|
|
364
|
+
"""
|
|
365
|
+
|
|
366
|
+
env_name = get_local_settings_env_name()
|
|
367
|
+
|
|
368
|
+
# Check if location exists and is readable
|
|
369
|
+
if not Path(path).exists():
|
|
370
|
+
warnings.warn(
|
|
371
|
+
f"The location you provided for the environment variable {env_name} doesn't exist: {path}."
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
os.environ[env_name] = path
|
|
375
|
+
_env.set('LOCAL_SETTINGS', path)
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def get_local_settings() -> str:
|
|
379
|
+
"""Returns the fully qualified filename of the local settings YAML file."""
|
|
380
|
+
|
|
381
|
+
local_settings = _env.get("LOCAL_SETTINGS")
|
|
382
|
+
|
|
383
|
+
if local_settings and not Path(local_settings).exists():
|
|
384
|
+
warnings.warn(
|
|
385
|
+
f"The local settings '{local_settings}' doesn't exist. As a result, "
|
|
386
|
+
f"the local settings for your project will not be loaded."
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
return local_settings or None
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def get_conf_repo_location_env_name() -> str:
|
|
393
|
+
"""Returns the name of the environment variable for the project."""
|
|
394
|
+
project = _env.get("PROJECT")
|
|
395
|
+
return f"{project}_CONF_REPO_LOCATION"
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
def get_conf_repo_location() -> str:
|
|
399
|
+
"""Returns the fully qualified name of the location of the repository with configuration and calibration data."""
|
|
400
|
+
|
|
401
|
+
location = _env.get("CONF_REPO_LOCATION")
|
|
402
|
+
|
|
403
|
+
if location and not Path(location).exists():
|
|
404
|
+
warnings.warn(f"The location of the configuration data repository doesn't exist: {location}.")
|
|
405
|
+
|
|
406
|
+
return location or None
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def set_conf_repo_location(location: str):
|
|
410
|
+
"""
|
|
411
|
+
Sets the environment variable and the internal representation to the given value.
|
|
412
|
+
|
|
413
|
+
Warnings:
|
|
414
|
+
Issues a warning when the given location doesn't exist.
|
|
415
|
+
"""
|
|
416
|
+
|
|
417
|
+
env_name = get_conf_repo_location_env_name()
|
|
418
|
+
|
|
419
|
+
# Check if location exists and is readable
|
|
420
|
+
if not Path(location).exists():
|
|
421
|
+
warnings.warn(
|
|
422
|
+
f"The location you provided for the environment variable {env_name} doesn't exist: {location}."
|
|
423
|
+
)
|
|
424
|
+
|
|
425
|
+
os.environ[env_name] = location
|
|
426
|
+
_env.set('CONF_REPO_LOCATION', location)
|
|
124
427
|
|
|
125
428
|
|
|
126
429
|
ignore_m_warning('egse.env')
|
|
127
430
|
|
|
128
|
-
|
|
431
|
+
|
|
432
|
+
def main(args: list | None = None): # pragma: no cover
|
|
129
433
|
|
|
130
434
|
import argparse
|
|
131
|
-
import os
|
|
132
435
|
import sys
|
|
133
436
|
import rich
|
|
134
437
|
|
|
135
|
-
from egse.config import get_common_egse_root
|
|
136
|
-
|
|
137
438
|
parser = argparse.ArgumentParser()
|
|
138
439
|
parser.add_argument(
|
|
139
440
|
"--full",
|
|
@@ -148,13 +449,13 @@ if __name__ == "__main__":
|
|
|
148
449
|
help="Print help on the environment variables and paths.",
|
|
149
450
|
)
|
|
150
451
|
|
|
151
|
-
args = parser.parse_args()
|
|
452
|
+
args = parser.parse_args(args or [])
|
|
152
453
|
|
|
153
454
|
def check_env_dir(env_var: str):
|
|
154
455
|
|
|
155
|
-
value =
|
|
456
|
+
value = _env.get(env_var)
|
|
156
457
|
|
|
157
|
-
if value
|
|
458
|
+
if value == NoValue():
|
|
158
459
|
value = "[bold red]not set"
|
|
159
460
|
elif not value.startswith('/'):
|
|
160
461
|
value = f"[default]{value} [bold orange3](this is a relative path!)"
|
|
@@ -166,12 +467,11 @@ if __name__ == "__main__":
|
|
|
166
467
|
value = f"[default]{value}"
|
|
167
468
|
return value
|
|
168
469
|
|
|
169
|
-
|
|
170
470
|
def check_env_file(env_var: str):
|
|
171
471
|
|
|
172
|
-
value =
|
|
472
|
+
value = _env.get(env_var)
|
|
173
473
|
|
|
174
|
-
if value
|
|
474
|
+
if not value:
|
|
175
475
|
value = "[bold red]not set"
|
|
176
476
|
elif not os.path.exists(value):
|
|
177
477
|
value = f"[default]{value} [bold red](location doesn't exist!)"
|
|
@@ -181,24 +481,21 @@ if __name__ == "__main__":
|
|
|
181
481
|
|
|
182
482
|
rich.print("Environment variables:")
|
|
183
483
|
|
|
184
|
-
|
|
484
|
+
project = _env.get("PROJECT")
|
|
485
|
+
|
|
486
|
+
for var in MANDATORY_ENVIRONMENT_VARIABLES:
|
|
487
|
+
rich.print(f" {var} = {_env.get(var)}")
|
|
488
|
+
for var in KNOWN_PROJECT_ENVIRONMENT_VARIABLES:
|
|
185
489
|
if var.endswith("_SETTINGS"):
|
|
186
|
-
rich.print(f" {var} = {check_env_file(var)}")
|
|
490
|
+
rich.print(f" {project}_{var} = {check_env_file(var)}")
|
|
187
491
|
else:
|
|
188
|
-
rich.print(f" {var} = {check_env_dir(var)}")
|
|
492
|
+
rich.print(f" {project}_{var} = {check_env_dir(var)}")
|
|
189
493
|
|
|
190
494
|
rich.print()
|
|
191
495
|
rich.print("Generated locations and filenames")
|
|
192
496
|
|
|
193
497
|
with all_logging_disabled():
|
|
194
|
-
|
|
195
|
-
rich.print(f" {get_common_egse_root() = !s}", flush=True)
|
|
196
|
-
location = get_common_egse_root()
|
|
197
|
-
if not Path(location).exists():
|
|
198
|
-
rich.print("[red]ERROR: The generated Common-EGSE location doesn't exist![/]")
|
|
199
|
-
except ValueError as exc:
|
|
200
|
-
rich.print(f" get_common_egse_path() = [red]{exc}[/]")
|
|
201
|
-
|
|
498
|
+
warnings.filterwarnings("ignore", category=UserWarning)
|
|
202
499
|
try:
|
|
203
500
|
rich.print(f" {get_data_storage_location() = }", flush=True)
|
|
204
501
|
location = get_data_storage_location()
|
|
@@ -223,6 +520,14 @@ if __name__ == "__main__":
|
|
|
223
520
|
except ValueError as exc:
|
|
224
521
|
rich.print(f" get_log_file_location() = [red]{exc}[/]")
|
|
225
522
|
|
|
523
|
+
try:
|
|
524
|
+
rich.print(f" {get_local_settings() = }", flush=True)
|
|
525
|
+
location = get_local_settings()
|
|
526
|
+
if location is None or not Path(location).exists():
|
|
527
|
+
rich.print("[red]ERROR: The local settings file doesn't exist![/]")
|
|
528
|
+
except ValueError as exc:
|
|
529
|
+
rich.print(f" get_local_settings() = [red]{exc}[/]")
|
|
530
|
+
|
|
226
531
|
if args.full:
|
|
227
532
|
rich.print()
|
|
228
533
|
rich.print(f" PYTHONPATH=[default]{os.environ.get('PYTHONPATH')}")
|
|
@@ -233,43 +538,38 @@ if __name__ == "__main__":
|
|
|
233
538
|
path_msg = "\n ".join(os.environ.get("PATH").split(":"))
|
|
234
539
|
rich.print(f" PATH=[\n {path_msg}\n ]")
|
|
235
540
|
|
|
236
|
-
help_msg =
|
|
237
|
-
[bold]
|
|
238
|
-
This variable
|
|
239
|
-
project. Its value is usually '~/git/plato-common-egse' which is considered the default
|
|
240
|
-
location.
|
|
241
|
-
|
|
242
|
-
[bold]{ENV_PLATO_INSTALL}[/bold]:
|
|
243
|
-
This variable shall point to the location where the CGSE will be installed and is
|
|
541
|
+
help_msg = """
|
|
542
|
+
[bold]PROJECT_INSTALL_LOCATION[/bold]:
|
|
543
|
+
This variable shall point to the location where the CGSE will be installed and is
|
|
244
544
|
usually set to `/cgse`. The variable is used by the [blue]update_cgse[/blue] script.
|
|
245
545
|
|
|
246
|
-
[bold]
|
|
546
|
+
[bold]PROJECT_CONF_DATA_LOCATION[/bold]:
|
|
247
547
|
This directory is the root folder for all the Setups of the site, the site is part
|
|
248
548
|
of the name. By default, this directory is located in the overall data storage folder.
|
|
249
549
|
|
|
250
|
-
[bold]
|
|
251
|
-
This variable is the root of the working copy of the 'plato-cgse-conf' project.
|
|
550
|
+
[bold]PROJECT_CONF_REPO_LOCATION[/bold]:
|
|
551
|
+
This variable is the root of the working copy of the 'plato-cgse-conf' project.
|
|
252
552
|
The value is usually set to `~/git/plato-cgse-conf`.
|
|
253
553
|
|
|
254
|
-
[bold]
|
|
554
|
+
[bold]PROJECT_DATA_STORAGE_LOCATION[/bold]:
|
|
255
555
|
This directory contains all the data files from the control servers and other
|
|
256
|
-
components. This folder is the root folder for all data from all cameras and
|
|
257
|
-
all sites. Below this folder shall be a folder for each of the cameras and in
|
|
258
|
-
there a sub-folder for each of the sites where that camera was tested. The
|
|
556
|
+
components. This folder is the root folder for all data from all cameras and
|
|
557
|
+
all sites. Below this folder shall be a folder for each of the cameras and in
|
|
558
|
+
there a sub-folder for each of the sites where that camera was tested. The
|
|
259
559
|
hierarchy is therefore: `$PLATO_DATA_STORAGE_LOCATION/<camera name>/<site id>.
|
|
260
|
-
Each of those folder shall contain at least the sub-folder [blue]daily[/blue], and [blue]obs[/blue].
|
|
261
|
-
|
|
262
|
-
There is also a file called [blue]obsid-table-<site id>.txt[/blue] which is maintained by
|
|
560
|
+
Each of those folder shall contain at least the sub-folder [blue]daily[/blue], and [blue]obs[/blue].
|
|
561
|
+
|
|
562
|
+
There is also a file called [blue]obsid-table-<site id>.txt[/blue] which is maintained by
|
|
263
563
|
the configuration manager and contains information about the observations that
|
|
264
564
|
were run and the commands to start those observation.
|
|
265
565
|
|
|
266
|
-
[bold]
|
|
267
|
-
This directory contains the log files with all messages that were sent to the
|
|
566
|
+
[bold]PROJECT_LOG_FILE_LOCATION[/bold]:
|
|
567
|
+
This directory contains the log files with all messages that were sent to the
|
|
268
568
|
logger control server. The log files are rotated on a daily basis at midnight UTC.
|
|
269
569
|
By default, this directory is also located in the overall data storage folder.
|
|
270
570
|
|
|
271
|
-
[bold]
|
|
272
|
-
This file is used for local site-specific settings. When the environment
|
|
571
|
+
[bold]PROJECT_LOCAL_SETTINGS[/bold]:
|
|
572
|
+
This file is used for local site-specific settings. When the environment
|
|
273
573
|
variable is not set, no local settings will be loaded. By default, this variable
|
|
274
574
|
is assumed to be '/cgse/local_settings.yaml'.
|
|
275
575
|
"""
|
|
@@ -285,3 +585,8 @@ if __name__ == "__main__":
|
|
|
285
585
|
#
|
|
286
586
|
# PLATO_WORKDIR
|
|
287
587
|
# PLATO_COMMON_EGSE_PATH - YES
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
if __name__ == "__main__":
|
|
591
|
+
import sys
|
|
592
|
+
main(sys.argv[1:])
|