# or func_output().
#
+from __future__ import print_function
+
import getopt
import re
import os
def output(x):
global SILENT_MODE
if not SILENT_MODE:
- print x
+ print(x)
def output_ts(x):
elif 'func' in v:
try:
s = v['func'](cap)
- except Exception, e:
+ except Exception as e:
s = str(e)
if check_space(cap, k, len(s)):
v['output'] = StringIOmtime(s)
collect_all_info = True
if '--help' in sys.argv:
- print """\
+ print("""
%(argv0)s: create status report bundles to assist in problem diagnosis
usage: %(argv0)s OPTIONS
--outfd=FD write output to FD (requires --output=tar)
--unlimited ignore default limits on sizes of data collected
--debug print ovs-bugtool debug info on stdout\
-""" % {'argv0': sys.argv[0]}
+""" % {'argv0': sys.argv[0]})
sys.exit(0)
# we need access to privileged files, exit if we are not running as root
if os.getuid() != 0:
- print >>sys.stderr, "Error: ovs-bugtool must be run as root"
+ print("Error: ovs-bugtool must be run as root", file=sys.stderr)
return 1
output_file = None
argv, 'sy', ['capabilities', 'silent', 'yestoall', 'entries=',
'output=', 'outfd=', 'outfile=', 'all', 'unlimited',
'debug', 'ovs', 'log-days='])
- except getopt.GetoptError, opterr:
- print >>sys.stderr, opterr
+ except getopt.GetoptError as opterr:
+ print(opterr, file=sys.stderr)
return 2
try:
if v in ['tar', 'tar.bz2', 'tar.gz', 'zip']:
output_type = v
else:
- print >>sys.stderr, "Invalid output format '%s'" % v
+ print("Invalid output format '%s'" % v, file=sys.stderr)
return 2
# "-s" or "--silent" means suppress output (except for the final
old = fcntl.fcntl(output_fd, fcntl.F_GETFD)
fcntl.fcntl(output_fd, fcntl.F_SETFD, old | fcntl.FD_CLOEXEC)
except:
- print >>sys.stderr, "Invalid output file descriptor", output_fd
+ print("Invalid output file descriptor", output_fd,
+ file=sys.stderr)
return 2
if k == '--outfile':
log_days = int(v)
if len(params) != 1:
- print >>sys.stderr, "Invalid additional arguments", str(params)
+ print("Invalid additional arguments", str(params), file=sys.stderr)
return 2
if output_fd != -1 and output_type != 'tar':
- print >>sys.stderr, "Option '--outfd' only valid with '--output=tar'"
+ print("Option '--outfd' only valid with '--output=tar'",
+ file=sys.stderr)
return 2
if output_fd != -1 and output_file is not None:
- print >>sys.stderr, "Cannot set both '--outfd' and '--outfile'"
+ print("Cannot set both '--outfd' and '--outfile'", file=sys.stderr)
return 2
if output_file is not None and not unlimited_data:
make_zip(subdir, output_file)
if dbg:
- print >>sys.stderr, "Category sizes (max, actual):\n"
+ print("Category sizes (max, actual):\n", file=sys.stderr)
for c in caps.keys():
- print >>sys.stderr, " %s (%d, %d)" % (c, caps[c][MAX_SIZE],
- cap_sizes[c])
+ print(" %s (%d, %d)" % (c, caps[c][MAX_SIZE], cap_sizes[c]),
+ file=sys.stderr)
cleanup_ovsdb()
return 0
filename = "%s/%s.%s" % (BUG_DIR, subdir, suffix)
else:
filename = output_file
- old_umask = os.umask(0077)
+ old_umask = os.umask(0o077)
tf = tarfile.open(filename, mode)
os.umask(old_umask)
else:
if output_fd == -1:
output('Writing tarball %s successful.' % filename)
if SILENT_MODE:
- print filename
+ print(filename)
def make_zip(subdir, output_file):
filename = "%s/%s.zip" % (BUG_DIR, subdir)
else:
filename = output_file
- old_umask = os.umask(0077)
+ old_umask = os.umask(0o077)
zf = zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED)
os.umask(old_umask)
output('Writing archive %s successful.' % filename)
if SILENT_MODE:
- print filename
+ print(filename)
def make_inventory(inventory, subdir):
"ns", CAP_XML_ROOT, None)
map(lambda key: capability(document, key),
[k for k in caps.keys() if not caps[k][HIDDEN]])
- print document.toprettyxml()
+ print(document.toprettyxml())
def capability(document, key):
return disks
-class ProcOutput:
+class ProcOutput(object):
debug = False
def __init__(self, command, max_time, inst=None, filter=None,
try:
sys.exit(main())
except KeyboardInterrupt:
- print "\nInterrupted."
+ print("\nInterrupted.")
sys.exit(3)