Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions MC/bin/o2dpg_dpl_config_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ def log_line(logger, message):
else:
logger.write(message + "\n")

def quote_for_nested_string(val):
s = str(val)
# Already double-quoted?
if s.startswith('"') and s.endswith('"'):
return s
# Escape inner quotes
s_escaped = s.replace('"', r'\"')
return f'"{s_escaped}"'

def quote_if_needed(val):
# Only quote values that are likely to break shell parsing
# or contain nested shell-sensitive characters
s = str(val)
if re.search(r'[ \t;:&|<>]', s):
return quote_for_nested_string(s)
return s

def modify_dpl_command(cmd_str, config_anchor, allow_overwrite=False, logger=None, configname=None):
# check if cmd_str is given as list, in which case we transfrom to string
if isinstance(cmd_str, list) == True:
Expand Down Expand Up @@ -196,12 +213,6 @@ def modify_dpl_command(cmd_str, config_anchor, allow_overwrite=False, logger=Non
added = []
overwritten = []

def quote_if_needed(val):
s = str(val)
if " " in s and not (s.startswith('"') and s.endswith('"')):
return f'"{s}"'
return s

# Step 1: Existing options (preserved or overwritten)
for key, val in existing_opts.items():
if allow_overwrite and key in anchor_opts:
Expand Down
4 changes: 2 additions & 2 deletions MC/bin/o2dpg_sim_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from o2dpg_workflow_utils import createTask, createGlobalInitTask, dump_workflow, adjust_RECO_environment, isActive, activate_detector, deactivate_detector, compute_n_workers, merge_dicts
from o2dpg_qc_finalization_workflow import include_all_QC_finalization
from o2dpg_sim_config import create_sim_config, create_geant_config, constructConfigKeyArg, option_if_available, overwrite_config
from o2dpg_dpl_config_tools import parse_command_string, modify_dpl_command, dpl_option_from_config, TaskFinalizer
from o2dpg_dpl_config_tools import dpl_option_from_config, TaskFinalizer, quote_if_needed

# for some JAliEn interaction
from alienpy.alien import JAlien
Expand Down Expand Up @@ -504,7 +504,7 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True):
if ccdbbackend:
common=common + " --condition-not-after " + str(args.condition_not_after)
if ccdbRemap != None:
common=common + " --condition-remap " + ccdbRemap
common=common + f" --condition-remap {quote_if_needed(ccdbRemap)} "
if args.noIPC!=None:
return common + " --no-IPC "
if bigshm:
Expand Down