Skip to content

Commit d8ca7c2

Browse files
authored
Merge pull request #5684 from TaykYoku/integration_fixCSGlobal
[integration] remove CSGlobals.Extensions class
2 parents 025eca8 + c557111 commit d8ca7c2

File tree

3 files changed

+29
-106
lines changed

3 files changed

+29
-106
lines changed
Lines changed: 15 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,19 @@
11
"""
22
Some Helper functions to retrieve common location from the CS
33
"""
4-
import importlib
5-
from DIRAC.Core.Utilities.Decorators import deprecated
6-
from DIRAC.Core.Utilities.DIRACSingleton import DIRACSingleton
74
from DIRAC.Core.Utilities.Extensions import extensionsByPriority
85

96

10-
class Extensions(metaclass=DIRACSingleton):
11-
def __init__(self):
12-
self.__modules = {}
13-
self.__orderedExtNames = []
14-
self.__csExt = []
15-
16-
def __load(self):
17-
if self.__orderedExtNames:
18-
return
19-
for extName in extensionsByPriority():
20-
try:
21-
res = importlib.import_module(extName)
22-
if res[0]:
23-
res[0].close()
24-
self.__orderedExtNames.append(extName)
25-
self.__modules[extName] = res
26-
except ImportError:
27-
pass
28-
29-
def getCSExtensions(self):
30-
if not self.__csExt:
31-
exts = extensionsByPriority()
32-
33-
self.__csExt = []
34-
for ext in exts:
35-
if ext.endswith("DIRAC"):
36-
ext = ext[:-5]
37-
# If the extension is now "" (i.e. vanilla DIRAC), don't include it
38-
if ext:
39-
self.__csExt.append(ext)
40-
return self.__csExt
41-
42-
@deprecated("Use DIRAC.Core.Utilities.Extensions.extensionsByPriority instead")
43-
def getInstalledExtensions(self):
44-
return extensionsByPriority()
45-
46-
def getExtensionPath(self, extName):
47-
self.__load()
48-
return self.__modules[extName][1]
49-
50-
def getExtensionData(self, extName):
51-
self.__load()
52-
return self.__modules[extName]
53-
54-
55-
def getSetup():
7+
def getSetup() -> str:
8+
"""
9+
Return setup name
10+
"""
5611
from DIRAC import gConfig
5712

5813
return gConfig.getValue("/DIRAC/Setup", "")
5914

6015

61-
def getVO(defaultVO=""):
16+
def getVO(defaultVO: str = "") -> str:
6217
"""
6318
Return VO from configuration
6419
"""
@@ -67,29 +22,27 @@ def getVO(defaultVO=""):
6722
return gConfig.getValue("/DIRAC/VirtualOrganization", defaultVO)
6823

6924

70-
def getCSExtensions():
25+
def getCSExtensions() -> list:
7126
"""
7227
Return list of extensions registered in the CS
7328
They do not include DIRAC
7429
"""
75-
return Extensions().getCSExtensions()
30+
return [ext[:-5] if ext.endswith("DIRAC") else ext for ext in extensionsByPriority() if ext != "DIRAC"]
7631

7732

78-
@deprecated("Use DIRAC.Core.Utilities.Extensions.extensionsByPriority instead")
79-
def getInstalledExtensions():
33+
def skipCACheck() -> bool:
8034
"""
81-
Return list of extensions registered in the CS and available in local installation
35+
Skip CA check
8236
"""
83-
return extensionsByPriority()
84-
85-
86-
def skipCACheck():
8737
from DIRAC import gConfig
8838

89-
return gConfig.getValue("/DIRAC/Security/SkipCAChecks", "false").lower() in ("y", "yes", "true")
39+
return gConfig.getValue("/DIRAC/Security/SkipCAChecks", False)
9040

9141

92-
def useServerCertificate():
42+
def useServerCertificate() -> bool:
43+
"""
44+
Use server certificate
45+
"""
9346
from DIRAC import gConfig
9447

95-
return gConfig.getValue("/DIRAC/Security/UseServerCertificate", "false").lower() in ("y", "yes", "true")
48+
return gConfig.getValue("/DIRAC/Security/UseServerCertificate", False)

src/DIRAC/ConfigurationSystem/Client/Helpers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
__RCSID__ = "$Id$"
99

1010
from DIRAC.ConfigurationSystem.Client.Helpers.Path import *
11-
from DIRAC.ConfigurationSystem.Client.Helpers.CSGlobals import getCSExtensions, getInstalledExtensions, getVO
11+
from DIRAC.ConfigurationSystem.Client.Helpers.CSGlobals import getCSExtensions, getVO

