Skip to content

Commit 5bd4c66

Browse files
authored
Merge pull request #6945 from fstagni/80_fixes56
[8.0] print a warning message when no CFG file is found
2 parents 9d8274a + bb280c6 commit 5bd4c66

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

src/DIRAC/ConfigurationSystem/Client/LocalConfiguration.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ def __parseCommandLine(self):
412412

413413
groupArgs = []
414414
step = 0
415-
for i in range(len(self.commandArgumentList)):
416-
argMarking, description, mandatory, values, default = self.commandArgumentList[i]
415+
for i, commandArgument in enumerate(self.commandArgumentList):
416+
argMarking, description, mandatory, values, default = commandArgument
417417

418418
# Check whether the required arguments are given in the command line
419419
if len(self.commandArgList) <= (i + step):
@@ -433,7 +433,7 @@ def __parseCommandLine(self):
433433
if values and cArg not in values:
434434
gLogger.fatal(
435435
"Error when parsing command line arguments: "
436-
'"%s" does not match the allowed values for %s' % (cArg, argMarking)
436+
f'"{cArg}" does not match the allowed values for {argMarking}'
437437
)
438438
self.showHelp(exitCode=1)
439439

@@ -444,30 +444,51 @@ def __parseCommandLine(self):
444444
def __loadCFGFiles(self):
445445
"""
446446
Loads possibly several cfg files, in order:
447-
1. ~/.dirac.cfg
448-
2. cfg files pointed by DIRACSYSCONFIG env variable (comma-separated)
447+
1. cfg files pointed by DIRACSYSCONFIG env variable (comma-separated)
448+
2. ~/.dirac.cfg
449449
3. cfg files specified in addCFGFile calls
450450
4. cfg files that come from the command line
451451
"""
452452
errorsList = []
453+
foundCFGFile = False
454+
455+
# 1. $DIRACSYSCONFIG
453456
if "DIRACSYSCONFIG" in os.environ:
454457
diracSysConfigFiles = os.environ["DIRACSYSCONFIG"].replace(" ", "").split(",")
455458
for diracSysConfigFile in reversed(diracSysConfigFiles):
456459
gLogger.debug(f"Loading file from DIRACSYSCONFIG {diracSysConfigFile}")
460+
if os.path.isfile(diracSysConfigFile):
461+
foundCFGFile = True
457462
gConfigurationData.loadFile(diracSysConfigFile)
463+
464+
# 2. ~/.dirac.cfg
465+
if os.path.isfile(os.path.expanduser("~/.dirac.cfg")):
466+
foundCFGFile = True
458467
gConfigurationData.loadFile(os.path.expanduser("~/.dirac.cfg"))
468+
469+
# 3. cfg files specified in addCFGFile calls
459470
for fileName in self.additionalCFGFiles:
460-
gLogger.debug(f"Loading file {fileName}")
471+
if os.path.isfile(fileName):
472+
foundCFGFile = True
473+
gLogger.debug(f"Loading file {fileName}")
461474
retVal = gConfigurationData.loadFile(fileName)
462475
if not retVal["OK"]:
463476
gLogger.debug(f"Could not load file {fileName}: {retVal['Message']}")
464477
errorsList.append(retVal["Message"])
478+
479+
# 4. cfg files that come from the command line
465480
for fileName in self.cliAdditionalCFGFiles:
466-
gLogger.debug(f"Loading file {fileName}")
481+
if os.path.isfile(fileName):
482+
foundCFGFile = True
483+
gLogger.debug(f"Loading file {fileName}")
467484
retVal = gConfigurationData.loadFile(fileName)
468485
if not retVal["OK"]:
469486
gLogger.debug(f"Could not load file {fileName}: {retVal['Message']}")
470487
errorsList.append(retVal["Message"])
488+
489+
if not foundCFGFile:
490+
gLogger.warn("No CFG file loaded, was that intentional?")
491+
471492
return errorsList
472493

473494
def __addUserDataToConfiguration(self):

src/DIRAC/ConfigurationSystem/private/ConfigurationData.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import _thread
88
import time
99
import datetime
10-
import DIRAC
1110

1211
from diraccfg import CFG
12+
13+
import DIRAC
1314
from DIRAC.Core.Utilities.File import mkDir
1415
from DIRAC.Core.Utilities import List
1516
from DIRAC.Core.Utilities.ReturnValues import S_OK, S_ERROR
@@ -251,15 +252,13 @@ def getAutoPublish(self):
251252
value = self.extractOptionFromCFG(f"{self.configurationPath}/AutoPublish", self.localCFG)
252253
if value and value.lower() in ("no", "false", "n"):
253254
return False
254-
else:
255-
return True
255+
return True
256256

257257
def getAutoSlaveSync(self):
258258
value = self.extractOptionFromCFG(f"{self.configurationPath}/AutoSlaveSync", self.localCFG)
259259
if value and value.lower() in ("no", "false", "n"):
260260
return False
261-
else:
262-
return True
261+
return True
263262

264263
def getServers(self):
265264
return list(self.remoteServerList)
@@ -290,8 +289,7 @@ def isMaster(self):
290289
value = self.extractOptionFromCFG(f"{self.configurationPath}/Master", self.localCFG)
291290
if value and value.lower() in ("yes", "true", "y"):
292291
return True
293-
else:
294-
return False
292+
return False
295293

296294
def getServicesPath(self):
297295
return "/Services"

0 commit comments

Comments
 (0)