DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
daqconf
python
daqconf
set_session_env_var.py
Go to the documentation of this file.
1
import
conffwk
2
import
confmodel_dal
3
import
sys
4
5
def
set_session_env_var
(
6
oksfile: str,
7
session_name: str,
8
requested_env_var_name: str,
9
requested_env_var_value: str,
10
overwrite: bool =
True
,
11
) ->
None
:
12
"""Script to set the value of an environment variable in the specified Session of the
13
specified OKS database file"""
14
db =
conffwk.Configuration
(
"oksconflibs:"
+ oksfile)
15
if
session_name ==
""
:
16
print(f
"Error: the session name needs to be specified"
, file=sys.stderr)
17
return
18
else
:
19
try
:
20
session = db.get_dal(
"Session"
, session_name)
21
except
:
22
print(f
"Error: could not find Session \"{session_name}\" in file \"{oksfile}\""
, file=sys.stderr)
23
return
24
25
schemafiles = [
26
"schema/confmodel/dunedaq.schema.xml"
27
]
28
dal =
conffwk.dal.module
(
"dal"
, schemafiles)
29
30
# First, check if the requested env var is already defined for the specified OKS Session
31
existing_env_var =
None
32
for
entry
in
session.environment:
33
if
isinstance(entry, dal.VariableSet):
34
for
subentry
in
entry.contains:
35
if
subentry.name == requested_env_var_name:
36
existing_env_var = subentry
37
break
38
else
:
39
if
entry.name == requested_env_var_name:
40
existing_env_var = entry
41
42
if
existing_env_var
is
not
None
:
43
break
44
45
# if we found an existing env var, and we have been told not to over-write it, exit now
46
if
existing_env_var
is
not
None
and
not
overwrite:
47
return
48
49
# if we found an existing env var, update the DB with the new value
50
if
existing_env_var
is
not
None
:
51
existing_env_var.value = requested_env_var_value
52
db.update_dal(existing_env_var)
53
54
# otherwise, create a new env var and assign it to the OKS Session
55
else
:
56
# 03-Jul-2025, KAB: switched from using a "temporary" string in the dal_name
57
# to using the session name. This means that each Session will get its own
58
# instance of the DAL Variable, which seems safer than having the possibility
59
# of multiple Sessions sharing the same Variable.
60
new_env_var_dal_name = session_name +
"-env-var-"
+ requested_env_var_name
61
new_env_var_dal_name = new_env_var_dal_name.lower()
62
new_env_var_dal_name = new_env_var_dal_name.replace(
"_"
,
"-"
)
63
64
new_env_var = dal.Variable(new_env_var_dal_name, name=requested_env_var_name, value=requested_env_var_value)
65
db.update_dal(new_env_var)
66
67
session.environment.append(new_env_var)
68
db.update_dal(session)
69
70
# commit all changes
71
db.commit()
conffwk.Configuration.Configuration
Definition
Configuration.py:29
conffwk.dal.module
module(name, schema, other_dals=[], backend='oksconflibs', db=None)
Definition
dal.py:695
set_session_env_var
Definition
set_session_env_var.py:1
Generated on
for DUNE-DAQ by
1.17.0