當前位置: 首頁>>代碼示例>>Python>>正文


Python GaussLog.printMessage方法代碼示例

本文整理匯總了Python中script.util.GaussLog.GaussLog.printMessage方法的典型用法代碼示例。如果您正苦於以下問題:Python GaussLog.printMessage方法的具體用法?Python GaussLog.printMessage怎麽用?Python GaussLog.printMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在script.util.GaussLog.GaussLog的用法示例。


在下文中一共展示了GaussLog.printMessage方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: executeCommand

# 需要導入模塊: from script.util.GaussLog import GaussLog [as 別名]
# 或者: from script.util.GaussLog.GaussLog import printMessage [as 別名]
def executeCommand():
    """
    """
    failedNodes = ""
    succeedNodes = ""
    try:
        command = (g_opts.cmd.strip()).split(" ")
        if len(command) > 1:
            GaussLog.exitWithError("Parameter -c input error, only need command.")
        checkCmd = "which %s" % command[0]
        (status, output) = g_sshTool.getSshStatusOutput(checkCmd)
        for node in status.keys():
            if status[node] != 0:
                failedNodes += "%s " % node
            else:
                succeedNodes += "%s " % node
        if failedNodes != "":
            GaussLog.exitWithError(
                "Command %s not exist or not have executable permissions on %s." % (command, failedNodes)
            )
        failedNodes = ""
        succeedNodes = ""
        executeCmd = g_opts.cmd + " " + g_opts.parameterlist
        #############################################################
        cmdFile = "%s/ClusterCall_%d.sh" % (DefaultValue.getTmpDirFromEnv(), os.getpid())
        cmdCreateFile = "touch %s" % cmdFile
        (status, output) = commands.getstatusoutput(cmdCreateFile)
        if status != 0:
            GaussLog.exitWithError("Touch file %s failed!" % cmdFile)

        cmdFileMod = "chmod 640 %s" % cmdFile
        (status, output) = commands.getstatusoutput(cmdFileMod)
        if status != 0:
            GaussLog.exitWithError("Chmod file %s failed!" % cmdFile)

        fp = open(cmdFile, "a")
        fp.write("#!/bin/sh")
        fp.write(os.linesep)
        fp.write("%s" % (executeCmd))
        fp.write(os.linesep)
        fp.flush()
        fp.close()

        ##############################################################
        cmdDir = DefaultValue.getTmpDirFromEnv()
        g_sshTool.scpFiles(cmdFile, cmdDir)
        cmdExecute = "sh %s" % cmdFile
        (status, output) = g_sshTool.getSshStatusOutput(cmdExecute)

        for node in status.keys():
            if status[node] != 0:
                failedNodes += "%s " % node
            else:
                succeedNodes += "%s " % node
        if failedNodes != "" and succeedNodes != "":
            GaussLog.printMessage("Execute command failed on %s." % failedNodes)
            GaussLog.printMessage("Execute command succeed on %s.\n" % succeedNodes)
        elif failedNodes == "":
            GaussLog.printMessage("Execute command succeed on all nodes.\n")
        elif succeedNodes == "":
            GaussLog.printMessage("Execute command failed on all nodes.\n")

        GaussLog.printMessage("Output:\n%s" % output)

        cmdFileRm = "rm %s" % cmdFile
        g_sshTool.executeCommand(cmdFileRm, "rm cmdFile")

    except Exception, e:
        if fp:
            fp.close()
        cmdFileRm = "rm %s" % cmdFile
        g_sshTool.executeCommand(cmdFileRm, "rm cmdFile")
        GaussLog.exitWithError(str(e))
開發者ID:jianhuiz,項目名稱:cf-apps,代碼行數:75,代碼來源:ClusterCall.py


注:本文中的script.util.GaussLog.GaussLog.printMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。