Skip to content

Commit

Permalink
Fixed and disabled DictFile.append(), replaced by add_environment()
Browse files Browse the repository at this point in the history
append was used only for environment variables in the condor submit file and was causing a malformed submit file

add_environment was already used at times and is a better method. append was fixed and is still there commented in case we'd like to use it for other attributes in the future
  • Loading branch information
mambelli committed Dec 17, 2024
1 parent 24574f4 commit d64a273
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
3 changes: 2 additions & 1 deletion creation/lib/cgWCreate.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def populate(self, exe_fname, entry_name, conf, entry):
frontend_recipients = [] # TODO: change when adding support for LOG_RECIPIENTS_CLIENT
log_recipients = list(set(factory_recipients + frontend_recipients))
if len(log_recipients) > 0:
self.append("environment", '"LOG_RECIPIENTS=' + "'" + " ".join(log_recipients) + "'" + '"')
# self.append("environment", '"LOG_RECIPIENTS=' + "'" + " ".join(log_recipients) + "'" + '"')
self.add_environment("LOG_RECIPIENTS='" + " ".join(log_recipients) + "'")
# print("Token dir: " + token_basedir) # DEBUG

# Add in some common elements before setting up grid type specific attributes
Expand Down
40 changes: 26 additions & 14 deletions creation/lib/cgWDictFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,34 @@ def __init__(
cWDictFile.DictFile.__init__(self, dir, fname, sort_keys, order_matters, fname_idx)
self.jobs_in_cluster = jobs_in_cluster

def append(self, key, val):
# TODO add_environment would allow an easier handling of the environment attribute:
# - ordered dict as input
# - handling quoting and escaping
# - formatting and overwriting the environment attribute in the submit file dict
if key == "environment":
# assumed to be in the new format (quoted)
if key not in self.keys:
self.add(key, val)
else:
# should add some protection about correct quoting
self.add(f"{val[:-1]} {self[key][1:]}", True)
else:
raise RuntimeError(f"CondorJDLDictFile append unsupported for key {key} (val: {val})!")
# append has been replaced by add_environment to ease the quote handling
# If a generic version is needed, the code can be modified and restored
# def append(self, key, val):
# if key == "environment":
# # assumed to be in the new format (quoted)
# if key not in self.keys:
# self.add(key, val)
# else:
# # should add some protection about correct quoting
# self.add(key, f"{val[:-1]} {self[key][1:]}", True)
# else:
# raise RuntimeError(f"CondorJDLDictFile append unsupported for key {key} (val: {val})!")

def add_environment(self, val):
"""Add a variable definition to the "environment" key in the CondorJDLDictFile.
Defines a new "environment" entry if not there,
appends to the existing environment if there.
The whole environment value is enclosed in double quotes (")
Args:
val (str): variable definition to add to the environment. Cannot contain double quotes (")
Single quotes (') are OK and can be used to quote string values
"""
# TODO: improve environment handling:
# - allow ordered dict as input
# - handling quoting and escaping, e.g. validate val for double quotes
# - formatting and overwriting the environment attribute in the submit file dict
# e.g. add a variable already in the environment
curenv = self.get("environment")
if curenv:
if curenv[0] == '"':
Expand Down

0 comments on commit d64a273

Please sign in to comment.