Skip to content

Commit a31e5d9

Browse files
committed
feat: add walrus operator in RemoteRunner
1 parent b50ca8d commit a31e5d9

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/DIRAC/WorkloadManagementSystem/Utilities/RemoteRunner.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ def execute(self, command, workingDirectory=".", numberOfProcessors=1, cleanRemo
6565
self.log.verbose("Command to submit:", command)
6666

6767
# Check whether CE parameters are set
68-
result = self._checkParameters()
69-
if not result["OK"]:
68+
if not (result := self._checkParameters())["OK"]:
7069
result["Errno"] = DErrno.ESECTION
7170
return result
7271
self.log.info(
@@ -75,8 +74,7 @@ def execute(self, command, workingDirectory=".", numberOfProcessors=1, cleanRemo
7574
)
7675

7776
# Set up Application Queue
78-
result = self._setUpWorkloadCE(numberOfProcessors)
79-
if not result["OK"]:
77+
if not (result := self._setUpWorkloadCE(numberOfProcessors))["OK"]:
8078
result["Errno"] = DErrno.ERESUNA
8179
return result
8280
workloadCE = result["Value"]
@@ -94,8 +92,9 @@ def execute(self, command, workingDirectory=".", numberOfProcessors=1, cleanRemo
9492
outputs = ["/"]
9593

9694
# Submit the command as a job
97-
result = workloadCE.submitJob(self.executable, workloadCE.proxy, inputs=inputs, outputs=outputs)
98-
if not result["OK"]:
95+
if not (result := workloadCE.submitJob(self.executable, workloadCE.proxy, inputs=inputs, outputs=outputs))[
96+
"OK"
97+
]:
9998
result["Errno"] = DErrno.EWMSSUBM
10099
return result
101100
jobID = result["Value"][0]
@@ -116,24 +115,21 @@ def execute(self, command, workingDirectory=".", numberOfProcessors=1, cleanRemo
116115

117116
# Get job outputs
118117
self.log.info("Getting the outputs of the command...")
119-
result = workloadCE.getJobOutput(f"{jobID}:::{stamp}", os.path.abspath("."))
120-
if not result["OK"]:
118+
if not (result := workloadCE.getJobOutput(f"{jobID}:::{stamp}", os.path.abspath(".")))["OK"]:
121119
result["Errno"] = DErrno.EWMSJMAN
122120
return result
123121
output, error = result["Value"]
124122

125123
# Make sure the output is correct
126124
self.log.info("Checking the integrity of the outputs...")
127-
result = self._checkOutputIntegrity(".")
128-
if not result["OK"]:
125+
if not (result := self._checkOutputIntegrity("."))["OK"]:
129126
result["Errno"] = DErrno.EWMSJMAN
130127
return result
131128
self.log.info("The output has been retrieved and declared complete")
132129

133130
# Clean job in the remote resource
134131
if cleanRemoteJob:
135-
result = workloadCE.cleanJob(jobID)
136-
if not result["OK"]:
132+
if not (result := workloadCE.cleanJob(jobID))["OK"]:
137133
self.log.warn("Failed to clean the output remotely", result["Message"])
138134
self.log.info("The job has been remotely removed")
139135

@@ -261,7 +257,6 @@ def _checkOutputIntegrity(self, workingDirectory):
261257
while chunk := f.read(128 * hash.block_size):
262258
hash.update(chunk)
263259
if checkSum != hash.hexdigest():
264-
print(hash.hexdigest())
265260
return S_ERROR(f"{localOutput} is corrupted")
266261

267262
return S_OK()

0 commit comments

Comments
 (0)