From 25c15e4a9d3b59e01771709fe4dfaf23bb2dc1bb Mon Sep 17 00:00:00 2001 From: Fred Wright Date: Tue, 12 Apr 2016 15:34:41 -0700 Subject: Fixes more devtools programs for Python 3. This fixes the aivdmtable, regressdiff, sizes, and striplog programs to work with Python 3. The "striplog" program didn't require any actual changes, but it still adds the usual compatibility comment and future import. In the case of "sizes", it also adjusts the scons cleanup pattern to include the temporary directory, and adds explicit checking (with an exception) for build failures. TESTED: Ran all four programs with both Python 2 and Python 3. --- devtools/aivdmtable | 8 ++++++-- devtools/regressdiff | 16 ++++++++++------ devtools/sizes | 22 ++++++++++++++++++---- devtools/striplog | 4 ++++ 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/devtools/aivdmtable b/devtools/aivdmtable index aef8a6ad..c5720709 100755 --- a/devtools/aivdmtable +++ b/devtools/aivdmtable @@ -4,6 +4,10 @@ # # This file is Copyright (c) 2010 by the GPSD project # BSD terms apply: see the file COPYING in the distribution root for details. +# +# This code runs compatibly under Python 2 and 3.x for x >= 2. +# Preserve this property! +from __future__ import absolute_import, print_function, division sixbits = ( "000000", "000001", "000010", "000011", "000100", @@ -24,10 +28,10 @@ sixbits = ( def asciiarmor(): print("`--------`-------`---------`-------") print(" Char ASCII Decimal Bits") - for ch in range(ord('0'), ord('W')+1) + range(ord('`'), ord('w')+1): + for ch in list(range(ord('0'), ord('W')+1)) + list(range(ord('`'), ord('w')+1)): n = ch - 48 if n >= 40: n -= 8 - print '"%s" %3d %3d %s' % (chr(ch), ch, n, sixbits[n]) + print('"%s" %3d %3d %s' % (chr(ch), ch, n, sixbits[n])) print("---------------------------------------") if __name__ == "__main__": diff --git a/devtools/regressdiff b/devtools/regressdiff index 947fa8aa..fa658c12 100755 --- a/devtools/regressdiff +++ b/devtools/regressdiff @@ -5,12 +5,16 @@ # # This file is Copyright (c) 2010 by the GPSD project # BSD terms apply: see the file COPYING in the distribution root for details. +# +# This code runs compatibly under Python 2 and 3.x for x >= 2. +# Preserve this property! +from __future__ import absolute_import, print_function, division import sys -class BufferedFile(file): +class BufferedFile(object): def __init__(self, name): - file.__init__(self, name) + self.file = open(name) self.linebuffer = [] self.lineno = 0 def readline(self): @@ -18,7 +22,7 @@ class BufferedFile(file): if self.linebuffer: return self.linebuffer.pop() else: - return file.readline(self) + return self.file.readline() def pushback(self, line): self.lineno -= 1 self.linebuffer.append(line) @@ -42,6 +46,6 @@ if __name__ == "__main__": f2 = BufferedFile(sys.argv[2]) eaten = eatspan(f1, f2) - print "First %d lines match" % eaten - print `f1.peek()` - print `f2.peek()` + print("First %d lines match" % eaten) + print(f1.peek()) + print(f2.peek()) diff --git a/devtools/sizes b/devtools/sizes index f6f3f610..9bd555af 100755 --- a/devtools/sizes +++ b/devtools/sizes @@ -2,6 +2,10 @@ # # sizes -- explore the sizes of static gpsd binaries # +# This code runs compatibly under Python 2 and 3.x for x >= 2. +# Preserve this property! +from __future__ import absolute_import, print_function, division + import os # NMEA variants other than vanilla NMEA @@ -49,14 +53,24 @@ debugging = [ "oldstyle=no", ] + +class BuildFailed(BaseException): + "Build failed for this configuration." + pass + + def sizeit(legend, tag, options): - print legend + ":" - print "Options:", " ".join(options) - os.system("scons -c > /dev/null; rm -fr .scons*") - os.system("scons shared=no " + " ".join(options) + " gpsd >/dev/null") + print(legend + ":") + print("Options:", " ".join(options)) + os.system("scons -c > /dev/null; rm -fr .scon*") + status = os.system("scons shared=no " + " ".join(options) + + " gpsd >/dev/null") + if status != 0: + raise BuildFailed(options) os.rename("gpsd", "gpsd-" + tag + "-build") os.rename("gpsd_config.h", "gpsd_config.h-" + tag) + # Main sequence os.system("uname -a") sizeit("Minimalist build, stripped to NMEA only with shm interface", diff --git a/devtools/striplog b/devtools/striplog index 9c82e5a3..c0233f54 100755 --- a/devtools/striplog +++ b/devtools/striplog @@ -8,6 +8,10 @@ # This file is Copyright (c) 2010 by the GPSD project # BSD terms apply: see the file COPYING in the distribution root for details. # +# This code runs compatibly under Python 2 and 3.x for x >= 2. +# Preserve this property! +from __future__ import absolute_import, print_function, division + import getopt, sys secondline = firstline = stripjson = False -- cgit v1.2.1