def parseCommandLine():
    """
    parse command line
    input : NA
    output: NA
    """
    try:
        opts, args = getopt.getopt(sys.argv[1:], "U:R:C:l:X:", ["help"])
    except getopt.GetoptError as e:
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e))
    if (len(args) > 0):
        usage()
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] %
                               str(args[0]))

    global g_opts
    g_opts = CmdOptions()

    parameter_map = {
        "-U": g_opts.userInfo,
        "-R": g_opts.installPath,
        "-l": g_opts.logFile,
        "-X": g_opts.clusterConfig
    }
    parameter_keys = parameter_map.keys()
    for key, value in opts:
        if (key == "--help"):
            usage()
            sys.exit(0)
        elif (key in parameter_keys):
            parameter_map[key] = value
        elif (key == "-C"):
            g_opts.confParameters.append(value)
        else:
            GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % value)
        Parameter.checkParaVaild(key, value)

    g_opts.userInfo = parameter_map["-U"]
    g_opts.installPath = parameter_map["-R"]
    if os.path.islink(
            g_opts.installPath) or not os.path.exists(g_opts.installPath):
        versionFile = VersionInfo.get_version_file()
        commitid = VersionInfo.get_version_info(versionFile)[2]
        g_opts.installPath = g_opts.installPath + "_" + commitid
    g_opts.logFile = parameter_map["-l"]
    g_opts.clusterConfig = parameter_map["-X"]
Exemple #2
0
 def deleteSymbolicAppPath(self):
     """
     function: delete symbolic app path
     input  : NA
     output : NA
     """
     self.context.logger.debug("Delete symbolic link $GAUSSHOME.")
     versionFile = VersionInfo.get_version_file()
     commitid = VersionInfo.get_version_info(versionFile)[2]
     cmd = "rm -rf %s" % self.context.clusterInfo.appPath
     self.context.clusterInfo.appPath = \
         self.context.clusterInfo.appPath + "_" + commitid
     DefaultValue.execCommandWithMode(cmd, "Delete symbolic link",
                                      self.context.sshTool,
                                      self.context.isSingle,
                                      self.context.mpprcFile)
     self.context.logger.debug(
         "Successfully delete symbolic link $GAUSSHOME, cmd: %s." % cmd)
def createLinkToApp():
    """
    function: create link to app
    input  : NA
    output : NA
    """
    if g_opts.upgrade:
        g_opts.logger.log("Under upgrade process,"
                          " no need to create symbolic link.")
        return
    g_opts.logger.debug("Created symbolic link to $GAUSSHOME with commitid.")
    gaussHome = DefaultValue.getInstallDir(g_opts.user)
    if gaussHome == "":
        raise Exception(ErrorCode.GAUSS_518["GAUSS_51800"] % "$GAUSSHOME")
    versionFile = VersionInfo.get_version_file()
    commitid = VersionInfo.get_version_info(versionFile)[2]
    actualPath = gaussHome + "_" + commitid
    if os.path.exists(gaussHome):
        if not os.path.islink(gaussHome):
            raise Exception(ErrorCode.GAUSS_502["GAUSS_50200"] % gaussHome
                            + " Cannot create symbolic link,"
                              " please rename or delete it.")
        else:
            if os.path.realpath(gaussHome) == actualPath:
                g_opts.logger.log("$GAUSSHOME points to %s, no need to create"
                                  " symbolic link." % actualPath)
                return

    cmd = "ln -snf %s %s" % (actualPath, gaussHome)
    g_opts.logger.log("Command for creating symbolic link: %s." % cmd)
    (status, output) = subprocess.getstatusoutput(cmd)
    if status != 0:
        g_opts.logger.log(output)
        g_opts.logger.logExit(ErrorCode.GAUSS_501["GAUSS_50107"] % "app.")
    g_opts.logger.debug("Successfully created symbolic link to"
                        " $GAUSSHOME with commitid.")