示例#1
0
    def _loadWebAppCFGFiles(self, extension):
        """
        Load WebApp/web.cfg definitions

        :param str extension: the module name of the extension of WebAppDirac for example: LHCbWebDIRAC
        """
        webCFG = CFG()
        for modName in ["WebAppDIRAC", extension]:
            cfgPath = join(self._destination, modName, "WebApp", "web.cfg")
            if not isfile(cfgPath):
                logging.info(f"Web configuration file {cfgPath} does not exists!")
                continue
            try:
                modCFG = CFG().loadFromFile(cfgPath)
            except Exception as e:
                logging.error(f"Could not load {cfgPath}: {e}")
                continue
            logging.info(f"Loaded {cfgPath}")
            expl = ["/WebApp"]
            while expl:
                current = expl.pop(0)
                if not modCFG.isSection(current):
                    continue
                if modCFG.getOption(f"{current}/AbsoluteDefinition", False):
                    logging.info(f"{modName}:{current} is an absolute definition")
                    try:
                        webCFG.deleteKey(current)
                    except Exception:
                        pass
                    modCFG.deleteKey(f"{current}/AbsoluteDefinition")
                else:
                    expl += [f"{current}/{sec}" for sec in modCFG[current].listSections()]
            # Add the modCFG
            webCFG = webCFG.mergeWith(modCFG)
        return webCFG
示例#2
0
def main():
    Script.disableCS()

    Script.registerSwitch("t:", "type=",
                          "Installation type. 'server' by default.",
                          setInstallType)
    Script.parseCommandLine(ignoreErrors=True)

    # Collect all the requested python modules to install
    reqDict = {}
    for entry in os.listdir(rootPath):
        if len(entry) < 5 or entry.find("DIRAC") != len(entry) - 5:
            continue
        reqFile = os.path.join(rootPath, entry, "releases.cfg")
        try:
            with open(reqFile, "r") as extfd:
                reqCFG = CFG().loadFromBuffer(extfd.read())
        except BaseException:
            gLogger.verbose("%s not found" % reqFile)
            continue
        reqList = reqCFG.getOption(
            "/RequiredExternals/%s" % instType.capitalize(), [])
        if not reqList:
            gLogger.verbose(
                "%s does not have requirements for %s installation" %
                (entry, instType))
            continue
        for req in reqList:
            reqName = False
            reqCond = ""
            for cond in ("==", ">="):
                iP = cond.find(req)
                if iP > 0:
                    reqName = req[:iP]
                    reqCond = req[iP:]
                    break
            if not reqName:
                reqName = req
            if reqName not in reqDict:
                reqDict[reqName] = (reqCond, entry)
            else:
                gLogger.notice("Skipping %s, it's already requested by %s" %
                               (reqName, reqDict[reqName][1]))

    if not reqDict:
        gLogger.notice("No extra python module requested to be installed")
        sys.exit(0)

    for reqName in reqDict:
        package = "%s%s" % (reqName, reqDict[reqName][0])
        gLogger.notice("Requesting installation of %s" % package)
        status, output = pipInstall(package)
        if status != 0:
            gLogger.error(output)
        else:
            gLogger.notice("Successfully installed %s" % package)