Skip to content

Commit 34f6bd7

Browse files
authored
Merge pull request #6505 from kreczko/kreczko-code-issues-part2
[integration] simplify if-statements for readability and performance
2 parents 18a6f89 + 9f0d2a3 commit 34f6bd7

File tree

9 files changed

+19
-49
lines changed

9 files changed

+19
-49
lines changed

src/DIRAC/ConfigurationSystem/private/ConfigurationData.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,11 @@ def mergingEnabled(self):
249249

250250
def getAutoPublish(self):
251251
value = self.extractOptionFromCFG("%s/AutoPublish" % self.configurationPath, self.localCFG)
252-
if value and value.lower() in ("no", "false", "n"):
253-
return False
254-
else:
255-
return True
252+
return not bool(value and value.lower() in ("no", "false", "n"))
256253

257254
def getAutoSlaveSync(self):
258255
value = self.extractOptionFromCFG("%s/AutoSlaveSync" % self.configurationPath, self.localCFG)
259-
if value and value.lower() in ("no", "false", "n"):
260-
return False
261-
else:
262-
return True
256+
return not bool(value and value.lower() in ("no", "false", "n"))
263257

264258
def getServers(self):
265259
return list(self.remoteServerList)
@@ -288,10 +282,7 @@ def getCompressedData(self):
288282

289283
def isMaster(self):
290284
value = self.extractOptionFromCFG("%s/Master" % self.configurationPath, self.localCFG)
291-
if value and value.lower() in ("yes", "true", "y"):
292-
return True
293-
else:
294-
return False
285+
return bool(value and value.lower() in ("yes", "true", "y"))
295286

296287
def getServicesPath(self):
297288
return "/Services"
@@ -304,15 +295,11 @@ def isService(self):
304295

305296
def useServerCertificate(self):
306297
value = self.extractOptionFromCFG("/DIRAC/Security/UseServerCertificate")
307-
if value and value.lower() in ("y", "yes", "true"):
308-
return True
309-
return False
298+
return bool(value and value.lower() in ("yes", "true", "y"))
310299

311300
def skipCACheck(self):
312301
value = self.extractOptionFromCFG("/DIRAC/Security/SkipCAChecks")
313-
if value and value.lower() in ("y", "yes", "true"):
314-
return True
315-
return False
302+
return bool(value and value.lower() in ("yes", "true", "y"))
316303

317304
def dumpLocalCFGToFile(self, fileName):
318305
try:

src/DIRAC/DataManagementSystem/Client/CmdDirCompletion/DirectoryCompletion.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,13 @@ def parse_text_line(self, text, line, cwd):
4444

4545
# check absolute path
4646
def check_absolute(self, path):
47-
if path.startswith(self.fs.seq):
48-
return True
49-
else:
50-
return False
47+
return path.startswith(self.fs.seq)
5148

5249
# generate absolute path
5350
def generate_absolute(self, path, cwd):
5451
if self.check_absolute(path):
55-
pass
56-
else:
57-
path = os.path.join(cwd, path)
58-
return path
52+
return path
53+
return os.path.join(cwd, path)
5954

6055
# get the parent directory or the current directory
6156
# Using the last char "/" to determine

src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/SecurityManager/SecurityManagerBase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def hasAccess(self, opType, paths, credDict):
6969

7070
successful = {}
7171
failed = {}
72-
if not opType.lower() in ["read", "write", "execute"]:
72+
if opType.lower() not in ["read", "write", "execute"]:
7373
return S_ERROR("Operation type not known")
7474
if self.db.globalReadAccess and (opType.lower() == "read"):
7575
for path in paths:

src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/SecurityManager/VOMSSecurityManager.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,7 @@ def __shareVomsRole(self, grpName, otherGrpName):
7979
def __isNotExistError(self, errorMsg):
8080
"""Returns true if the errorMsg means that the file/directory does not exist"""
8181

82-
for possibleMsg in ["not exist", "not found", "No such file or directory"]:
83-
if possibleMsg in errorMsg:
84-
return True
85-
86-
return False
82+
return any(possibleMsg in errorMsg for possibleMsg in ["not exist", "not found", "No such file or directory"])
8783

8884
def __getFilePermission(self, path, credDict, noExistStrategy=None):
8985
"""Checks POSIX permission for a file using the VOMS roles.

src/DIRAC/FrameworkSystem/Service/UserProfileManagerHandler.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ def export_deleteProfiles(self, userList):
129129
"""
130130
credDict = self.getRemoteCredentials()
131131
requesterUserName = credDict["username"]
132-
if Properties.SERVICE_ADMINISTRATOR in credDict["properties"]:
133-
admin = True
134-
else:
135-
admin = False
132+
admin = Properties.SERVICE_ADMINISTRATOR in credDict["properties"]
136133
for entry in userList:
137134
userName = entry
138135
if admin or userName == requesterUserName:

src/DIRAC/FrameworkSystem/scripts/dirac_sys_sendmail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def main():
3333

3434
arg = "".join(args)
3535

36-
if not len(arg) > 0:
36+
if not arg:
3737
gLogger.error("Missing argument")
3838
DIRACexit(2)
3939

src/DIRAC/Resources/Storage/RFIOStorage.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,7 @@ def __getDir(self, srcDirectory, destDirectory):
703703
subDirsGot = False
704704

705705
# Check whether all the operations were successful
706-
if subDirsGot and gotFiles:
707-
allGot = True
708-
else:
709-
allGot = False
706+
allGot = bool(gotFiles and subDirsGot)
710707
resDict = {"AllGot": allGot, "Files": filesGot, "Size": sizeGot}
711708
return S_OK(resDict)
712709

src/DIRAC/TransformationSystem/Agent/ValidateOutputDataAgent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def initialize(self):
6868
def execute(self):
6969
"""The VerifyOutputData execution method"""
7070
self.enableFlag = self.am_getOption("EnableFlag", "True")
71-
if not self.enableFlag == "True":
71+
if self.enableFlag != "True":
7272
self.log.info("VerifyOutputData is disabled by configuration option 'EnableFlag'")
7373
return S_OK("Disabled via CS flag")
7474

src/DIRAC/TransformationSystem/Client/Transformation.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -564,15 +564,13 @@ def getSummaryTransformations(self, transID=[]):
564564
except Exception as x:
565565
print("Exception %s " % str(x))
566566

567-
if not len(dictList) > 0:
567+
if not dictList:
568568
gLogger.error("No found transformations satisfying input condition")
569569
return S_ERROR("No found transformations satisfying input condition")
570-
else:
571-
print(
572-
self._printFormattedDictList(
573-
dictList, paramShowNamesShort, paramShowNamesShort[0], paramShowNamesShort[0]
574-
)
575-
)
570+
571+
print(
572+
self._printFormattedDictList(dictList, paramShowNamesShort, paramShowNamesShort[0], paramShowNamesShort[0])
573+
)
576574

577575
return S_OK(dictList)
578576

0 commit comments

Comments
 (0)