src/DIRAC/TransformationSystem/scripts/dirac_production_runjoblocal.py

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,27 @@
33
Module created to run failed jobs locally on a CVMFS-configured machine.
44
It creates the necessary environment, downloads the necessary files, modifies the necessary
55
files and runs the job
6-
7-
Usage:
8-
dirac-production-runjoblocal [Data imput mode] [job ID]
9-
10-
Arguments:
11-
Download (Job ID): Defines data aquisition as DownloadInputData
12-
Protocol (Job ID): Defines data acquisition as InputDataByProtocol
136
"""
14-
from __future__ import absolute_import
15-
from __future__ import division
16-
from __future__ import print_function
17-
18-
__RCSID__ = "$Id$"
19-
207
import os
218
import shutil
229
import ssl
2310

11+
from xml.etree import ElementTree as et
12+
2413
from urllib.request import urlopen
2514

15+
from DIRAC.Interfaces.API.Dirac import Dirac
16+
from DIRAC.Core.Utilities.File import mkDir
2617
from DIRAC.Core.Utilities.DIRACScript import DIRACScript as Script
18+
from DIRAC.ConfigurationSystem.Client.Helpers.CSGlobals import getVO, getSetup
19+
from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData
2720

2821

2922
def __runSystemDefaults(jobID, vo):
3023
"""
3124
Creates the environment for running the job and returns
3225
the path for the other functions.
33-
3426
"""
35-
from DIRAC.Core.Utilities.File import mkDir
36-
3727
tempdir = str(vo) + "job" + str(jobID) + "temp"
3828
mkDir(tempdir)
3929
basepath = os.getcwd()
@@ -44,10 +34,7 @@ def __downloadJobDescriptionXML(jobID, basepath):
4434
"""
4535
Downloads the jobDescription.xml file into the temporary directory
4636
created.
47-
4837
"""
49-
from DIRAC.Interfaces.API.Dirac import Dirac
50-
5138
jdXML = Dirac()
5239
jdXML.getInputSandbox(jobID, basepath)
5340

@@ -56,24 +43,18 @@ def __modifyJobDescription(jobID, basepath, downloadinputdata):
5643
"""
5744
Modifies the jobDescription.xml to, instead of DownloadInputData, it
5845
uses InputDataByProtocol
59-
6046
"""
61-
from DIRAC import S_OK
62-
6347
if not downloadinputdata:
64-
from xml.etree import ElementTree as et
65-
6648
archive = et.parse(basepath + "InputSandbox" + str(jobID) + os.path.sep + "jobDescription.xml")
6749
for element in archive.iter():
6850
if element.text == "DIRAC.WorkloadManagementSystem.Client.DownloadInputData":
6951
element.text = "DIRAC.WorkloadManagementSystem.Client.InputDataByProtocol"
7052
archive.write(basepath + "InputSandbox" + str(jobID) + os.path.sep + "jobDescription.xml")
7153

7254

73-
def __downloadPilotScripts(basepath, diracpath):
55+
def __downloadPilotScripts():
7456
"""
7557
Downloads the scripts necessary to configure the pilot
76-
7758
"""
7859

7960
context = ssl._create_unverified_context()
@@ -105,11 +86,6 @@ def __configurePilot(basepath, vo):
10586
This method was created specifically for LHCb pilots, more info
10687
about othe VOs is needed to make it more general.
10788
"""
108-
109-
from DIRAC.ConfigurationSystem.Client.Helpers.CSGlobals import getVO, getSetup
110-
from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData
111-
112-
vo = getVO()
11389
currentSetup = getSetup()
11490
masterCS = gConfigurationData.getMasterServer()
11591

@@ -131,7 +107,6 @@ def __configurePilot(basepath, vo):
131107
def __runJobLocally(jobID, basepath, vo):
132108
"""
133109
Runs the job!
134-
135110
"""
136111
ipr = __import__(str(vo) + "DIRAC.Interfaces.API." + str(vo) + "Job", globals(), locals(), [str(vo) + "Job"], -1)
137112
voJob = getattr(ipr, str(vo) + "Job")
@@ -144,26 +119,22 @@ def __runJobLocally(jobID, basepath, vo):
144119

145120
@Script()
146121
def main():
147-
Script.registerSwitch("D:", "Download=", "Defines data acquisition as DownloadInputData")
148-
Script.registerSwitch("P:", "Protocol=", "Defines data acquisition as InputDataByProtocol")
149-
Script.parseCommandLine(ignoreErrors=False)
122+
Script.registerSwitch("D:", "Download=", "Set jobID here. Defines data acquisition as DownloadInputData")
123+
Script.registerSwitch("I:", "Protocol=", "Set jobID here. Defines data acquisition as InputDataByProtocol")
124+
switches, args = Script.parseCommandLine(ignoreErrors=False)
150125

151126
_downloadinputdata = False
152127
_jobID = None
153128

154-
for switch in Script.getUnprocessedSwitches():
129+
for switch in switches:
155130
if switch[0] in ("D", "Download"):
156131
_downloadinputdata = True
157132
_jobID = switch[1]
158133
if switch[0] in ("I", "Protocol"):
159134
_downloadinputdata = False
160135
_jobID = switch[1]
161136

162-
from DIRAC.ConfigurationSystem.Client.Helpers.CSGlobals import Extensions
163-
164-
ext = Extensions()
165-
_vo = ext.getCSExtensions()[0]
166-
_diracPath = Extensions().getExtensionPath("DIRAC")
137+
_vo = getVO()
167138
_dir = os.path.expanduser("~") + os.path.sep
168139
try:
169140
_path = __runSystemDefaults(_jobID, _vo)
@@ -172,12 +143,11 @@ def main():
172143

173144
__modifyJobDescription(_jobID, _path, _downloadinputdata)
174145

175-
__downloadPilotScripts(_path, _diracPath)
146+
__downloadPilotScripts()
176147

177148
__configurePilot(_path, _vo)
178149

179150
__runJobLocally(_jobID, _path, _vo)
180-
181151
finally:
182152
os.chdir(_dir)
183153
os.rename(_dir + ".dirac.cfg.old", _dir + ".dirac.cfg")

0 commit comments

Comments
 (0)