From 4ef079272a4c8d6e17f687a50a39de4241596cd1 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Thu, 14 Nov 2013 16:11:01 +0000 Subject: Replace print statements with six.print_() calls Using the print statement as though it was a function leads to incorrect behaviour in a python2 runtime. E.g.: print() print( "Some examples:") print() Produces: () Some examples: () Instead replace use of the print keyword with a call to the six module's print_() function. Fixes Issue #219 Signed-off-by: Bryn M. Reeves --- sos/policies/__init__.py | 5 +++-- sos/sosreport.py | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py index e666f0c7..46b41e0c 100644 --- a/sos/policies/__init__.py +++ b/sos/policies/__init__.py @@ -17,6 +17,7 @@ from sos.plugins import IndependentPlugin from sos import _sos as _ import hashlib from textwrap import fill +from six import print_ def import_policy(name): policy_fqname = "sos.policies.%s" % name @@ -354,9 +355,9 @@ No changes will be made to system configuration. quiet mode""" if not self.commons['cmdlineopts'].quiet: if msg: - print(msg) + print_(msg) else: - print() + print_() def get_msg(self): diff --git a/sos/sosreport.py b/sos/sosreport.py index 3605b81f..f297b670 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -58,6 +58,7 @@ if six.PY3: from configparser import ConfigParser else: from ConfigParser import ConfigParser +from six import print_ class TempFileUtil(object): @@ -91,15 +92,15 @@ class OptionParserExtended(OptionParser): def print_help(self, out=sys.stdout): """ Prints help content including examples """ OptionParser.print_help(self, out) - print() - print( "Some examples:") - print() - print( " enable cluster plugin only and collect dlm lockdumps:") - print( " # sosreport -o cluster -k cluster.lockdump") - print() - print( " disable memory and samba plugins, turn off rpm -Va collection:") - print( " # sosreport -n memory,samba -k rpm.rpmva=off") - print() + print_() + print_( "Some examples:") + print_() + print_( " enable cluster plugin only and collect dlm lockdumps:") + print_( " # sosreport -o cluster -k cluster.lockdump") + print_() + print_( " disable memory and samba plugins, turn off rpm -Va collection:") + print_( " # sosreport -n memory,samba -k rpm.rpmva=off") + print_() class SosOption(Option): """Allow to specify comma delimited list of plugins""" @@ -631,7 +632,7 @@ class SoSReport(object): import traceback, pdb # we are NOT in interactive mode, print the exception... traceback.print_exception(etype, eval_, etrace, limit=2, file=sys.stdout) - print + print_() # ...then start the debugger in post-mortem mode. pdb.pm() -- cgit