From 8e282cf3709a97fbcdcc3ab81fbd088916aedf0a Mon Sep 17 00:00:00 2001 From: fstagni Date: Fri, 16 Jun 2023 08:52:14 +0200 Subject: [PATCH] sweep: #6945 print a warning message when no CFG file is found --- .../Client/LocalConfiguration.py | 35 +++++++++++++++---- .../private/ConfigurationData.py | 3 +- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/DIRAC/ConfigurationSystem/Client/LocalConfiguration.py b/src/DIRAC/ConfigurationSystem/Client/LocalConfiguration.py index 2f2d5eb191a..3613817a5fe 100755 --- a/src/DIRAC/ConfigurationSystem/Client/LocalConfiguration.py +++ b/src/DIRAC/ConfigurationSystem/Client/LocalConfiguration.py @@ -413,8 +413,8 @@ def __parseCommandLine(self): groupArgs = [] step = 0 - for i in range(len(self.commandArgumentList)): - argMarking, description, mandatory, values, default = self.commandArgumentList[i] + for i, commandArgument in enumerate(self.commandArgumentList): + argMarking, description, mandatory, values, default = commandArgument # Check whether the required arguments are given in the command line if len(self.commandArgList) <= (i + step): @@ -434,7 +434,7 @@ def __parseCommandLine(self): if values and cArg not in values: gLogger.fatal( "Error when parsing command line arguments: " - '"%s" does not match the allowed values for %s' % (cArg, argMarking) + f'"{cArg}" does not match the allowed values for {argMarking}' ) self.showHelp(exitCode=1) @@ -445,30 +445,51 @@ def __parseCommandLine(self): def __loadCFGFiles(self): """ Loads possibly several cfg files, in order: - 1. ~/.dirac.cfg - 2. cfg files pointed by DIRACSYSCONFIG env variable (comma-separated) + 1. cfg files pointed by DIRACSYSCONFIG env variable (comma-separated) + 2. ~/.dirac.cfg 3. cfg files specified in addCFGFile calls 4. cfg files that come from the command line """ errorsList = [] + foundCFGFile = False + + # 1. $DIRACSYSCONFIG if "DIRACSYSCONFIG" in os.environ: diracSysConfigFiles = os.environ["DIRACSYSCONFIG"].replace(" ", "").split(",") for diracSysConfigFile in reversed(diracSysConfigFiles): gLogger.debug(f"Loading file from DIRACSYSCONFIG {diracSysConfigFile}") + if os.path.isfile(diracSysConfigFile): + foundCFGFile = True gConfigurationData.loadFile(diracSysConfigFile) + + # 2. ~/.dirac.cfg + if os.path.isfile(os.path.expanduser("~/.dirac.cfg")): + foundCFGFile = True gConfigurationData.loadFile(os.path.expanduser("~/.dirac.cfg")) + + # 3. cfg files specified in addCFGFile calls for fileName in self.additionalCFGFiles: - gLogger.debug(f"Loading file {fileName}") + if os.path.isfile(fileName): + foundCFGFile = True + gLogger.debug(f"Loading file {fileName}") retVal = gConfigurationData.loadFile(fileName) if not retVal["OK"]: gLogger.debug(f"Could not load file {fileName}: {retVal['Message']}") errorsList.append(retVal["Message"]) + + # 4. cfg files that come from the command line for fileName in self.cliAdditionalCFGFiles: - gLogger.debug(f"Loading file {fileName}") + if os.path.isfile(fileName): + foundCFGFile = True + gLogger.debug(f"Loading file {fileName}") retVal = gConfigurationData.loadFile(fileName) if not retVal["OK"]: gLogger.debug(f"Could not load file {fileName}: {retVal['Message']}") errorsList.append(retVal["Message"]) + + if not foundCFGFile: + gLogger.warn("No CFG file loaded, was that intentional?") + return errorsList def __addUserDataToConfiguration(self): diff --git a/src/DIRAC/ConfigurationSystem/private/ConfigurationData.py b/src/DIRAC/ConfigurationSystem/private/ConfigurationData.py index 3df5676ce98..6f9abb1c8cf 100755 --- a/src/DIRAC/ConfigurationSystem/private/ConfigurationData.py +++ b/src/DIRAC/ConfigurationSystem/private/ConfigurationData.py @@ -7,9 +7,10 @@ import _thread import time import datetime -import DIRAC from diraccfg import CFG + +import DIRAC from DIRAC.Core.Utilities.File import mkDir from DIRAC.Core.Utilities import List from DIRAC.Core.Utilities.ReturnValues import S_OK, S_ERROR