summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorrodrigc <rodrigc@FreeBSD.org>2015-11-19 00:01:52 +0000
committerrodrigc <rodrigc@FreeBSD.org>2015-11-19 00:01:52 +0000
commitb75981aabc20f749744f5b8ca7e596ce3f276154 (patch)
treeac0a298319445487c327ba5ef036a39c5cc7318f /tools
parent6ae0b4f9be2b79ffde9848f96e414b5dcff599ad (diff)
downloadFreeBSD-src-b75981aabc20f749744f5b8ca7e596ce3f276154.zip
FreeBSD-src-b75981aabc20f749744f5b8ca7e596ce3f276154.tar.gz
Use print as a function for Python 3 [PEP 3105]
Import print_function from the __future__ module to activate this for Python 2. This works as far back as Python 2.6.0a2: https://docs.python.org/2/library/__future__.html [PEP 3105] https://www.python.org/dev/peps/pep-3105/
Diffstat (limited to 'tools')
-rw-r--r--tools/debugscripts/kld_deb.py7
-rw-r--r--tools/regression/netinet/ip_id_period/ip_id_period.py1
-rw-r--r--tools/sched/schedgraph.py33
-rwxr-xr-xtools/tools/shlib-compat/shlib-compat.py67
4 files changed, 56 insertions, 52 deletions
diff --git a/tools/debugscripts/kld_deb.py b/tools/debugscripts/kld_deb.py
index 5cf0167..167b3dc 100644
--- a/tools/debugscripts/kld_deb.py
+++ b/tools/debugscripts/kld_deb.py
@@ -26,6 +26,7 @@
#
# $FreeBSD$
+from __future__ import print_function
import sys
import os
import popen2
@@ -42,7 +43,7 @@ printre = re.compile(r'\$\d+\s+=\s+')
kld_debug_paths = []
if len(sys.argv[1:]) < 2:
- print 'Usage: prog <kerncomp> <core> [<paths>]'
+ print('Usage: prog <kerncomp> <core> [<paths>]')
sys.exit(1)
#Get the base modules path
@@ -129,7 +130,7 @@ for i in addr[1:]:
#Tell our user that we couldn't find it.
a = i[1]
sys.stderr.write("Can't find module: %s (addr: %d + header)\n" % (i[0], a))
- print '#add-symbol-file <file>', a, '#add header'
+ print('#add-symbol-file <file>', a, '#add header')
continue
#j = popen2.popen4('objdump --section-headers /boot/kernel/%s | grep "\.text"' % i[0])[0].read().strip().split()
@@ -137,6 +138,6 @@ for i in addr[1:]:
j = popen2.popen4('objdump --section-headers "%s" | grep "\.text"' % p)[0].read().strip().split()
try:
a = int(j[5], 16)
- print 'add-symbol-file', p, i[1] + a
+ print('add-symbol-file', p, i[1] + a)
except IndexError:
sys.stderr.write('Bad file: %s, address: %d\n' % (i[0], i[1]))
diff --git a/tools/regression/netinet/ip_id_period/ip_id_period.py b/tools/regression/netinet/ip_id_period/ip_id_period.py
index ba84321..c04f5a4 100644
--- a/tools/regression/netinet/ip_id_period/ip_id_period.py
+++ b/tools/regression/netinet/ip_id_period/ip_id_period.py
@@ -27,6 +27,7 @@
# code. It will push 200000 packets, then report back what the min and max
# periods it saw for different IDs were.
+from __future__ import print_function
import os
import signal
import subprocess
diff --git a/tools/sched/schedgraph.py b/tools/sched/schedgraph.py
index 0723dc3..6d8a4b9 100644
--- a/tools/sched/schedgraph.py
+++ b/tools/sched/schedgraph.py
@@ -26,6 +26,7 @@
#
# $FreeBSD$
+from __future__ import print_function
import sys
import re
import random
@@ -142,7 +143,7 @@ class Colormap:
color = self.map[name]
except:
color = colors[random.randrange(0, len(colors))]
- print "Picking random color", color, "for", name
+ print("Picking random color", color, "for", name)
self.map[name] = color
self.table.append((name, color))
return (color)
@@ -736,9 +737,9 @@ class StateEvent(Event):
color = colormap.lookup(self.name)
if (duration < 0):
duration = 0
- print "Unsynchronized timestamp"
- print self.cpu, self.timestamp
- print next.cpu, next.timestamp
+ print("Unsynchronized timestamp")
+ print(self.cpu, self.timestamp)
+ print(next.cpu, next.timestamp)
delta = duration / canvas.ratio
l = canvas.create_rectangle(xpos, ypos,
xpos + delta, ypos - 10, fill=color, width=0,
@@ -762,9 +763,9 @@ class CountEvent(Event):
self.duration = duration = next.timestamp - self.timestamp
if (duration < 0):
duration = 0
- print "Unsynchronized timestamp"
- print self.cpu, self.timestamp
- print next.cpu, next.timestamp
+ print("Unsynchronized timestamp")
+ print(self.cpu, self.timestamp)
+ print(next.cpu, next.timestamp)
self.attrs.insert(0, ("count", self.count))
self.attrs.insert(1, ("duration", ticks2sec(duration)))
delta = duration / canvas.ratio
@@ -941,7 +942,7 @@ class KTRFile:
try:
ifp = open(file)
except:
- print "Can't open", file
+ print("Can't open", file)
sys.exit(1)
# quoteexp matches a quoted string, no escaping
@@ -989,14 +990,14 @@ class KTRFile:
status.startup("Parsing line " + str(lineno))
m = ktrre.match(line);
if (m == None):
- print "Can't parse", lineno, line,
+ print("Can't parse", lineno, line, end=' ')
continue;
(index, cpu, timestamp, group, id, type, dat, dat1, attrstring) = m.groups();
if (dat == None):
dat = dat1
if (self.checkstamp(timestamp) == 0):
- print "Bad timestamp at", lineno, ":",
- print cpu, timestamp
+ print("Bad timestamp at", lineno, ":", end=' ')
+ print(cpu, timestamp)
continue
#
# Build the table of optional attributes
@@ -1032,7 +1033,7 @@ class KTRFile:
args = (dat, cpu, timestamp, attrs)
e = self.makeevent(group, id, type, args)
if (e == None):
- print "Unknown type", type, lineno, line,
+ print("Unknown type", type, lineno, line, end=' ')
def makeevent(self, group, id, type, args):
e = None
@@ -1098,9 +1099,9 @@ class KTRFile:
if (self.stathz != 0):
return (self.timespan() / self.ticks[0]) * int(self.stathz)
# Pretend we have a 1ns clock
- print "WARNING: No clock discovered and no frequency ",
- print "specified via the command line."
- print "Using fake 1ghz clock"
+ print("WARNING: No clock discovered and no frequency ", end=' ')
+ print("specified via the command line.")
+ print("Using fake 1ghz clock")
return (oneghz);
def fixup(self):
@@ -1624,7 +1625,7 @@ class SchedGraph(Frame):
return self.display.getstate(tag)
if (len(sys.argv) != 2 and len(sys.argv) != 3):
- print "usage:", sys.argv[0], "<ktr file> [clock freq in ghz]"
+ print("usage:", sys.argv[0], "<ktr file> [clock freq in ghz]")
sys.exit(1)
if (len(sys.argv) > 2):
diff --git a/tools/tools/shlib-compat/shlib-compat.py b/tools/tools/shlib-compat/shlib-compat.py
index c0fb2d2..2d970b5 100755
--- a/tools/tools/shlib-compat/shlib-compat.py
+++ b/tools/tools/shlib-compat/shlib-compat.py
@@ -26,6 +26,7 @@
#
# $FreeBSD$
+from __future__ import print_function
import os
import sys
import re
@@ -78,7 +79,7 @@ class App(object):
def warn(cond, msg):
if cond:
- print >> sys.stderr, "WARN: " + msg
+ print("WARN: " + msg, file=sys.stderr)
# {{{ misc
@@ -694,12 +695,12 @@ class Shlib(object):
(sym.name_ver, self.libfile, sym.offset))
continue
if Config.verbose >= 3:
- print "Parsing symbol %s (%s)" % (sym.name_ver, self.libfile)
+ print("Parsing symbol %s (%s)" % (sym.name_ver, self.libfile))
sym.definition = dwarf.build(raw)
def parse(self):
if not os.path.isfile(self.libfile):
- print >> sys.stderr, ("No such file: %s" % self.libfile)
+ print("No such file: %s" % self.libfile, file=sys.stderr)
sys.exit(1)
self.parse_objdump()
self.parse_dwarfdump()
@@ -722,7 +723,7 @@ class Parser(object):
self.parser(line)
err = fd.close()
if err:
- print >> sys.stderr, ("Execution failed: %s" % self.proc)
+ print("Execution failed: %s" % self.proc, file=sys.stderr)
sys.exit(2)
def parse_begin(self, line):
@@ -964,16 +965,16 @@ def common_symbols(origlib, newlib):
result = []
verdiff = ListDiff(origlib.versions.keys(), newlib.versions.keys())
if Config.verbose >= 1:
- print 'Original versions: ', list_str(verdiff.orig)
- print 'New versions: ', list_str(verdiff.new)
+ print('Original versions: ', list_str(verdiff.orig))
+ print('New versions: ', list_str(verdiff.new))
for vername in verdiff.added:
- print 'Added version: ', vername
- print ' Added symbols: ', \
- names_ver_str(vername, newlib.versions[vername].names())
+ print('Added version: ', vername)
+ print(' Added symbols: ', \
+ names_ver_str(vername, newlib.versions[vername].names()))
for vername in verdiff.removed:
- print 'Removed version: ', vername
- print ' Removed symbols: ', \
- names_ver_str(vername, origlib.versions[vername].names())
+ print('Removed version: ', vername)
+ print(' Removed symbols: ', \
+ names_ver_str(vername, origlib.versions[vername].names()))
added = []
removed = []
for vername in verdiff.common:
@@ -990,13 +991,13 @@ def common_symbols(origlib, newlib):
sym = CommonSymbol(origver.symbols[n], newver.symbols[n])
commonver.append(sym)
if added:
- print 'Added symbols:'
+ print('Added symbols:')
for i in added:
- print ' ', i
+ print(' ', i)
if removed:
- print 'Removed symbols:'
+ print('Removed symbols:')
for i in removed:
- print ' ', i
+ print(' ', i)
return result
def cmp_symbols(commonver):
@@ -1011,27 +1012,27 @@ def cmp_symbols(commonver):
App.result_code = 1
if Config.verbose >= 1 or not match:
if missing:
- print '%s: missing definition' % \
- (sym.origsym.name_ver,)
+ print('%s: missing definition' % \
+ (sym.origsym.name_ver,))
continue
- print '%s: definitions %smatch' % \
- (sym.origsym.name_ver, "" if match else "mis")
+ print('%s: definitions %smatch' % \
+ (sym.origsym.name_ver, "" if match else "mis"))
if Config.dump or (not match and not Config.no_dump):
for x in [(sym.origsym, Config.origfile),
(sym.newsym, Config.newfile)]:
xsym = x[0]
xout = x[1].out
if not xsym.definition:
- print >> xout, '\n// Definition not found: %s %s' % \
- (xsym.name_ver, xsym.lib.libfile)
+ print('\n// Definition not found: %s %s' % \
+ (xsym.name_ver, xsym.lib.libfile), file=xout)
continue
- print >> xout, '\n// Definitions mismatch: %s %s' % \
- (xsym.name_ver, xsym.lib.libfile)
+ print('\n// Definitions mismatch: %s %s' % \
+ (xsym.name_ver, xsym.lib.libfile), file=xout)
pp = PrettyPrinter()
pp.run(xsym.definition)
for i in pp.nested():
- print >> xout, i
- print >> xout, pp.result()
+ print(i, file=xout)
+ print(pp.result(), file=xout)
def dump_symbols(commonver):
class SymbolDump(object):
@@ -1043,13 +1044,13 @@ def dump_symbols(commonver):
r = self.pp.run(sym.definition)
self.res.append('/* %s@%s */ %s' % (sym.name, sym.version, r))
def finish(self):
- print >> self.io_conf.out, '\n// Symbol dump: version %s, library %s' % \
- (ver.name, self.io_conf.filename)
+ print('\n// Symbol dump: version %s, library %s' % \
+ (ver.name, self.io_conf.filename), file=self.io_conf.out)
for i in self.pp.nested():
- print >> self.io_conf.out, i
- print >> self.io_conf.out, ''
+ print(i, file=self.io_conf.out)
+ print('', file=self.io_conf.out)
for i in self.res:
- print >> self.io_conf.out, i
+ print(i, file=self.io_conf.out)
for ver in commonver:
names = sorted(ver.names());
d_orig = SymbolDump(Config.origfile)
@@ -1150,7 +1151,7 @@ if __name__ == '__main__':
dump_symbols(commonver)
cmp_symbols(commonver)
if Config.verbose >= 4:
- print Dwarf.cmpcache.stats.show('Cmp')
- print DwarfdumpParser.tagcache_stats.show('Dwarf tag')
+ print(Dwarf.cmpcache.stats.show('Cmp'))
+ print(DwarfdumpParser.tagcache_stats.show('Dwarf tag'))
sys.exit(App.result_code)
OpenPOWER on IntegriCloud