1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-19 15:33:56 +00:00

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/
This commit is contained in:
Craig Rodrigues 2015-11-19 00:01:52 +00:00
parent 3fbd30d495
commit 749f65e3e3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=291041
5 changed files with 57 additions and 53 deletions

View File

@ -26,6 +26,7 @@
# #
# $FreeBSD$ # $FreeBSD$
from __future__ import print_function
import sys import sys
import os import os
import popen2 import popen2
@ -42,7 +43,7 @@
kld_debug_paths = [] kld_debug_paths = []
if len(sys.argv[1:]) < 2: if len(sys.argv[1:]) < 2:
print 'Usage: prog <kerncomp> <core> [<paths>]' print('Usage: prog <kerncomp> <core> [<paths>]')
sys.exit(1) sys.exit(1)
#Get the base modules path #Get the base modules path
@ -129,7 +130,7 @@ def get_addresses(inp, out):
#Tell our user that we couldn't find it. #Tell our user that we couldn't find it.
a = i[1] a = i[1]
sys.stderr.write("Can't find module: %s (addr: %d + header)\n" % (i[0], a)) 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 continue
#j = popen2.popen4('objdump --section-headers /boot/kernel/%s | grep "\.text"' % i[0])[0].read().strip().split() #j = popen2.popen4('objdump --section-headers /boot/kernel/%s | grep "\.text"' % i[0])[0].read().strip().split()
@ -137,6 +138,6 @@ def get_addresses(inp, out):
j = popen2.popen4('objdump --section-headers "%s" | grep "\.text"' % p)[0].read().strip().split() j = popen2.popen4('objdump --section-headers "%s" | grep "\.text"' % p)[0].read().strip().split()
try: try:
a = int(j[5], 16) a = int(j[5], 16)
print 'add-symbol-file', p, i[1] + a print('add-symbol-file', p, i[1] + a)
except IndexError: except IndexError:
sys.stderr.write('Bad file: %s, address: %d\n' % (i[0], i[1])) sys.stderr.write('Bad file: %s, address: %d\n' % (i[0], i[1]))

View File

@ -27,6 +27,7 @@
# code. It will push 200000 packets, then report back what the min and max # code. It will push 200000 packets, then report back what the min and max
# periods it saw for different IDs were. # periods it saw for different IDs were.
from __future__ import print_function
import os import os
import signal import signal
import subprocess import subprocess

View File

