Skip to content

Commit

Permalink
style: more compact code (Codeium)
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Aug 28, 2024
1 parent a6d98b3 commit 792c5c2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
49 changes: 20 additions & 29 deletions src/DIRAC/ResourceStatusSystem/Command/DowntimeCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
diracToGOC_conversion = {
# Storage elements
"CREAM": "CREAM-CE", # deprecated
"HTCondorCE" :"org.opensciencegrid.htcondorce",
"ARC" : "ARC-CE",
"ARC6" : "ARC-CE",
"AREX" : "ARC-CE",
"HTCondorCE": "org.opensciencegrid.htcondorce",
"ARC": "ARC-CE",
"ARC6": "ARC-CE",
"AREX": "ARC-CE",
# FTS
"FTS3": "FTS",
"FTS": "FTS",
Expand All @@ -53,15 +53,8 @@ class DowntimeCommand(Command):
def __init__(self, args=None, clients=None):
super().__init__(args, clients)

if "GOCDBClient" in self.apis:
self.gClient = self.apis["GOCDBClient"]
else:
self.gClient = GOCDBClient()

if "ResourceManagementClient" in self.apis:
self.rmClient = self.apis["ResourceManagementClient"]
else:
self.rmClient = ResourceManagementClient()
self.gClient = self.apis.get("GOCDBClient", GOCDBClient())
self.rmClient = self.apis.get("ResourceManagementClient", ResourceManagementClient())

def _storeCommand(self, result):
"""
Expand Down Expand Up @@ -158,23 +151,23 @@ def _prepareCommand(self):

# The DIRAC se names mean nothing on the grid, but their hosts and service types do mean.
elif elementType == "StorageElement":
# Get the SE object and its protocols
try:
se = StorageElement(elementName)
se_protocols = list(se.localAccessProtocolList)
se_protocols.extend(x for x in se.localWriteProtocolList if x not in se_protocols)
except AttributeError: # Sometimes the SE can't be instantiated properly
except AttributeError:
self.log.error("Failure instantiating StorageElement object", elementName)
return S_ERROR("Failure instantiating StorageElement")
if "SEType" in se.options:
# Type should follow the convention TXDY
seType = se.options["SEType"]
diskSE = re.search("D[1-9]", seType) is not None
tapeSE = re.search("T[1-9]", seType) is not None
if tapeSE:
gOCDBServiceType = diracToGOC_conversion[f"tape_{se_protocols[0]}"] # Just take the first, for simplicity
elif diskSE:
gOCDBServiceType = diracToGOC_conversion[f"disk_{se_protocols[0]}"] # Just take the first, for simplicity

# Determine the SE type and update gOCDBServiceType accordingly
se_type = se.options.get("SEType", "")
if re.search(r"D[1-9]", se_type):
gOCDBServiceType = diracToGOC_conversion[f"disk_{se_protocols[0]}"]
elif re.search(r"T[1-9]", se_type):
gOCDBServiceType = diracToGOC_conversion[f"tape_{se_protocols[0]}"]

# Get the SE hosts and return an error if none are found
res = getSEHosts(elementName)
if not res["OK"]:
return res
Expand Down Expand Up @@ -252,9 +245,8 @@ def doNew(self, masterParams=None):

# cleaning the Cache
if elementNames:
cleanRes = self._cleanCommand(element, elementNames)
if not cleanRes["OK"]:
return cleanRes
if not (res := self._cleanCommand(element, elementNames))["OK"]:
return res

uniformResult = []

Expand Down Expand Up @@ -286,9 +278,8 @@ def doNew(self, masterParams=None):

uniformResult.append(dt)

storeRes = self._storeCommand(uniformResult)
if not storeRes["OK"]:
return storeRes
if not (res := self._storeCommand(uniformResult))["OK"]:
return res

return S_OK()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# Mock external libraries / modules not interesting for the unit test
seMock = mock.MagicMock()
seMock.options = {"SEType": "T0D1"}
seMock.localAccessProtocolList = ["https", "root"]
seMock.localWriteProtocolList = ["https"]

mock_GOCDBClient = mock.MagicMock()
mock_RMClient = mock.MagicMock()
Expand Down

0 comments on commit 792c5c2

Please sign in to comment.