Skip to content

Commit

Permalink
Revisiting where self variables are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
anpicci committed Dec 17, 2024
1 parent 24c1643 commit f28f70a
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions src/python/WMCore/Storage/Backends/GFAL2Impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ def __init__(self, stagein=False):
self.copyOpts = '-t 2400 -T 2400 -p -v --abort-on-failure {checksum} {options} {source} {destination}'
self.copyCommand = self.setups.format('. $JOBSTARTDIR/startup_environment.sh; date; gfal-copy ' + self.copyOpts)

def adjustSetup(self, auth_method=None):
"""
Adjust the `self.setups` based on the selected authentication method and regenerate commands.
"""
if auth_method == "X509":
self.setups = "env -i X509_USER_PROXY=$X509_USER_PROXY JOBSTARTDIR=$JOBSTARTDIR bash -c '{}'"
elif auth_method == "TOKEN":
self.setups = "env -i BEARER_TOKEN=$(cat $BEARER_TOKEN_FILE) JOBSTARTDIR=$JOBSTARTDIR bash -c '{}'"
else:
logging.info("Warning! Running gfal without either a X509 certificate or a token!")
self.setups = "env -i JOBSTARTDIR=$JOBSTARTDIR bash -c '{}'"

# Regenerate dependent commands
self.removeCommand = self.setups.format('. $JOBSTARTDIR/startup_environment.sh; date; gfal-rm -t 600 {}')
self.copyOpts = '-t 2400 -T 2400 -p -v --abort-on-failure {checksum} {options} {source} {destination}'
self.copyCommand = self.setups.format('. $JOBSTARTDIR/startup_environment.sh; date; gfal-copy ' + self.copyOpts)

def createFinalPFN(self, pfn):
"""
_createFinalPFN_
Expand Down Expand Up @@ -124,20 +141,8 @@ def createStageOutCommand(self, sourcePFN, targetPFN, options=None, checksums=No
:checksums: dict, collect checksums according to the algorithms saved as keys
:auth_method: str, the authentication method to be used ("X509", "TOKEN", or None)
"""

# Adjust self.setups based on the selected authentication method
if auth_method == "X509":
self.setups = "env -i X509_USER_PROXY=$X509_USER_PROXY JOBSTARTDIR=$JOBSTARTDIR bash -c '{}'"
elif auth_method == "TOKEN":
self.setups = "env -i BEARER_TOKEN=$(cat $BEARER_TOKEN_FILE) JOBSTARTDIR=$JOBSTARTDIR bash -c '{}'"
else:
logging.info("Warning! Running gfal without either a X509 certificate or a token!")
self.setups = "env -i JOBSTARTDIR=$JOBSTARTDIR bash -c '{}'"

#Need to define this variables here, otherwise the self.setups update is not propagated
self.removeCommand = self.setups.format('. $JOBSTARTDIR/startup_environment.sh; date; gfal-rm -t 600 {}')
self.copyOpts = '-t 2400 -T 2400 -p -v --abort-on-failure {checksum} {options} {source} {destination}'
self.copyCommand = self.setups.format('. $JOBSTARTDIR/startup_environment.sh; date; gfal-copy ' + self.copyOpts)
# Adjust the setup
self.adjustSetup(auth_method)

# Construct the gfal-cp command
copyCommandDict = self.buildCopyCommandDict(sourcePFN, targetPFN, options, checksums)
Expand All @@ -154,7 +159,7 @@ def createStageOutCommand(self, sourcePFN, targetPFN, options=None, checksums=No
{remove_command}
fi
exit $EXIT_STATUS
""".format(remove_command=self.createRemoveFileCommand(targetPFN))
""".format(remove_command=self.createRemoveFileCommand(targetPFN))

return result

Expand All @@ -170,18 +175,10 @@ def createDebuggingCommand(self, sourcePFN, targetPFN, options=None, checksums=N
:auth_method: str, the authentication method to be used ("X509", "TOKEN", or None)
"""

# Adjust self.setups based on the selected authentication method
if auth_method == "X509":
self.setups = "env -i X509_USER_PROXY=$X509_USER_PROXY JOBSTARTDIR=$JOBSTARTDIR bash -c '{}'"
elif auth_method == "TOKEN":
self.setups = "env -i BEARER_TOKEN=$(cat $BEARER_TOKEN_FILE) JOBSTARTDIR=$JOBSTARTDIR bash -c '{}'"
else:
self.setups = "env -i JOBSTARTDIR=$JOBSTARTDIR bash -c '{}'"
#Need to define this variables here, otherwise the self.setups update is not propagated
self.removeCommand = self.setups.format('. $JOBSTARTDIR/startup_environment.sh; date; gfal-rm -t 600 {}')
self.copyOpts = '-t 2400 -T 2400 -p -v --abort-on-failure {checksum} {options} {source} {destination}'
self.copyCommand = self.setups.format('. $JOBSTARTDIR/startup_environment.sh; date; gfal-copy ' + self.copyOpts)
# Adjust the setup
self.adjustSetup(auth_method)

# Build the gfal-cp command for debugging purposes
copyCommandDict = self.buildCopyCommandDict(sourcePFN, targetPFN, options, checksums)
copyCommand = self.copyCommand.format_map(copyCommandDict)

Expand Down

0 comments on commit f28f70a

Please sign in to comment.