Esempio n. 1
0
def main():
    Script.registerSwitch("t", "test", "Only test. Don't commit changes")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(
        "UserCfg:  Cfg FileName with Users as sections containing"
        "DN, Groups, and other properties as options")
    Script.parseCommandLine(ignoreErrors=True)

    args = Script.getExtraCLICFGFiles()

    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()
    exitCode = 0
    testOnly = False
    errorList = []

    for unprocSw in Script.getUnprocessedSwitches():
        if unprocSw[0] in ("t", "test"):
            testOnly = True

    try:
        usersCFG = CFG().loadFromFile(args[0])
    except Exception as e:
        errorList.append("file open",
                         "Can't parse file %s: %s" % (args[0], str(e)))
        errorCode = 1
    else:
        if not diracAdmin.csSyncUsersWithCFG(usersCFG):
            errorList.append(("modify users", "Cannot sync with %s" % args[0]))
            exitCode = 255

    if not exitCode and not testOnly:
        result = diracAdmin.csCommitChanges()
        if not result["OK"]:
            errorList.append(("commit", result["Message"]))
            exitCode = 255

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRAC.exit(exitCode)
Esempio n. 2
0
def main():
    cliParams = Params()

    Script.disableCS()
    Script.registerSwitch(
        "e", "exitOnError",
        "flag to exit on error of any component installation",
        cliParams.setExitOnError)

    Script.addDefaultOptionValue("/DIRAC/Security/UseServerCertificate", "yes")
    Script.addDefaultOptionValue("LogLevel", "INFO")
    Script.parseCommandLine()
    args = Script.getExtraCLICFGFiles()

    if len(args) > 1:
        Script.showHelp(exitCode=1)

    cfg = None
    if len(args):
        cfg = args[0]
    from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller

    gComponentInstaller.exitOnError = cliParams.exitOnError

    result = gComponentInstaller.setupSite(Script.localCfg, cfg)
    if not result["OK"]:
        print("ERROR:", result["Message"])
        exit(-1)

    result = gComponentInstaller.getStartupComponentStatus([])
    if not result["OK"]:
        print("ERROR:", result["Message"])
        exit(-1)

    print("\nStatus of installed components:\n")
    result = gComponentInstaller.printStartupStatus(result["Value"])
    if not result["OK"]:
        print("ERROR:", result["Message"])
        exit(-1)