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