From dbfa93c62253aab8e1ceb1c1ed578ae88c9dc8f7 Mon Sep 17 00:00:00 2001 From: Brian May Date: Sun, 15 Jul 2018 09:37:12 +1000 Subject: Fix print statements for Python 3.6 compatibility --- bin/apt-update-file | 7 +- bin/check-syntax | 2 +- bin/list-queue | 2 +- bin/mass-bug-filer | 13 ++-- bin/show-debsecan | 8 +-- bin/src2bin_text.py | 2 +- bin/tracker_service.py | 4 +- bin/update-db | 11 ++-- lib/python/debian_support.py | 21 +++--- lib/python/secmaster.py | 3 +- lib/python/sectracker/repo.py | 2 +- lib/python/sectracker/xcollections.py | 2 +- lib/python/sectracker_test/run.py | 9 +-- lib/python/sectracker_test/test_analyzers.py | 7 +- lib/python/sectracker_test/test_parsers.py | 8 +-- lib/python/security_db.py | 97 ++++++++++++++-------------- 16 files changed, 103 insertions(+), 95 deletions(-) diff --git a/bin/apt-update-file b/bin/apt-update-file index 081b6211ca..244ae4436d 100755 --- a/bin/apt-update-file +++ b/bin/apt-update-file @@ -1,6 +1,7 @@ #!/usr/bin/python # This script is mainly used to demo the updateFile function. +from __future__ import print_function import os import os.path import string @@ -28,7 +29,7 @@ if len(sys.argv) != 3: try: debian_support.updateFile(sys.argv[1], sys.argv[2]) except: - print >>sys.stderr, \ - "error: in download of %s to %s:" % (repr(sys.argv[1]), - repr(sys.argv[2])) + print("error: in download of %s to %s:" % (repr(sys.argv[1]), + repr(sys.argv[2])), + file=sys.stderr) raise diff --git a/bin/check-syntax b/bin/check-syntax index a0dde979fe..9e171778e1 100755 --- a/bin/check-syntax +++ b/bin/check-syntax @@ -75,7 +75,7 @@ def parse_file(name, filename): if len(sys.argv) == 2 and sys.argv[1] == "--get": l = [src["name"] for src in sources] - print ' '.join(l) + print(' '.join(l)) sys.exit(0) if len(sys.argv) != 3 or find_source(sys.argv[1]) == None: diff --git a/bin/list-queue b/bin/list-queue index 2a5e4dec60..556b7f5b27 100755 --- a/bin/list-queue +++ b/bin/list-queue @@ -224,5 +224,5 @@ def main(): "version" : 1, "binary" : pkgwithdist(debs, dists), } - print json.dumps(result) + print(json.dumps(result)) main() diff --git a/bin/mass-bug-filer b/bin/mass-bug-filer index 5987b12f7f..ce2477e0d2 100755 --- a/bin/mass-bug-filer +++ b/bin/mass-bug-filer @@ -1,4 +1,5 @@ #!/usr/bin/python +from __future__ import print_function import sys import apt @@ -7,7 +8,7 @@ import os import re if len(sys.argv) < 3: - print >>sys.stderr, "usage: %s FILE PACKAGE..." % sys.argv[0] + print("usage: %s FILE PACKAGE..." % sys.argv[0], file=sys.stderr) sys.exit(1) message_file = file(sys.argv[1]) @@ -17,7 +18,7 @@ cache = apt.Cache() errors = False for p in packages: if not cache.has_key(p): - print >>sys.stderr, "error: no such package:", p + print("error: no such package:", p, file=sys.stderr) errors = True if errors: sys.exit(2) @@ -37,7 +38,7 @@ for line in source_lines: if line == '\n': if h_subject is None: - print >>sys.stderr, "error: missing Subject header" + print("error: missing Subject header", file=sys.stderr) sys.exit(2) state = 1 continue @@ -45,7 +46,7 @@ for line in source_lines: # state == 0 match = re_header.match(line) if match is None: - print >>sys.stderr, "error: invalid line:", line + print("error: invalid line:", line, file=sys.stderr) sys.exit(2) (k, v) = match.groups() if k == "Subject": @@ -54,7 +55,7 @@ for line in source_lines: if h_bug.has_key(k): h_bug[k] = v continue - print >>sys.stderr, "error: invalid header field:", k + print("error: invalid header field:", k, file=sys.stderr) sys.exit(2) def make_message(pkg): @@ -79,7 +80,7 @@ for p in packages: sendmail(make_message(p)) for p in packages: - print "\t- %s (bug filed)" % p + print("\t- %s (bug filed)" % p) diff --git a/bin/show-debsecan b/bin/show-debsecan index 1d518e7a86..91286adc86 100755 --- a/bin/show-debsecan +++ b/bin/show-debsecan @@ -7,7 +7,7 @@ import zlib from cStringIO import StringIO if len(sys.argv) not in (2, 3): - print "usage: show-debsecan DATABASE-PATH [BLOB-NAME]" + print("usage: show-debsecan DATABASE-PATH [BLOB-NAME]") sys.exit(1) db = apsw.Connection(sys.argv[1]) @@ -15,7 +15,7 @@ c = db.cursor() if len(sys.argv) == 2: for (name,) in c.execute("SELECT name FROM debsecan_data ORDER BY name"): - print name + print(name) else: # len(sys.argv) == 3 name = sys.argv[2] for (data,) in c.execute("SELECT data FROM debsecan_data WHERE name = ?", @@ -47,9 +47,9 @@ else: # len(sys.argv) == 3 break (package, vuln, rest) = line.split(',', 2) vuln = vuln_names[int(vuln)] - print "%s,%s,%s" % (package, vuln, rest) + print("%s,%s,%s" % (package, vuln, rest)) for line in data: - print line, + print(line) db.close() diff --git a/bin/src2bin_text.py b/bin/src2bin_text.py index 743a70bbb8..87354b288e 100755 --- a/bin/src2bin_text.py +++ b/bin/src2bin_text.py @@ -68,4 +68,4 @@ if __name__ == '__main__': for line in fileinput.input(): if 'We recommend that you upgrade your' in line: line = word_wrap("%s: %s.\n" % (line[:-2],change(line,exclude)),width=73) - print line, + print(line) diff --git a/bin/tracker_service.py b/bin/tracker_service.py index b6eb166ca0..0d764e239e 100755 --- a/bin/tracker_service.py +++ b/bin/tracker_service.py @@ -12,8 +12,8 @@ import email.utils if __name__ == "__main__": if len(sys.argv) not in (3, 5): - print "usage: python tracker_service.py SOCKET-PATH DATABASE-PATH" - print " python tracker_service.py URL HOST PORT DATABASE-PATH" + print("usage: python tracker_service.py SOCKET-PATH DATABASE-PATH") + print(" python tracker_service.py URL HOST PORT DATABASE-PATH") sys.exit(1) if len(sys.argv) == 3: socket_name = sys.argv[1] diff --git a/bin/update-db b/bin/update-db index 1c61ce3928..000ee00606 100755 --- a/bin/update-db +++ b/bin/update-db @@ -1,4 +1,5 @@ #!/usr/bin/python +from __future__ import print_function import os import os.path @@ -40,20 +41,20 @@ try: warnings = db.readBugs(cursor, 'data') except SyntaxError as e: if e.filename is None or e.lineno is None: - print "error:", e + print("error:", e) else: - print "%s:%d: %s" % (e.filename, e.lineno, e.msg) + print("%s:%d: %s" % (e.filename, e.lineno, e.msg)) sys.exit(1) except debian_support.ParseError as e: e.printOut(sys.stderr) sys.exit(1) except security_db.InsertError as e: for err in e.errors: - print err + print(err) sys.exit(1) if warnings: for x in warnings: - print x + print(x) sys.exit(1) # Packages @@ -73,7 +74,7 @@ if new_file: warnings = db.calculateVulnerabilities(cursor) if warnings: for x in warnings: - print x + print(x) sys.exit(1) # debsecan data diff --git a/lib/python/debian_support.py b/lib/python/debian_support.py index e4bc12ee77..26ce3507cf 100644 --- a/lib/python/debian_support.py +++ b/lib/python/debian_support.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +from __future__ import print_function """This module implements facilities to deal with Debian-specific metadata.""" @@ -320,7 +321,7 @@ def updateFile(remote, local, verbose=None): local_file = file(local) except IOError: if verbose: - print "updateFile: no local copy, downloading full file" + print("updateFile: no local copy, downloading full file") return downloadFile(remote, local) lines = local_file.readlines() @@ -338,11 +339,11 @@ def updateFile(remote, local, verbose=None): index_fields = list(PackageFile(index_name, index_url)) except ParseError: if verbose: - print "updateFile: could not interpret patch index file" + print("updateFile: could not interpret patch index file") return downloadFile(remote, local) except IOError: if verbose: - print "updateFile: could not download patch index file" + print("updateFile: could not download patch index file") return downloadFile(remote, local) for fields in index_fields: @@ -351,7 +352,7 @@ def updateFile(remote, local, verbose=None): (remote_hash, remote_size) = re_whitespace.split(value) if local_hash == remote_hash: if verbose: - print "updateFile: local file is up-to-date" + print("updateFile: local file is up-to-date") return lines continue @@ -379,16 +380,16 @@ def updateFile(remote, local, verbose=None): continue if verbose: - print "updateFile: field %s ignored" % `field` + print("updateFile: field %s ignored" % repr(field)) if not patches_to_apply: if verbose: - print "updateFile: could not find historic entry", local_hash + print("updateFile: could not find historic entry", local_hash) return downloadFile(remote, local) for patch_name in patches_to_apply: if verbose: - print "updateFile: downloading patch " + `patch_name` + print("updateFile: downloading patch " + repr(patch_name)) try: patch_contents = downloadGunzipLines(remote + '.diff/' + patch_name + '.gz') @@ -396,15 +397,15 @@ def updateFile(remote, local, verbose=None): return downloadFile(remote, local) if readLinesSHA1(patch_contents ) != patch_hashes[patch_name]: if verbose: - print "updateFile: patch was garbled: " + repr(patch_name) + print("updateFile: patch was garbled: " + repr(patch_name)) return downloadFile(remote, local) patchLines(lines, patchesFromEdScript(patch_contents)) new_hash = readLinesSHA1(lines) if new_hash != remote_hash: if verbose: - print "updateFile: patch failed, got %s instead of %s" \ - % (new_hash, remote_hash) + print("updateFile: patch failed, got %s instead of %s" + % (new_hash, remote_hash)) return downloadFile(remote, local) replaceFile(lines, local) diff --git a/lib/python/secmaster.py b/lib/python/secmaster.py index 73522d552d..f87cdfd1e4 100644 --- a/lib/python/secmaster.py +++ b/lib/python/secmaster.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +from __future__ import print_function # Name of the security-master host HOST = "seger.debian.org" @@ -55,4 +56,4 @@ def listqueue(): if __name__ == "__main__": for pkg, archs in listqueue(): - print " ".join(pkg.astuple()), "=>", ", ".join(archs) + print(" ".join(pkg.astuple()), "=>", ", ".join(archs)) diff --git a/lib/python/sectracker/repo.py b/lib/python/sectracker/repo.py index ab0c43d89b..a108de8c3b 100644 --- a/lib/python/sectracker/repo.py +++ b/lib/python/sectracker/repo.py @@ -251,7 +251,7 @@ class RepoCollection(object): def warn(self, msg): if self.verbose: - print msg + print(msg) class Config(object): def __init__(self, config, root): diff --git a/lib/python/sectracker/xcollections.py b/lib/python/sectracker/xcollections.py index 4dbf38010e..2a63a0ee83 100644 --- a/lib/python/sectracker/xcollections.py +++ b/lib/python/sectracker/xcollections.py @@ -72,7 +72,7 @@ def namedtuple(typename, field_names, verbose=False): for i, name in enumerate(field_names): template += ' %s = _property(_itemgetter(%d))\n' % (name, i) if verbose: - print template + print(template) # Execute the template string in a temporary namespace and # support tracing utilities by setting a value for frame.f_globals['__name__'] diff --git a/lib/python/sectracker_test/run.py b/lib/python/sectracker_test/run.py index 886eded6a8..44fa675fcb 100644 --- a/lib/python/sectracker_test/run.py +++ b/lib/python/sectracker_test/run.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +from __future__ import print_function if __name__ != "__main__": raise Exception("run must be executed directly") @@ -45,13 +46,13 @@ for name in files: if name[-3:] != ".py" or name == "run.py": continue fullpath = "%s/%s" % (ourpath, name) - print "* Running", name + print("* Running", name) p = subprocess.Popen(("python", "--", fullpath), env=env) ret = p.wait() if ret != 0: - print "Test exited with status", ret - print + print("Test exited with status", ret) + print() errors = errors or ret != 0 if errors: - print "ERROR: some tests aborted with errors" + print("ERROR: some tests aborted with errors") sys.exit(1) diff --git a/lib/python/sectracker_test/test_analyzers.py b/lib/python/sectracker_test/test_analyzers.py index 133c9386dd..e192945e2b 100644 --- a/lib/python/sectracker_test/test_analyzers.py +++ b/lib/python/sectracker_test/test_analyzers.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +from __future__ import print_function import os @@ -43,7 +44,7 @@ if False: for r, pv in rpv.items(): for p, v in pv.items(): if len(v) > 1: - print r, p, v + print(r, p, v) # copysources copysrc = copysources(bugdb, diag) @@ -54,12 +55,12 @@ assert "DSA-1472-1" in copysrc["CVE-2008-0225"] vdb = fixedversions(bugdb, copysrc, rpv, diag) if False: for v in vdb: - print v + print(v) assert bestversion(c, "sid", "bash").name == "bash" assert bestversion(c, "sid", "bash", ("unsupported", "supported")).name \ == "bash" for err in diag.messages(): - print "%s:%d: %s: %s" % (err.file, err.line, err.level, err.message) + print("%s:%d: %s: %s" % (err.file, err.line, err.level, err.message)) assert not diag.messages() diff --git a/lib/python/sectracker_test/test_parsers.py b/lib/python/sectracker_test/test_parsers.py index 436b2f027c..970e9f4177 100644 --- a/lib/python/sectracker_test/test_parsers.py +++ b/lib/python/sectracker_test/test_parsers.py @@ -28,22 +28,22 @@ assert "bash" in o["bash"].binary safeunlink("../../data/CVE/list" + EXTENSION) o = cvelist("../../data/CVE/list") for err in o.messages: - print "%s:%d: %s: %s" % (err.file, err.line, err.level, err.message) + print("%s:%d: %s: %s" % (err.file, err.line, err.level, err.message)) safeunlink("../../data/DSA/list" + EXTENSION) o = dsalist("../../data/DSA/list") for err in o.messages: - print "%s:%d: %s: %s" % (err.file, err.line, err.level, err.message) + print("%s:%d: %s: %s" % (err.file, err.line, err.level, err.message)) safeunlink("../../data/DTSA/list" + EXTENSION) o = dtsalist("../../data/DTSA/list") for err in o.messages: - print "%s:%d: %s: %s" % (err.file, err.line, err.level, err.message) + print("%s:%d: %s: %s" % (err.file, err.line, err.level, err.message)) safeunlink("../../data/DLA/list" + EXTENSION) o = dlalist("../../data/DLA/list") for err in o.messages: - print "%s:%d: %s: %s" % (err.file, err.line, err.level, err.message) + print("%s:%d: %s: %s" % (err.file, err.line, err.level, err.message)) Message = sectracker.diagnostics.Message for (line, res, xmsgs) in [ diff --git a/lib/python/security_db.py b/lib/python/security_db.py index 90529ad38d..84f62f0d65 100644 --- a/lib/python/security_db.py +++ b/lib/python/security_db.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +from __future__ import print_function """This module implements a small database for tracking security bugs. @@ -268,8 +269,8 @@ class DB: c.execute("PRAGMA user_version = 22") elif v != self.schema_version: if self.verbose: - print "DB: schema version mismatch: expected %d, got %d" \ - % (self.schema_version, v) + print("DB: schema version mismatch: expected %d, got %d" + % (self.schema_version, v)) raise SchemaMismatch(repr(v)) self._initViews(c) return @@ -633,7 +634,7 @@ class DB: def do_parse(packages): if self.verbose: - print " reading " + `filename` + print(" reading " + repr(filename)) re_source = re.compile\ (r'^([a-zA-Z0-9.+-]+)(?:\s+\(([a-zA-Z0-9.+:~-]+)\))?$') @@ -713,13 +714,13 @@ class DB: """Reads a directory of package files.""" if self.verbose: - print "readPackages:" + print("readPackages:") self._readSourcePackages(cursor, directory) self._readBinaryPackages(cursor, directory) if self.verbose: - print " finished" + print(" finished") def _readSourcePackages(self, cursor, directory): """Reads from directory with source package files.""" @@ -727,7 +728,7 @@ class DB: re_sources = re.compile(r'.*/([a-z-]+)_([a-z-]*)_([a-z-]+)_Sources$') if self.verbose: - print " reading source packages" + print(" reading source packages") for filename in glob.glob(directory + '/*_Sources'): match = re_sources.match(filename) @@ -768,7 +769,7 @@ class DB: r'.*/([a-z-]+)_([a-z-]*)_([a-z-]+)_([a-z0-9-]+)_Packages$') if self.verbose: - print " reading binary packages" + print(" reading binary packages") # First check for any changes. @@ -786,7 +787,7 @@ class DB: break if not changed: if self.verbose: - print " finished (no changes)" + print(" finished (no changes)") return # Real import. We have to re-read all Packages files even if @@ -825,11 +826,11 @@ class DB: if unchanged: if self.verbose: - print " finished (no changes)" + print(" finished (no changes)") return if self.verbose: - print " deleting old data" + print(" deleting old data") cursor.execute("DELETE FROM binary_packages") self._clearVersions(cursor) @@ -847,7 +848,7 @@ class DB: yield key + (archs,) if self.verbose: - print " storing binary package data" + print(" storing binary package data") cursor.executemany( """INSERT INTO binary_packages @@ -880,7 +881,7 @@ class DB: def readBugs(self, cursor, path): if self.verbose: - print "readBugs:" + print("readBugs:") def clear_db(cleared=[False]): # Avoid clearing the database multiple times. @@ -908,7 +909,7 @@ class DB: clear_db() if self.verbose: - print " reading " + `source.name` + print(" reading " + repr(source.name)) for bug in source: try: @@ -945,7 +946,7 @@ class DB: break if unchanged: if self.verbose: - print " finished (no changes)" + print(" finished (no changes)") return clear_db() @@ -966,13 +967,13 @@ class DB: read_one(cls(path + srcpath)) if self.verbose: - print " update removed packages" + print(" update removed packages") self.readRemovedPackages(cursor, path + source_removed_packages) errors = [] if self.verbose: - print " check cross-references" + print(" check cross-references") for (bug,) in cursor.execute( """SELECT DISTINCT target FROM bugs_xref @@ -982,7 +983,7 @@ class DB: errors.append("reference to unknown bug " + bug) if self.verbose: - print " copy notes" + print(" copy notes") # Copy notes from DSA/DTSA/DLA to CVE. @@ -1037,7 +1038,7 @@ class DB: raise InsertError(errors) if self.verbose: - print " finished" + print(" finished") def availableReleases(self, cursor=None): """Returns a list of tuples (RELEASE, ARCHIVE, @@ -1088,15 +1089,15 @@ class DB: """Updates the linear version table.""" if self.verbose: - print "updateVersions:" + print("updateVersions:") for x in cursor.execute("SELECT * FROM version_linear_order LIMIT 1"): if self.verbose: - print " finished (no changes)" + print(" finished (no changes)") return if self.verbose: - print " reading" + print(" reading") versions = [] for (v,) in cursor.execute( @@ -1107,18 +1108,18 @@ class DB: versions.append(debian_support.Version(v)) if self.verbose: - print " calculating linear order" + print(" calculating linear order") versions.sort() if self.verbose: - print " storing linear order" + print(" storing linear order") for v in versions: cursor.execute( "INSERT INTO version_linear_order (version) VALUES (?)", (str(v),)) if self.verbose: - print " updating package notes" + print(" updating package notes") cursor.execute( """UPDATE package_notes SET fixed_version_id = (SELECT id FROM version_linear_order @@ -1126,14 +1127,14 @@ class DB: WHERE fixed_version IS NOT NULL""") if self.verbose: - print " updating source packages" + print(" updating source packages") cursor.execute( """UPDATE source_packages SET version_id = (SELECT id FROM version_linear_order WHERE version = source_packages.version)""") if self.verbose: - print " finished" + print(" finished") def calculateVulnerabilities(self, cursor): """Calculate vulnerable packages. @@ -1149,8 +1150,8 @@ class DB: self._updateVersions(cursor) if self.verbose: - print "calculateVulnerabilities:" - print " checking version consistency in package notes" + print("calculateVulnerabilities:") + print(" checking version consistency in package notes") # The following does not work because stable->security -> # testing -> unstable propagation is no longer available. @@ -1175,7 +1176,7 @@ class DB: % (b.source_file, b.source_line, `rel`, rel_ver)) if self.verbose: - print " checking source packages" + print(" checking source packages") cursor.execute( """UPDATE package_notes SET package_kind = 'unknown' WHERE package_kind IN ('source', 'binary')""") @@ -1206,13 +1207,13 @@ class DB: return result if self.verbose: - print " remove old status" + print(" remove old status") cursor.execute("DELETE FROM source_package_status") cursor.execute("DELETE FROM bug_status") if self.verbose: - print " calculate package status" - print " source packages (unqualified)" + print(" calculate package status") + print(" source packages (unqualified)") cursor.execute( """INSERT INTO source_package_status @@ -1229,7 +1230,7 @@ class DB: # therefore we use INSERT OR REPLACE. if self.verbose: - print " source packages (qualified)" + print(" source packages (qualified)") cursor.execute( """INSERT OR REPLACE INTO source_package_status SELECT n.bug_name, p.rowid, @@ -1244,7 +1245,7 @@ class DB: # assign nvd urgencies to those that have not yet been assigned if self.verbose: - print " insert nvd urgencies" + print(" insert nvd urgencies") cursor.execute( """REPLACE INTO source_package_status SELECT s.bug_name, s.package, s.vulnerable, @@ -1271,7 +1272,7 @@ class DB: # Calculate the release-specific bug status. if self.verbose: - print " calculate release status" + print(" calculate release status") c = self.cursor() @@ -2095,13 +2096,13 @@ class DB: AND sp.release = binary_packages.release AND sp.archive = binary_packages.archive) """): - print "error: binary package without source package" - print " binary package:", package - print " release:", release + print("error: binary package without source package") + print(" binary package:", package) + print(" release:", release) if archive: - print " archive:", archive - print " architecture:", architecture - print " missing source package:", source + print(" archive:", archive) + print(" architecture:", architecture) + print(" missing source package:", source) for (package, release, archive, architecture, version, source, source_version) \ @@ -2118,15 +2119,15 @@ class DB: debian_support.Version(source_version)) assert relation != 0 if relation <= 0: - print "error: binary package is older than source package" + print("error: binary package is older than source package") else: - print "warning: binary package is newer than source package" - print " binary package: %s (%s)" % (package, version) - print " source package: %s (%s)" % (source, source_version) - print " release:", release + print("warning: binary package is newer than source package") + print(" binary package: %s (%s)" % (package, version)) + print(" source package: %s (%s)" % (source, source_version)) + print(" release:", release) if archive: - print " archive:", archive - print " architecture:", architecture + print(" archive:", archive) + print(" architecture:", architecture) def test(): assert mergeLists(u'',u'') == [], mergeLists(u'', u'') -- cgit v1.2.3