gfs2_trace: update for python3
PATCH 1/2 gfs2_trace: update for python3
--- gfs2/scripts/gfs2_trace | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
gfs2/scripts/gfs2_trace +9 -9
@@ -119,7 +119,7 @@ class FileUtils: fout.write(data + "\n") fout.close() return True - except UnicodeEncodeError, e: + except UnicodeEncodeError as e: message = "There was a unicode encode error writing to the file: %s." %(pathToFilename) logging.getLogger(MAIN_LOGGER_NAME).error(message) return False
@@ -319,7 +319,7 @@ class TraceEvents: @return: Returns a list of all the trace event names found. @rtype: Array """ - return self.__traceEventsMap.keys() + return list(self.__traceEventsMap.keys()) def getTraceEvent(self, traceEventName): """
@@ -330,7 +330,7 @@ class TraceEvents: match is found then None is returned. @rtype: TraceEvent """ - if (self.__traceEventsMap.has_key(traceEventName)): + if (traceEventName in self.__traceEventsMap): return self.__traceEventsMap.get(traceEventName) return None
@@ -555,7 +555,7 @@ class OptionParserExtended(OptionParser): exampleMessage += "# %s -N -e gfs2_demote_rq,gfs2_glock_state_change,gfs2_promote -c /tmp/gfs2_trace.log\n" %(self.__commandName) self.print_version() OptionParser.print_help(self) - print exampleMessage + print(exampleMessage) class ExtendOption (Option): """
@@ -699,9 +699,9 @@ if __name__ == "__main__": # Disable logging to console except for debug when we print into information to console. logging.disable(logging.CRITICAL) if (len(traceEventsString) > 0): - print "trace event name trace event status" - print "---------------- ------------------" - print traceEventsString.rstrip() + print("trace event name trace event status") + print("---------------- ------------------") + print(traceEventsString.rstrip()) exitScript() # ####################################################################### # Enable or Disable Trace Events
@@ -758,7 +758,7 @@ if __name__ == "__main__": fout.close() message = "The data was written to this file: %s" %(cmdLineOpts.pathToOutputFilename) logging.getLogger(MAIN_LOGGER_NAME).info(message) - except UnicodeEncodeError, e: + except UnicodeEncodeError as e: message = "There was a unicode encode error writing to the file: %s." %(cmdLineOpts.pathToOutputFilename) logging.getLogger(MAIN_LOGGER_NAME).error(message) except IOError:
@@ -780,7 +780,7 @@ if __name__ == "__main__": message = "There was an error creating the tarfile: %s." %(pathToTarFilename) logging.getLogger(MAIN_LOGGER_NAME).error(message) except KeyboardInterrupt: - print "" + print("") message = "This script will exit since control-c was executed by end user." logging.getLogger(MAIN_LOGGER_NAME).error(message) exitScript()
Signature · 1 line
2.17.0
PATCH 2/2 gfs2_lockcapture: update for python3
--- gfs2/scripts/gfs2_lockcapture | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-)
gfs2/scripts/gfs2_lockcapture +18 -14
@@ -75,7 +75,7 @@ class ClusterNode: """ rString = "" rString += "%s:%s(id:%d)" %(self.getClusterName(), self.getClusterNodeName(), self.getClusterNodeID()) - fsLabels = self.__mapOfMountedFilesystemLabels.keys() + fsLabels = list(self.__mapOfMountedFilesystemLabels.keys()) fsLabels.sort() for fsLabel in fsLabels: rString += "\n\t%s --> %s" %(fsLabel, self.__mapOfMountedFilesystemLabels.get(fsLabel))
@@ -126,10 +126,10 @@ class ClusterNode: """ # If true will prepend the cluster name to gfs2 fs name if (includeClusterName): - return self.__mapOfMountedFilesystemLabels.keys() + return list(self.__mapOfMountedFilesystemLabels.keys()) else: listOfGFS2MountedFilesystemLabels = [] - for fsLabel in self.__mapOfMountedFilesystemLabels.keys(): + for fsLabel in list(self.__mapOfMountedFilesystemLabels.keys()): fsLabelSplit = fsLabel.split(":", 1) if (len(fsLabelSplit) == 2): listOfGFS2MountedFilesystemLabels.append(fsLabelSplit[1])
@@ -146,7 +146,7 @@ class ClusterNode: @rtype: Map """ mapOfGFS2MountedFilesystemPaths = {} - for fsLabel in self.__mapOfMountedFilesystemLabels.keys(): + for fsLabel in list(self.__mapOfMountedFilesystemLabels.keys()): value = self.__mapOfMountedFilesystemLabels.get(fsLabel) mountPoint = value.split("type", 1)[0].split("on")[1] if (len(mountPoint) > 0):
@@ -238,7 +238,7 @@ def runCommandOutput(command, listOfCommandOptions, standardOut=subprocess.PIPE, message += "\n%s" %(stderr.rstrip()) logging.getLogger(MAIN_LOGGER_NAME).error(message) return None - return stdout.strip().rstrip() + return stdout.decode().strip().rstrip() def writeToFile(pathToFilename, data, appendToFile=True, createFile=False): """
@@ -271,7 +271,7 @@ def writeToFile(pathToFilename, data, appendToFile=True, createFile=False): fout.write(data + "\n") fout.close() return True - except UnicodeEncodeError, e: + except UnicodeEncodeError as e: message = "There was a unicode encode error writing to the file: %s." %(pathToFilename) logging.getLogger(MAIN_LOGGER_NAME).error(message) return False
@@ -638,13 +638,13 @@ def getClusterNode(listOfGFS2Names): mapOfMountedFilesystemLabels = getLabelMapForMountedFilesystems(clusterName, getMountedGFS2Filesystems()) # These will be the GFS2 filesystems that will have their lockdump information gathered. if (len(listOfGFS2Names) > 0): - for label in mapOfMountedFilesystemLabels.keys(): + for label in list(mapOfMountedFilesystemLabels.keys()): foundMatch = False for gfs2FSName in listOfGFS2Names: if ((gfs2FSName == label) or ("%s:%s"%(clusterName, gfs2FSName) == label)): foundMatch = True break - if ((not foundMatch) and (mapOfMountedFilesystemLabels.has_key(label))): + if ((not foundMatch) and (label in mapOfMountedFilesystemLabels)): del(mapOfMountedFilesystemLabels[label]) # Cast the node id to an int, and default is 0 if node is not found or # not castable.
@@ -680,7 +680,7 @@ def parse_dlm_ls(dlm_ls): dlmToolLSMap = dict.fromkeys(dlmToolLSKeys) lines = section.split("\n") for line in lines: - for dlmToolLSKey in dlmToolLSMap.keys(): + for dlmToolLSKey in list(dlmToolLSMap.keys()): if (line.startswith(dlmToolLSKey)): value = line.replace(dlmToolLSKey, " ", 1).strip().rstrip() dlmToolLSMap[dlmToolLSKey] = value
@@ -1181,7 +1181,7 @@ class OptionParserExtended(OptionParser): examplesMessage += "\nthe data collected in the output directory: /tmp and all the questions will be answered with yes.\n" examplesMessage += "\n# %s -r 2 -s 25 -P -o /tmp\n" %(self.__commandName) OptionParser.print_help(self) - print examplesMessage + print(examplesMessage) class ExtendOption (Option): """
@@ -1316,8 +1316,8 @@ if __name__ == "__main__": logging.getLogger(MAIN_LOGGER_NAME).error(message) if (cmdLineOpts.enablePrintInfo): logging.disable(logging.CRITICAL) - print "List of all the mounted GFS2 filesystems that can have their lockdump data captured:" - print clusternode + print("List of all the mounted GFS2 filesystems that can have their lockdump data captured:") + print(clusternode) exitScript() # ####################################################################### # Verify they want to continue because this script will trigger sysrq events.
@@ -1328,7 +1328,11 @@ if __name__ == "__main__": prompt = " [y/n] " while True: sys.stdout.write(question + prompt) - choice = raw_input().lower() + try: # python2 compatible input + input = raw_input + except NameError: + pass + choice = input().lower() if (choice in valid): if (valid.get(choice)): # If yes, or y then exit loop and continue.
@@ -1508,7 +1512,7 @@ if __name__ == "__main__": logging.getLogger(MAIN_LOGGER_NAME).error(message) # ####################################################################### except KeyboardInterrupt: - print "" + print("") message = "This script will exit since control-c was executed by end user." logging.getLogger(MAIN_LOGGER_NAME).error(message) exitScript(errorCode=1)
Signature · 1 line
2.17.0
PATCH 1/2 gfs2_trace: update for python3
In reply to Valentin VidicBoth patches pushed - thanks!
Andy
PATCH 1/2 gfs2_trace: update for python3
Quoted 1 line · Andrew Price
Both patches pushed - thanks!
Great, thanks. Please also check the spelling patch from yesterday :)
Signature · 1 line
Valentin
PATCH 1/2 gfs2_trace: update for python3
Quoted 5 lines · Valentin Vidic
Quoted 1 line · Andrew Price
Both patches pushed - thanks!
Great, thanks. Please also check the spelling patch from yesterday :)
Also pushed. Thanks for the nudge :) (Overlooked because the subject didn't contain a component or "gfs2-utils").
Andy