@ -26,6 +26,7 @@
# #
# $FreeBSD$ # $FreeBSD$
from __future__ import print_function
import sys import sys
import re import re
import random import random
@ -142,7 +143,7 @@ def lookup(self, name):
color = self.map[name] color = self.map[name]
except: except:
color = colors[random.randrange(0, len(colors))] 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.map[name] = color
self.table.append((name, color)) self.table.append((name, color))
return (color) return (color)
@ -736,9 +737,9 @@ def draw(self, canvas, xpos, ypos):
color = colormap.lookup(self.name) color = colormap.lookup(self.name)
if (duration < 0): if (duration < 0):
duration = 0 duration = 0
print "Unsynchronized timestamp" print("Unsynchronized timestamp")
print self.cpu, self.timestamp print(self.cpu, self.timestamp)
print next.cpu, next.timestamp print(next.cpu, next.timestamp)
delta = duration / canvas.ratio delta = duration / canvas.ratio
l = canvas.create_rectangle(xpos, ypos, l = canvas.create_rectangle(xpos, ypos,
xpos + delta, ypos - 10, fill=color, width=0, xpos + delta, ypos - 10, fill=color, width=0,
@ -762,9 +763,9 @@ def draw(self, canvas, xpos, ypos):
self.duration = duration = next.timestamp - self.timestamp self.duration = duration = next.timestamp - self.timestamp
if (duration < 0): if (duration < 0):
duration = 0 duration = 0
print "Unsynchronized timestamp" print("Unsynchronized timestamp")
print self.cpu, self.timestamp print(self.cpu, self.timestamp)
print next.cpu, next.timestamp print(next.cpu, next.timestamp)
self.attrs.insert(0, ("count", self.count)) self.attrs.insert(0, ("count", self.count))
self.attrs.insert(1, ("duration", ticks2sec(duration))) self.attrs.insert(1, ("duration", ticks2sec(duration)))
delta = duration / canvas.ratio delta = duration / canvas.ratio
@ -941,7 +942,7 @@ def parse(self, file):
try: try:
ifp = open(file) ifp = open(file)
except: except:
print "Can't open", file print("Can't open", file)
sys.exit(1) sys.exit(1)
# quoteexp matches a quoted string, no escaping # quoteexp matches a quoted string, no escaping
@ -989,14 +990,14 @@ def parse(self, file):
status.startup("Parsing line " + str(lineno)) status.startup("Parsing line " + str(lineno))
m = ktrre.match(line); m = ktrre.match(line);
if (m == None): if (m == None):
print "Can't parse", lineno, line, print("Can't parse", lineno, line, end=' ')
continue; continue;
(index, cpu, timestamp, group, id, type, dat, dat1, attrstring) = m.groups(); (index, cpu, timestamp, group, id, type, dat, dat1, attrstring) = m.groups();
if (dat == None): if (dat == None):
dat = dat1 dat = dat1
if (self.checkstamp(timestamp) == 0): if (self.checkstamp(timestamp) == 0):
print "Bad timestamp at", lineno, ":", print("Bad timestamp at", lineno, ":", end=' ')
print cpu, timestamp print(cpu, timestamp)
continue continue
# #
# Build the table of optional attributes # Build the table of optional attributes
@ -1032,7 +1033,7 @@ def parse(self, file):
args = (dat, cpu, timestamp, attrs) args = (dat, cpu, timestamp, attrs)
e = self.makeevent(group, id, type, args) e = self.makeevent(group, id, type, args)
if (e == None): if (e == None):
print "Unknown type", type, lineno, line, print("Unknown type", type, lineno, line, end=' ')
def makeevent(self, group, id, type, args): def makeevent(self, group, id, type, args):
e = None e = None
@ -1098,9 +1099,9 @@ def ticksps(self):
if (self.stathz != 0): if (self.stathz != 0):
return (self.timespan() / self.ticks[0]) * int(self.stathz) return (self.timespan() / self.ticks[0]) * int(self.stathz)
# Pretend we have a 1ns clock # Pretend we have a 1ns clock
print "WARNING: No clock discovered and no frequency ", print("WARNING: No clock discovered and no frequency ", end=' ')
print "specified via the command line." print("specified via the command line.")
print "Using fake 1ghz clock" print("Using fake 1ghz clock")
return (oneghz); return (oneghz);
def fixup(self): def fixup(self):
@ -1624,7 +1625,7 @@ def getstate(self, tag):
return self.display.getstate(tag) return self.display.getstate(tag)
if (len(sys.argv) != 2 and len(sys.argv) != 3): 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) sys.exit(1)
if (len(sys.argv) > 2): if (len(sys.argv) > 2):

View File

@ -26,6 +26,7 @@
# #
# $FreeBSD$ # $FreeBSD$
from __future__ import print_function
import os import os
import sys import sys
import re import re
@ -78,7 +79,7 @@ class App(object):
def warn(cond, msg): def warn(cond, msg):
if cond: if cond:
print >> sys.stderr, "WARN: " + msg print("WARN: " + msg, file=sys.stderr)
# {{{ misc # {{{ misc
@ -694,12 +695,12 @@ def lookup(sym):
(sym.name_ver, self.libfile, sym.offset)) (sym.name_ver, self.libfile, sym.offset))
continue continue
if Config.verbose >= 3: 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) sym.definition = dwarf.build(raw)
def parse(self): def parse(self):
if not os.path.isfile(self.libfile): 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) sys.exit(1)
self.parse_objdump() self.parse_objdump()
self.parse_dwarfdump() self.parse_dwarfdump()
@ -722,7 +723,7 @@ def run(self):
self.parser(line) self.parser(line)
err = fd.close() err = fd.close()
if err: if err:
print >> sys.stderr, ("Execution failed: %s" % self.proc) print("Execution failed: %s" % self.proc, file=sys.stderr)
sys.exit(2) sys.exit(2)
def parse_begin(self, line): def parse_begin(self, line):
@ -964,16 +965,16 @@ def common_symbols(origlib, newlib):
result = [] result = []
verdiff = ListDiff(origlib.versions.keys(), newlib.versions.keys()) verdiff = ListDiff(origlib.versions.keys(), newlib.versions.keys())
if Config.verbose >= 1: if Config.verbose >= 1:
print 'Original versions: ', list_str(verdiff.orig) print('Original versions: ', list_str(verdiff.orig))
print 'New versions: ', list_str(verdiff.new) print('New versions: ', list_str(verdiff.new))
for vername in verdiff.added: for vername in verdiff.added:
print 'Added version: ', vername print('Added version: ', vername)
print ' Added symbols: ', \ print(' Added symbols: ', \
names_ver_str(vername, newlib.versions[vername].names()) names_ver_str(vername, newlib.versions[vername].names()))
for vername in verdiff.removed: for vername in verdiff.removed:
print 'Removed version: ', vername print('Removed version: ', vername)
print ' Removed symbols: ', \ print(' Removed symbols: ', \
names_ver_str(vername, origlib.versions[vername].names()) names_ver_str(vername, origlib.versions[vername].names()))
added = [] added = []
removed = [] removed = []
for vername in verdiff.common: for vername in verdiff.common:
@ -990,13 +991,13 @@ def common_symbols(origlib, newlib):
sym = CommonSymbol(origver.symbols[n], newver.symbols[n]) sym = CommonSymbol(origver.symbols[n], newver.symbols[n])
commonver.append(sym) commonver.append(sym)
if added: if added:
print 'Added symbols:' print('Added symbols:')
for i in added: for i in added:
print ' ', i print(' ', i)
if removed: if removed:
print 'Removed symbols:' print('Removed symbols:')
for i in removed: for i in removed:
print ' ', i print(' ', i)
return result return result
def cmp_symbols(commonver): def cmp_symbols(commonver):
@ -1011,27 +1012,27 @@ def cmp_symbols(commonver):
App.result_code = 1 App.result_code = 1
if Config.verbose >= 1 or not match: if Config.verbose >= 1 or not match:
if missing: if missing:
print '%s: missing definition' % \ print('%s: missing definition' % \
(sym.origsym.name_ver,) (sym.origsym.name_ver,))
continue continue
print '%s: definitions %smatch' % \ print('%s: definitions %smatch' % \
(sym.origsym.name_ver, "" if match else "mis") (sym.origsym.name_ver, "" if match else "mis"))
if Config.dump or (not match and not Config.no_dump): if Config.dump or (not match and not Config.no_dump):
for x in [(sym.origsym, Config.origfile), for x in [(sym.origsym, Config.origfile),
(sym.newsym, Config.newfile)]: (sym.newsym, Config.newfile)]:
xsym = x[0] xsym = x[0]
xout = x[1].out xout = x[1].out
if not xsym.definition: if not xsym.definition:
print >> xout, '\n// Definition not found: %s %s' % \ print('\n// Definition not found: %s %s' % \
(xsym.name_ver, xsym.lib.libfile) (xsym.name_ver, xsym.lib.libfile), file=xout)
continue continue
print >> xout, '\n// Definitions mismatch: %s %s' % \ print('\n// Definitions mismatch: %s %s' % \
(xsym.name_ver, xsym.lib.libfile) (xsym.name_ver, xsym.lib.libfile), file=xout)
pp = PrettyPrinter() pp = PrettyPrinter()
pp.run(xsym.definition) pp.run(xsym.definition)
for i in pp.nested(): for i in pp.nested():
print >> xout, i print(i, file=xout)
print >> xout, pp.result() print(pp.result(), file=xout)
def dump_symbols(commonver): def dump_symbols(commonver):
class SymbolDump(object): class SymbolDump(object):
@ -1043,13 +1044,13 @@ def run(self, sym):
r = self.pp.run(sym.definition) r = self.pp.run(sym.definition)
self.res.append('/* %s@%s */ %s' % (sym.name, sym.version, r)) self.res.append('/* %s@%s */ %s' % (sym.name, sym.version, r))
def finish(self): def finish(self):
print >> self.io_conf.out, '\n// Symbol dump: version %s, library %s' % \ print('\n// Symbol dump: version %s, library %s' % \
(ver.name, self.io_conf.filename) (ver.name, self.io_conf.filename), file=self.io_conf.out)
for i in self.pp.nested(): for i in self.pp.nested():
print >> self.io_conf.out, i print(i, file=self.io_conf.out)
print >> self.io_conf.out, '' print('', file=self.io_conf.out)
for i in self.res: for i in self.res:
print >> self.io_conf.out, i print(i, file=self.io_conf.out)
for ver in commonver: for ver in commonver:
names = sorted(ver.names()); names = sorted(ver.names());
d_orig = SymbolDump(Config.origfile) d_orig = SymbolDump(Config.origfile)
@ -1150,7 +1151,7 @@ def finish(self):
dump_symbols(commonver) dump_symbols(commonver)
cmp_symbols(commonver) cmp_symbols(commonver)
if Config.verbose >= 4: if Config.verbose >= 4:
print Dwarf.cmpcache.stats.show('Cmp') print(Dwarf.cmpcache.stats.show('Cmp'))
print DwarfdumpParser.tagcache_stats.show('Dwarf tag') print(DwarfdumpParser.tagcache_stats.show('Dwarf tag'))
sys.exit(App.result_code) sys.exit(App.result_code)

View File

@ -3,7 +3,7 @@
# $FreeBSD$ # $FreeBSD$
# #
# an aggressive little script for trimming duplicate cookies # an aggressive little script for trimming duplicate cookies
from __future__ import print_function
import argparse import argparse
import re import re