Skip to content

Commit 87fc17d

Browse files
committed
style: mostly f-strings
1 parent 25d6120 commit 87fc17d

File tree

1 file changed

+19
-47
lines changed

1 file changed

+19
-47
lines changed

src/DIRAC/TransformationSystem/DB/TransformationDB.py

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def addTransformation(
151151
res = self._getTransformationID(transName, connection=connection)
152152
if res["OK"]:
153153
return S_ERROR(
154-
"Transformation with name %s already exists with TransformationID = %d" % (transName, res["Value"])
154+
f"Transformation with name {transName} already exists with TransformationID = {res['Value']}"
155155
)
156156
elif res["Message"] != "Transformation does not exist":
157157
return res
@@ -229,7 +229,7 @@ def addTransformation(
229229
if not res["OK"]:
230230
gLogger.error("Failed to update parent transformation agent type, now deleting", res["Message"])
231231
return self.deleteTransformation(transID, connection=connection)
232-
message = "Creation of the derived transformation (%d)" % transID
232+
message = f"Creation of the derived transformation ({transID})"
233233
self.__updateTransformationLogging(originalID, message, author, connection=connection)
234234
res = self.getTransformationFiles(condDict={"TransformationID": originalID}, connection=connection)
235235
if not res["OK"]:
@@ -264,7 +264,7 @@ def addTransformation(
264264
res = self.__addFilesToTransformation(transID, fileIDs, connection=connection)
265265
if not res["OK"]:
266266
gLogger.error("Failed to add files to transformation", f"{transID} {res['Message']}")
267-
message = "Created transformation %d" % transID
267+
message = f"Created transformation {transID}"
268268

269269
self.__updateTransformationLogging(transID, message, author, connection=connection)
270270
return S_OK(transID)
@@ -401,24 +401,16 @@ def __updateTransformationParameter(self, transID, paramName, paramValue, connec
401401
if not res["OK"]:
402402
return S_ERROR("Failed to parse parameter value")
403403
paramValue = res["Value"]
404-
req = "UPDATE Transformations SET %s=%s, LastUpdate=UTC_TIMESTAMP() WHERE TransformationID=%d" % (
405-
paramName,
406-
paramValue,
407-
transID,
408-
)
404+
req = f"UPDATE Transformations SET {paramName}={paramValue}, LastUpdate=UTC_TIMESTAMP() WHERE TransformationID={transID}"
409405
return self._update(req, conn=connection)
410-
req = "UPDATE Transformations SET %s='%s', LastUpdate=UTC_TIMESTAMP() WHERE TransformationID=%d" % (
411-
paramName,
412-
paramValue,
413-
transID,
414-
)
406+
req = f"UPDATE Transformations SET {paramName}={paramValue}, LastUpdate=UTC_TIMESTAMP() WHERE TransformationID={transID}"
415407
return self._update(req, conn=connection)
416408

417409
def _getTransformationID(self, transName, connection=False):
418410
"""Method returns ID of transformation with the name=<name>"""
419411
try:
420412
transName = int(transName)
421-
cmd = "SELECT TransformationID from Transformations WHERE TransformationID=%d;" % transName
413+
cmd = f"SELECT TransformationID from Transformations WHERE TransformationID={transName};"
422414
except ValueError:
423415
if not isinstance(transName, str):
424416
return S_ERROR("Transformation should be ID or name")
@@ -433,7 +425,7 @@ def _getTransformationID(self, transName, connection=False):
433425
return S_OK(res["Value"][0][0])
434426

435427
def __deleteTransformation(self, transID, connection=False):
436-
req = "DELETE FROM Transformations WHERE TransformationID=%d;" % transID
428+
req = f"DELETE FROM Transformations WHERE TransformationID={transID};"
437429
return self._update(req, conn=connection)
438430

439431
def __updateFilterQueries(self, connection=False):
@@ -513,7 +505,7 @@ def deleteTransformationParameter(self, transName, paramName, author="", connect
513505
return res
514506

515507
def __addAdditionalTransformationParameter(self, transID, paramName, paramValue, connection=False):
516-
req = "DELETE FROM AdditionalParameters WHERE TransformationID=%d AND ParameterName='%s'" % (transID, paramName)
508+
req = f"DELETE FROM AdditionalParameters WHERE TransformationID={transID} AND ParameterName='{paramName}'"
517509
res = self._update(req, conn=connection)
518510
if not res["OK"]:
519511
return res
@@ -552,7 +544,7 @@ def __deleteTransformationParameters(self, transID, parameters=None, connection=
552544
"""Remove the parameters associated to a transformation"""
553545
if parameters is None:
554546
parameters = []
555-
req = "DELETE FROM AdditionalParameters WHERE TransformationID=%d" % transID
547+
req = f"DELETE FROM AdditionalParameters WHERE TransformationID={transID}"
556548
if parameters:
557549
req = f"{req} AND ParameterName IN ({stringListToString(parameters)});"
558550
return self._update(req, conn=connection)
@@ -778,15 +770,7 @@ def __insertExistingTransformationFiles(self, transID, fileTuplesList, connectio
778770
if taskID:
779771
# Should be readable up to 999,999 tasks: that field is an int(11) in the DB, not a string
780772
taskID = 1000000 * int(originalID) + int(taskID)
781-
req = "%s (%d,'%s','%d',%d,'%s','%s',UTC_TIMESTAMP())," % (
782-
req,
783-
transID,
784-
status,
785-
taskID,
786-
fileID,
787-
targetSE,
788-
usedSE,
789-
)
773+
req = f"{req} ({transID},'{status}','{taskID}',{fileID},'{targetSE}','{usedSE}',UTC_TIMESTAMP()),"
790774
if not candidates:
791775
continue
792776

@@ -877,12 +861,12 @@ def __deleteTransformationFileTask(self, transID, taskID, connection=False):
877861
"""Delete the file associated to a given task of a given transformation
878862
from the TransformationFileTasks table for transformation with TransformationID and TaskID
879863
"""
880-
req = "DELETE FROM TransformationFileTasks WHERE TransformationID=%d AND TaskID=%d" % (transID, taskID)
864+
req = f"DELETE FROM TransformationFileTasks WHERE TransformationID={transID} AND TaskID={taskID}"
881865
return self._update(req, conn=connection)
882866

883867
def __deleteTransformationFileTasks(self, transID, connection=False):
884868
"""Remove all associations between files, tasks and a transformation"""
885-
req = "DELETE FROM TransformationFileTasks WHERE TransformationID = %d;" % transID
869+
req = f"DELETE FROM TransformationFileTasks WHERE TransformationID = {transID}"
886870
res = self._update(req, conn=connection)
887871
if not res["OK"]:
888872
gLogger.error("Failed to delete transformation files/task history", res["Message"])
@@ -997,7 +981,7 @@ def deleteTasks(self, transName, taskIDbottom, taskIDtop, author="", connection=
997981
res = self.__removeTransformationTask(transID, taskID, connection=connection)
998982
if not res["OK"]:
999983
return res
1000-
message = "Deleted tasks from %d to %d" % (taskIDbottom, taskIDtop)
984+
message = f"Deleted tasks from {taskIDbottom} to {taskIDtop}"
1001985
self.__updateTransformationLogging(transID, message, author, connection=connection)
1002986
return res
1003987

@@ -1088,17 +1072,17 @@ def __setTaskParameterValue(self, transID, taskID, paramName, paramValue, connec
10881072

10891073
def __deleteTransformationTasks(self, transID, connection=False):
10901074
"""Delete all the tasks from the TransformationTasks table for transformation with TransformationID"""
1091-
req = "DELETE FROM TransformationTasks WHERE TransformationID=%d" % transID
1075+
req = f"DELETE FROM TransformationTasks WHERE TransformationID={transID}"
10921076
return self._update(req, conn=connection)
10931077

10941078
def __deleteTransformationTask(self, transID, taskID, connection=False):
10951079
"""Delete the task from the TransformationTasks table for transformation with TransformationID"""
1096-
req = "DELETE FROM TransformationTasks WHERE TransformationID=%d AND TaskID=%d" % (transID, taskID)
1080+
req = f"DELETE FROM TransformationTasks WHERE TransformationID={transID} AND TaskID={taskID}"
10971081
return self._update(req, conn=connection)
10981082

10991083
def __deleteTransformationMetaQueries(self, transID, connection=False):
11001084
"""Delete all the meta queries from the TransformationMetaQueries table for transformation with TransformationID"""
1101-
req = "DELETE FROM TransformationMetaQueries WHERE TransformationID=%d" % transID
1085+
req = f"DELETE FROM TransformationMetaQueries WHERE TransformationID={transID}"
11021086
return self._update(req, conn=connection)
11031087

11041088
####################################################################
@@ -1258,9 +1242,9 @@ def __insertTaskInputs(self, transID, taskID, lfns, connection=False):
12581242

12591243
def __deleteTransformationTaskInputs(self, transID, taskID=0, connection=False):
12601244
"""Delete all the tasks inputs from the TaskInputs table for transformation with TransformationID"""
1261-
req = "DELETE FROM TaskInputs WHERE TransformationID=%d" % transID
1245+
req = f"DELETE FROM TaskInputs WHERE TransformationID={transID}"
12621246
if taskID:
1263-
req = "%s AND TaskID=%d" % (req, int(taskID))
1247+
req = f"{req} AND TaskID={taskID}"
12641248
return self._update(req, conn=connection)
12651249

12661250
###########################################################################
@@ -1307,25 +1291,13 @@ def getTransformationLogging(self, transName, connection=False):
13071291

13081292
def __deleteTransformationLog(self, transID, connection=False):
13091293
"""Remove the entries in the transformation log for a transformation"""
1310-
req = "DELETE FROM TransformationLog WHERE TransformationID=%d;" % transID
1294+
req = f"DELETE FROM TransformationLog WHERE TransformationID={transID}"
13111295
return self._update(req, conn=connection)
13121296

13131297
###########################################################################
13141298
#
13151299
# These methods manipulate the DataFiles table
13161300
#
1317-
def __getAllFileIDs(self, connection=False):
1318-
"""Get all the fileIDs for the supplied list of lfns"""
1319-
req = "SELECT LFN,FileID FROM DataFiles;"
1320-
res = self._query(req, conn=connection)
1321-
if not res["OK"]:
1322-
return res
1323-
fids = {}
1324-
lfns = {}
1325-
for lfn, fileID in res["Value"]:
1326-
fids[fileID] = lfn
1327-
lfns[lfn] = fileID
1328-
return S_OK((fids, lfns))
13291301

13301302
def __getFileIDsForLfns(self, lfns, connection=False):
13311303
"""Get file IDs for the given list of lfns

0 commit comments

Comments
 (0)