summaryrefslogtreecommitdiff
path: root/usr/src/tools/scripts
diff options
context:
space:
mode:
authorAndy Fiddaman <omnios@citrus-it.co.uk>2018-11-15 10:17:46 +0000
committerDan McDonald <danmcd@joyent.com>2019-01-10 11:09:52 -0500
commitca13eaa51ee900abba73dfb6624e492f7e48863e (patch)
tree0e42badd7d21d429fb2cb02f823c20d30f90b113 /usr/src/tools/scripts
parent9b40c3052b9b0d91120c568df0c5211c131c8da1 (diff)
downloadillumos-gate-ca13eaa51ee900abba73dfb6624e492f7e48863e.tar.gz
9979 Support python3 for in-gate tools
Reviewed by: Toomas Soome <tsoome@me.com> Reviewed by: Peter Tribble <peter.tribble@gmail.com> Reviewed by: Alexander Pyhalov <apyhalov@gmail.com> Reviewed by: Andrew Stormont <andyjstormont@gmail.com> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/tools/scripts')
-rw-r--r--usr/src/tools/scripts/cddlchk.py19
-rw-r--r--usr/src/tools/scripts/copyrightchk.py14
-rw-r--r--usr/src/tools/scripts/git-pbchk.py115
-rw-r--r--usr/src/tools/scripts/hdrchk.py14
-rw-r--r--usr/src/tools/scripts/mapfilechk.py17
-rw-r--r--usr/src/tools/scripts/validate_pkg.py92
-rw-r--r--usr/src/tools/scripts/wscheck.py16
-rw-r--r--usr/src/tools/scripts/wsdiff.py320
8 files changed, 296 insertions, 311 deletions
diff --git a/usr/src/tools/scripts/cddlchk.py b/usr/src/tools/scripts/cddlchk.py
index d0b3a70474..793f077bea 100644
--- a/usr/src/tools/scripts/cddlchk.py
+++ b/usr/src/tools/scripts/cddlchk.py
@@ -1,4 +1,4 @@
-#!@PYTHON@
+#!@TOOLS_PYTHON@
#
# CDDL HEADER START
#
@@ -22,13 +22,14 @@
#
# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
#
#
# Check for valid CDDL blocks in source files.
#
-import sys, os, getopt, fnmatch
+import sys, os, io, getopt, fnmatch
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "lib",
"python%d.%d" % sys.version_info[:2]))
@@ -48,7 +49,7 @@ class ExceptionList(object):
fh = None
try:
fh = open(exfile, 'r')
- except IOError, e:
+ except IOError as e:
sys.stderr.write('Failed to open exception list: '
'%s: %s\n' % (e.filename, e.strerror))
sys.exit(2)
@@ -91,15 +92,15 @@ def usage():
def check(filename, opts):
try:
- fh = open(filename, 'r')
- except IOError, e:
+ with io.open(filename, encoding='utf-8',
+ errors='replace') as fh:
+ return cddlchk(fh, verbose=opts['verbose'],
+ lenient=opts['lenient'],
+ output=sys.stdout)
+ except IOError as e:
sys.stderr.write("failed to open '%s': %s\n" %
(e.filename, e.strerror))
return 1
- else:
- return cddlchk(fh, verbose=opts['verbose'],
- lenient=opts['lenient'],
- output=sys.stdout)
def walker(opts, dirname, fnames):
for f in fnames:
diff --git a/usr/src/tools/scripts/copyrightchk.py b/usr/src/tools/scripts/copyrightchk.py
index 8e6228f5f7..fab81fc7ce 100644
--- a/usr/src/tools/scripts/copyrightchk.py
+++ b/usr/src/tools/scripts/copyrightchk.py
@@ -1,4 +1,4 @@
-#!@PYTHON@
+#!@TOOLS_PYTHON@
#
# CDDL HEADER START
#
@@ -22,13 +22,14 @@
#
# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
#
#
# Check for valid SMI copyright notices in source files.
#
-import sys, os
+import sys, os, io
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "lib",
"python%d.%d" % sys.version_info[:2]))
@@ -41,13 +42,12 @@ from onbld.Checks.Copyright import copyright
ret = 0
for filename in sys.argv[1:]:
try:
- fin = open(filename, 'r')
- except IOError, e:
+ with io.open(filename, encoding='utf-8',
+ errors='replace') as fin:
+ ret |= copyright(fin, output=sys.stdout)
+ except IOError as e:
sys.stderr.write("failed to open '%s': %s\n" %
(e.filename, e.strerror))
continue
- ret |= copyright(fin, output=sys.stdout)
- fin.close()
-
sys.exit(ret)
diff --git a/usr/src/tools/scripts/git-pbchk.py b/usr/src/tools/scripts/git-pbchk.py
index 7f3956ac42..e0f3d662d1 100644
--- a/usr/src/tools/scripts/git-pbchk.py
+++ b/usr/src/tools/scripts/git-pbchk.py
@@ -1,4 +1,4 @@
-#!@PYTHON@
+#!@TOOLS_PYTHON@
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
@@ -21,16 +21,23 @@
# Copyright (c) 2015, 2016 by Delphix. All rights reserved.
# Copyright 2016 Nexenta Systems, Inc.
# Copyright 2018 Joyent, Inc.
+# Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
#
+from __future__ import print_function
+
import getopt
+import io
import os
import re
import subprocess
import sys
import tempfile
-from cStringIO import StringIO
+if sys.version_info[0] < 3:
+ from cStringIO import StringIO
+else:
+ from io import StringIO
#
# Adjust the load path based on our location and the version of python into
@@ -51,7 +58,6 @@ from onbld.Scm import Ignore
from onbld.Checks import Comments, Copyright, CStyle, HdrChk, WsCheck
from onbld.Checks import JStyle, Keywords, ManLint, Mapfile, SpellCheck
-
class GitError(Exception):
pass
@@ -65,15 +71,15 @@ def git(command):
command = ["git"] + command
try:
- tmpfile = tempfile.TemporaryFile(prefix="git-nits")
- except EnvironmentError, e:
+ tmpfile = tempfile.TemporaryFile(prefix="git-nits", mode="w+b")
+ except EnvironmentError as e:
raise GitError("Could not create temporary file: %s\n" % e)
try:
p = subprocess.Popen(command,
stdout=tmpfile,
stderr=subprocess.PIPE)
- except OSError, e:
+ except OSError as e:
raise GitError("could not execute %s: %s\n" % (command, e))
err = p.wait()
@@ -81,38 +87,30 @@ def git(command):
raise GitError(p.stderr.read())
tmpfile.seek(0)
- return tmpfile
-
+ lines = []
+ for l in tmpfile:
+ lines.append(l.decode('utf-8', 'replace'))
+ return lines
def git_root():
"""Return the root of the current git workspace"""
p = git('rev-parse --git-dir')
+ dir = p[0]
- if not p:
- sys.stderr.write("Failed finding git workspace\n")
- sys.exit(err)
-
- return os.path.abspath(os.path.join(p.readlines()[0],
- os.path.pardir))
-
+ return os.path.abspath(os.path.join(dir, os.path.pardir))
def git_branch():
"""Return the current git branch"""
p = git('branch')
- if not p:
- sys.stderr.write("Failed finding git branch\n")
- sys.exit(err)
-
for elt in p:
if elt[0] == '*':
if elt.endswith('(no branch)'):
return None
return elt.split()[1]
-
def git_parent_branch(branch):
"""Return the parent of the current git branch.
@@ -137,7 +135,6 @@ def git_parent_branch(branch):
return remote
return 'origin/master'
-
def git_comments(parent):
"""Return a list of any checkin comments on this git branch"""
@@ -147,8 +144,7 @@ def git_comments(parent):
sys.stderr.write("Failed getting git comments\n")
sys.exit(err)
- return [x.strip() for x in p.readlines() if x != ':SEP:\n']
-
+ return [x.strip() for x in p if x != ':SEP:\n']
def git_file_list(parent, paths=None):
"""Return the set of files which have ever changed on this branch.
@@ -170,17 +166,15 @@ def git_file_list(parent, paths=None):
return ret
-
def not_check(root, cmd):
"""Return a function which returns True if a file given as an argument
should be excluded from the check named by 'cmd'"""
- ignorefiles = filter(os.path.exists,
+ ignorefiles = list(filter(os.path.exists,
[os.path.join(root, ".git", "%s.NOT" % cmd),
- os.path.join(root, "exception_lists", cmd)])
+ os.path.join(root, "exception_lists", cmd)]))
return Ignore.ignore(root, ignorefiles)
-
def gen_files(root, parent, paths, exclude):
"""Return a function producing file names, relative to the current
directory, of any file changed on this branch (limited to 'paths' if
@@ -202,20 +196,19 @@ def gen_files(root, parent, paths, exclude):
path = relpath(abspath, '.')
try:
res = git("diff %s HEAD %s" % (parent, path))
- except GitError, e:
+ except GitError as e:
# This ignores all the errors that can be thrown. Usually, this
# means that git returned non-zero because the file doesn't
# exist, but it could also fail if git can't create a new file
# or it can't be executed. Such errors are 1) unlikely, and 2)
# will be caught by other invocations of git().
continue
- empty = not res.readline()
+ empty = not res
if (os.path.isfile(path) and not empty and
select(path) and not exclude(abspath)):
yield path
return ret
-
def comchk(root, parent, flist, output):
output.write("Comments:\n")
@@ -243,81 +236,68 @@ def mapfilechk(root, parent, flist, output):
for f in flist(lambda x: MapfileRE.match(x) and not
NotMapSuffixRE.match(x)):
- fh = open(f, 'r')
- ret |= Mapfile.mapfilechk(fh, output=output)
- fh.close()
+ with io.open(f, encoding='utf-8', errors='replace') as fh:
+ ret |= Mapfile.mapfilechk(fh, output=output)
return ret
-
def copyright(root, parent, flist, output):
ret = 0
output.write("Copyrights:\n")
for f in flist():
- fh = open(f, 'r')
- ret |= Copyright.copyright(fh, output=output)
- fh.close()
+ with io.open(f, encoding='utf-8', errors='replace') as fh:
+ ret |= Copyright.copyright(fh, output=output)
return ret
-
def hdrchk(root, parent, flist, output):
ret = 0
output.write("Header format:\n")
for f in flist(lambda x: x.endswith('.h')):
- fh = open(f, 'r')
- ret |= HdrChk.hdrchk(fh, lenient=True, output=output)
- fh.close()
+ with io.open(f, encoding='utf-8', errors='replace') as fh:
+ ret |= HdrChk.hdrchk(fh, lenient=True, output=output)
return ret
-
def cstyle(root, parent, flist, output):
ret = 0
output.write("C style:\n")
for f in flist(lambda x: x.endswith('.c') or x.endswith('.h')):
- fh = open(f, 'r')
- ret |= CStyle.cstyle(fh, output=output, picky=True,
+ with io.open(f, encoding='utf-8', errors='replace') as fh:
+ ret |= CStyle.cstyle(fh, output=output, picky=True,
check_posix_types=True,
check_continuation=True)
- fh.close()
return ret
-
def jstyle(root, parent, flist, output):
ret = 0
output.write("Java style:\n")
for f in flist(lambda x: x.endswith('.java')):
- fh = open(f, 'r')
- ret |= JStyle.jstyle(fh, output=output, picky=True)
- fh.close()
+ with io.open(f, encoding='utf-8', errors='replace') as fh:
+ ret |= JStyle.jstyle(fh, output=output, picky=True)
return ret
-
def manlint(root, parent, flist, output):
ret = 0
output.write("Man page format/spelling:\n")
ManfileRE = re.compile(r'.*\.[0-9][a-z]*$', re.IGNORECASE)
for f in flist(lambda x: ManfileRE.match(x)):
- fh = open(f, 'r')
- ret |= ManLint.manlint(fh, output=output, picky=True)
- ret |= SpellCheck.spellcheck(fh, output=output)
- fh.close()
+ with io.open(f, encoding='utf-8', errors='replace') as fh:
+ ret |= ManLint.manlint(fh, output=output, picky=True)
+ ret |= SpellCheck.spellcheck(fh, output=output)
return ret
def keywords(root, parent, flist, output):
ret = 0
output.write("SCCS Keywords:\n")
for f in flist():
- fh = open(f, 'r')
- ret |= Keywords.keywords(fh, output=output)
- fh.close()
+ with io.open(f, encoding='utf-8', errors='replace') as fh:
+ ret |= Keywords.keywords(fh, output=output)
return ret
def wscheck(root, parent, flist, output):
ret = 0
output.write("white space nits:\n")
for f in flist():
- fh = open(f, 'r')
- ret |= WsCheck.wscheck(fh, output=output)
- fh.close()
+ with io.open(f, encoding='utf-8', errors='replace') as fh:
+ ret |= WsCheck.wscheck(fh, output=output)
return ret
def run_checks(root, parent, cmds, paths='', opts={}):
@@ -334,17 +314,16 @@ def run_checks(root, parent, cmds, paths='', opts={}):
for cmd in cmds:
s = StringIO()
- exclude = not_check(root, cmd.func_name)
+ exclude = not_check(root, cmd.__name__)
result = cmd(root, parent, gen_files(root, parent, paths, exclude),
output=s)
ret |= result
if result != 0:
- print s.getvalue()
+ print(s.getvalue())
return ret
-
def nits(root, parent, paths):
cmds = [copyright,
cstyle,
@@ -353,10 +332,9 @@ def nits(root, parent, paths):
keywords,
manlint,
mapfilechk,
- wscheck]
+ wscheck]
run_checks(root, parent, cmds, paths)
-
def pbchk(root, parent, paths):
cmds = [comchk,
copyright,
@@ -366,17 +344,16 @@ def pbchk(root, parent, paths):
keywords,
manlint,
mapfilechk,
- wscheck]
+ wscheck]
run_checks(root, parent, cmds)
-
def main(cmd, args):
parent_branch = None
checkname = None
try:
opts, args = getopt.getopt(args, 'b:c:p:')
- except getopt.GetoptError, e:
+ except getopt.GetoptError as e:
sys.stderr.write(str(e) + '\n')
sys.stderr.write("Usage: %s [-c check] [-p branch] [path...]\n" % cmd)
sys.exit(1)
@@ -410,6 +387,6 @@ def main(cmd, args):
if __name__ == '__main__':
try:
main(os.path.basename(sys.argv[0]), sys.argv[1:])
- except GitError, e:
+ except GitError as e:
sys.stderr.write("failed to run git:\n %s\n" % str(e))
sys.exit(1)
diff --git a/usr/src/tools/scripts/hdrchk.py b/usr/src/tools/scripts/hdrchk.py
index 8c529b8c3d..8f31899623 100644
--- a/usr/src/tools/scripts/hdrchk.py
+++ b/usr/src/tools/scripts/hdrchk.py
@@ -1,4 +1,4 @@
-#!@PYTHON@
+#!@TOOLS_PYTHON@
#
# CDDL HEADER START
#
@@ -22,13 +22,14 @@
#
# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
#
#
# Check header files conform to ON standards.
#
-import sys, os, getopt
+import sys, os, io, getopt
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "lib",
"python%d.%d" % sys.version_info[:2]))
@@ -59,11 +60,10 @@ for opt, arg in opts:
ret = 0
for filename in args:
try:
- fh = open(filename, 'r')
- except IOError, e:
+ with io.open(filename, encoding='utf-8',
+ errors='replace') as fh:
+ ret |= hdrchk(fh, lenient=lenient, output=sys.stderr)
+ except IOError as e:
sys.stderr.write("failed to open '%s': %s\n" %
(e.filename, e.strerror))
- else:
- ret |= hdrchk(fh, lenient=lenient, output=sys.stderr)
- fh.close()
sys.exit(ret)
diff --git a/usr/src/tools/scripts/mapfilechk.py b/usr/src/tools/scripts/mapfilechk.py
index 0e3ba283a5..7429eba099 100644
--- a/usr/src/tools/scripts/mapfilechk.py
+++ b/usr/src/tools/scripts/mapfilechk.py
@@ -1,4 +1,4 @@
-#!@PYTHON@
+#!@TOOLS_PYTHON@
#
# CDDL HEADER START
#
@@ -22,13 +22,14 @@
#
# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
#
#
# Check for valid link-editor mapfile comment blocks in source files.
#
-import sys, os, getopt, fnmatch
+import sys, os, io, getopt, fnmatch
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "lib",
"python%d.%d" % sys.version_info[:2]))
@@ -48,7 +49,7 @@ class ExceptionList(object):
fh = None
try:
fh = open(exfile, 'r')
- except IOError, e:
+ except IOError as e:
sys.stderr.write('Failed to open exception list: '
'%s: %s\n' % (e.filename, e.strerror))
sys.exit(2)
@@ -90,14 +91,14 @@ def usage():
def check(filename, opts):
try:
- fh = open(filename, 'r')
- except IOError, e:
+ with io.open(filename, encoding='utf-8',
+ errors='replace') as fh:
+ return mapfilechk(fh, verbose=opts['verbose'],
+ output=sys.stdout)
+ except IOError as e:
sys.stderr.write("failed to open '%s': %s\n" %
(e.filename, e.strerror))
return 1
- else:
- return mapfilechk(fh, verbose=opts['verbose'],
- output=sys.stdout)
def walker(opts, dirname, fnames):
for f in fnames:
diff --git a/usr/src/tools/scripts/validate_pkg.py b/usr/src/tools/scripts/validate_pkg.py
index 6e5858a6ae..77e7d8e5d5 100644
--- a/usr/src/tools/scripts/validate_pkg.py
+++ b/usr/src/tools/scripts/validate_pkg.py
@@ -1,4 +1,4 @@
-#!@PYTHON@
+#!@TOOLS_PYTHON@
#
# CDDL HEADER START
#
@@ -25,6 +25,8 @@
# Use is subject to license terms.
#
+# Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
+
#
# Compare the content generated by a build to a set of manifests
# describing how that content is to be delivered.
@@ -132,13 +134,13 @@ class FileInfo(object):
mo = m & stat.S_IRWXO
e = self.editable
- if (((mu & 02) == 0 and (mo & mg & 04) == 04) or
- (t == "file" and mo & 01 == 1) or
+ if (((mu & 0o2) == 0 and (mo & mg & 0o4) == 0o4) or
+ (t == "file" and mo & 0o1 == 1) or
(mg, mo) == (mu, mu) or
((t == "file" and not e or t == "dir" and o == "bin") and
- (mg & 05 == mo & 05)) or
- (t == "file" and o == "bin" and mu & 01 == 01) or
- (m & 0105 != 0 and p.startswith("etc/security/dev/"))):
+ (mg & 0o5 == mo & 0o5)) or
+ (t == "file" and o == "bin" and mu & 0o1 == 0o1) or
+ (m & 0o105 != 0 and p.startswith("etc/security/dev/"))):
w.extend(["%s: owner \"%s\" may be safely " \
"changed to \"root\"" % (p, o)])
@@ -405,38 +407,38 @@ class DirectoryTree(dict):
def compare(self, other):
"""Compare two different sets of FileInfo objects.
"""
- keys1 = frozenset(self.keys())
- keys2 = frozenset(other.keys())
+ keys1 = frozenset(list(self.keys()))
+ keys2 = frozenset(list(other.keys()))
common = keys1.intersection(keys2)
onlykeys1 = keys1.difference(common)
onlykeys2 = keys2.difference(common)
if onlykeys1:
- print "Entries present in %s but not %s:" % \
- (self.name, other.name)
+ print("Entries present in %s but not %s:" % \
+ (self.name, other.name))
for path in sorted(onlykeys1):
- print("\t%s" % str(self[path]))
- print ""
+ print(("\t%s" % str(self[path])))
+ print("")
if onlykeys2:
- print "Entries present in %s but not %s:" % \
- (other.name, self.name)
+ print("Entries present in %s but not %s:" % \
+ (other.name, self.name))
for path in sorted(onlykeys2):
- print("\t%s" % str(other[path]))
- print ""
+ print(("\t%s" % str(other[path])))
+ print("")
nodifferences = True
for path in sorted(common):
if self[path] != other[path]:
if nodifferences:
nodifferences = False
- print "Entries that differ between %s and %s:" \
- % (self.name, other.name)
- print("%14s %s" % (self.name, self[path]))
- print("%14s %s" % (other.name, other[path]))
+ print("Entries that differ between %s and %s:" \
+ % (self.name, other.name))
+ print(("%14s %s" % (self.name, self[path])))
+ print(("%14s %s" % (other.name, other[path])))
if not nodifferences:
- print ""
+ print("")
class BadProtolistFormat(Exception):
@@ -468,7 +470,7 @@ class ProtoTree(DirectoryTree):
if path not in exceptions:
try:
newentries[path] = RealFileInfo(pdir, path)
- except OSError, e:
+ except OSError as e:
sys.stderr.write("Warning: unable to stat %s: %s\n" %
(path, e))
continue
@@ -491,10 +493,10 @@ class ProtoTree(DirectoryTree):
# that cross proto dir boundaries.
#
hk2path = {}
- for path, fileinfo in newentries.iteritems():
+ for path, fileinfo in newentries.items():
if fileinfo.hardkey:
hk2path.setdefault(fileinfo.hardkey, set()).add(path)
- for fileinfo in newentries.itervalues():
+ for fileinfo in newentries.values():
if fileinfo.hardkey:
fileinfo.hardpaths.update(hk2path[fileinfo.hardkey])
self.update(newentries)
@@ -510,7 +512,7 @@ class ProtoTree(DirectoryTree):
try:
plist = open(protolist)
- except IOError, exc:
+ except IOError as exc:
raise IOError("cannot open proto list: %s" % str(exc))
newentries = {}
@@ -543,10 +545,10 @@ class ProtoTree(DirectoryTree):
plist.close()
hk2path = {}
- for path, fileinfo in newentries.iteritems():
+ for path, fileinfo in newentries.items():
if fileinfo.hardkey:
hk2path.setdefault(fileinfo.hardkey, set()).add(path)
- for fileinfo in newentries.itervalues():
+ for fileinfo in newentries.values():
if fileinfo.hardkey:
fileinfo.hardpaths.update(hk2path[fileinfo.hardkey])
self.update(newentries)
@@ -582,9 +584,9 @@ class ManifestTree(DirectoryTree):
mfest = manifest.Manifest()
try:
mfest.set_content(open(os.path.join(root, mfile)).read())
- except IOError, exc:
+ except IOError as exc:
raise IOError("cannot read manifest: %s" % str(exc))
- except actions.ActionError, exc:
+ except actions.ActionError as exc:
raise ManifestParsingError(mfile, str(exc))
#
@@ -657,10 +659,10 @@ class ManifestTree(DirectoryTree):
modewarnings.update(self[path].checkmodes(modechecks))
if len(modewarnings) > 0:
- print "warning: unsafe permissions in %s" % mfile
+ print("warning: unsafe permissions in %s" % mfile)
for w in sorted(modewarnings):
- print w
- print ""
+ print(w)
+ print("")
def adddir(self, mdir, arch, modechecks, exceptions):
"""Walks the specified directory looking for pkg(5) manifests.
@@ -670,14 +672,14 @@ class ManifestTree(DirectoryTree):
stat.S_ISREG(os.lstat(os.path.join(mdir, mfile)).st_mode)):
try:
self.addmanifest(mdir, mfile, arch, modechecks, exceptions)
- except IOError, exc:
+ except IOError as exc:
sys.stderr.write("warning: %s\n" % str(exc))
def resolvehardlinks(self):
"""Populates mode, group, and owner for resolved (ie link target
is present in the manifest tree) hard links.
"""
- for info in self.values():
+ for info in list(self.values()):
if info.name() == "hardlink":
tgt = info.hardkey
if tgt in self:
@@ -696,7 +698,7 @@ class ExceptionList(set):
for fname in files:
try:
self.readexceptionfile(fname, arch)
- except IOError, exc:
+ except IOError as exc:
sys.stderr.write("warning: cannot read exception file: %s\n" %
str(exc))
@@ -772,7 +774,7 @@ def main(argv):
"""
try:
opts, args = getopt.getopt(argv, 'a:e:Ll:Mm:p:vX:')
- except getopt.GetoptError, exc:
+ except getopt.GetoptError as exc:
usage(str(exc))
if args:
@@ -849,8 +851,8 @@ def main(argv):
manifesttree.adddir(mdir, arch, modechecks, exceptions)
if listonly:
manifesttree.resolvehardlinks()
- for info in manifesttree.values():
- print "%s" % info.protostr()
+ for info in list(manifesttree.values()):
+ print("%s" % info.protostr())
sys.exit(0)
if modechecks is not None:
sys.exit(0)
@@ -865,24 +867,24 @@ def main(argv):
for plist in protolists:
try:
protolist.addprotolist(plist, exceptions)
- except IOError, exc:
+ except IOError as exc:
sys.stderr.write("warning: %s\n" % str(exc))
trees.append(protolist)
if verbose and exceptions:
- print "Entries present in exception list but missing from proto area:"
+ print("Entries present in exception list but missing from proto area:")
for exc in sorted(exceptions):
- print "\t%s" % exc
- print ""
+ print("\t%s" % exc)
+ print("")
usedexceptions = originalexceptions.difference(exceptions)
harmfulexceptions = usedexceptions.intersection(manifesttree)
if harmfulexceptions:
- print "Entries present in exception list but also in manifests:"
+ print("Entries present in exception list but also in manifests:")
for exc in sorted(harmfulexceptions):
- print "\t%s" % exc
+ print("\t%s" % exc)
del manifesttree[exc]
- print ""
+ print("")
trees[0].compare(trees[1])
diff --git a/usr/src/tools/scripts/wscheck.py b/usr/src/tools/scripts/wscheck.py
index ce85b8971f..ee3fd83b1d 100644
--- a/usr/src/tools/scripts/wscheck.py
+++ b/usr/src/tools/scripts/wscheck.py
@@ -1,4 +1,4 @@
-#!@PYTHON@
+#!@TOOLS_PYTHON@
#
# CDDL HEADER START
#
@@ -22,6 +22,7 @@
#
# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
#
#
@@ -29,7 +30,7 @@
# (space tab, trailing space)
#
-import sys, os
+import sys, os, io
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "lib",
"python%d.%d" % sys.version_info[:2]))
@@ -42,13 +43,12 @@ from onbld.Checks.WsCheck import wscheck
ret = 0
for filename in sys.argv[1:]:
try:
- fh = open(filename, 'r')
- except IOError, e:
+ with io.open(filename, encoding='utf-8',
+ errors='replace') as fh:
+ ret |= wscheck(fh, output=sys.stderr)
+ except IOError as e:
sys.stderr.write("failed to open '%s': %s\n" %
(e.filename, e.strerror))
- continue
-
- ret |= wscheck(fh, output=sys.stderr)
- fh.close()
+ continue
sys.exit(ret)
diff --git a/usr/src/tools/scripts/wsdiff.py b/usr/src/tools/scripts/wsdiff.py
index 367903a190..86b805b30f 100644
--- a/usr/src/tools/scripts/wsdiff.py
+++ b/usr/src/tools/scripts/wsdiff.py
@@ -1,4 +1,4 @@
-#!@PYTHON@
+#!@TOOLS_PYTHON@
#
# CDDL HEADER START
#
@@ -20,6 +20,7 @@
# CDDL HEADER END
#
# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
#
#
@@ -69,7 +70,8 @@
# -r Log results and observed differences
# -i Tell wsdiff which objects to compare via an input file list
-import datetime, fnmatch, getopt, os, profile, commands
+from __future__ import print_function
+import datetime, fnmatch, getopt, os, profile, subprocess
import re, resource, select, shutil, signal, string, struct, sys, tempfile
import time, threading
from stat import *
@@ -105,11 +107,12 @@ wsdiff_path = [ "/usr/bin",
# Ideally, we would purge use the use of __DATE__ from the source, but because
# this is source we wish to distribute with Solaris "unchanged", we cannot modify.
#
-wsdiff_exceptions = [ "usr/perl5/5.8.4/lib/sun4-solaris-64int/CORE/libperl.so.1",
- "usr/perl5/5.6.1/lib/sun4-solaris-64int/CORE/libperl.so.1",
- "usr/perl5/5.8.4/lib/i86pc-solaris-64int/CORE/libperl.so.1",
- "usr/perl5/5.6.1/lib/i86pc-solaris-64int/CORE/libperl.so.1"
- ]
+wsdiff_exceptions = [
+ "usr/perl5/5.8.4/lib/sun4-solaris-64int/CORE/libperl.so.1",
+ "usr/perl5/5.6.1/lib/sun4-solaris-64int/CORE/libperl.so.1",
+ "usr/perl5/5.8.4/lib/i86pc-solaris-64int/CORE/libperl.so.1",
+ "usr/perl5/5.6.1/lib/i86pc-solaris-64int/CORE/libperl.so.1"
+]
#####
# Logging routines
@@ -122,12 +125,12 @@ def debug(msg) :
msg = "## " + msg
if debugon :
output_lock.acquire()
- print >> sys.stdout, msg
+ print(msg)
sys.stdout.flush()
output_lock.release()
if logging :
log_lock.acquire()
- print >> log, msg
+ print(msg, file=log)
log.flush()
log_lock.release()
@@ -135,25 +138,25 @@ def debug(msg) :
def info(msg) :
output_lock.acquire()
- print >> sys.stdout, msg
+ print(msg)
sys.stdout.flush()
output_lock.release()
if logging :
log_lock.acquire()
- print >> log, msg
+ print(msg, file=log)
log.flush()
log_lock.release()
# Error message to be printed to the screen, and the log file
def error(msg) :
-
+
output_lock.acquire()
- print >> sys.stderr, "ERROR:", msg
+ print("ERROR: " + msg, file=sys.stderr)
sys.stderr.flush()
output_lock.release()
if logging :
log_lock.acquire()
- print >> log, "ERROR:", msg
+ print("ERROR: " + msg, file=log)
log.flush()
log_lock.release()
@@ -162,10 +165,10 @@ def v_info(msg) :
if logging :
log_lock.acquire()
- print >> log, msg
+ print(msg, file=log)
log.flush()
log_lock.release()
-
+
#
# Flag a detected file difference
# Display the fileName to stdout, and log the difference
@@ -179,7 +182,7 @@ def difference(f, dtype, diffs) :
if sorted :
differentFiles.append(f)
else:
- print >> sys.stdout, f
+ print(f)
sys.stdout.flush()
output_lock.release()
@@ -192,21 +195,20 @@ def log_difference(f, dtype, diffs) :
if logging :
log_lock.acquire()
- print >> log, f
- print >> log, "NOTE:", dtype, "difference detected."
+ print(f, file=log)
+ print("NOTE: " + dtype + " difference detected.", file=log)
difflen = len(diffs)
if difflen > 0 :
- print >> log
+ print('', file=log)
if not vdiffs and difflen > diffs_sz_thresh :
- print >> log, diffs[:diffs_sz_thresh]
- print >> log, \
- "... truncated due to length: " \
- "use -v to override ..."
+ print(diffs[:diffs_sz_thresh], file=log)
+ print("... truncated due to length: " +
+ "use -v to override ...", file=log)
else :
- print >> log, diffs
- print >> log, "\n"
+ print(diffs, file=log)
+ print('\n', file=log)
log.flush()
log_lock.release()
@@ -228,29 +230,30 @@ def diffFileData(tmpf1, tmpf2) :
binaries = True
tmp_od1 = tmpf1 + ".od"
tmp_od2 = tmpf2 + ".od"
-
+
cmd = od_cmd + " -c -t x4" + " " + tmpf1 + " > " + tmp_od1
os.system(cmd)
cmd = od_cmd + " -c -t x4" + " " + tmpf2 + " > " + tmp_od2
os.system(cmd)
-
+
tmpf1 = tmp_od1
tmpf2 = tmp_od2
try:
- data = commands.getoutput(diff_cmd + " " + tmpf1 + " " + tmpf2)
+ data = subprocess.check_output(
+ diff_cmd + " " + tmpf1 + " " + tmpf2)
# Remove the temp files as we no longer need them.
if binaries :
try:
os.unlink(tmp_od1)
- except OSError, e:
- error("diffFileData: unlink failed %s" % e)
+ except OSError as e:
+ error("diffFileData: unlink failed %s" % e)
try:
os.unlink(tmp_od2)
- except OSError, e:
- error("diffFileData: unlink failed %s" % e)
+ except OSError as e:
+ error("diffFileData: unlink failed %s" % e)
except:
- error("failed to get output of command: " + diff_cmd + " " \
+ error("failed to get output of command: " + diff_cmd + " "
+ tmpf1 + " " + tmpf2)
# Send exception for the failed command up
@@ -323,14 +326,15 @@ def fnFormat(fn) :
#
def usage() :
sys.stdout.flush()
- print >> sys.stderr, """Usage: wsdiff [-dvVst] [-r results ] [-i filelist ] old new
+ print("""Usage: wsdiff [-dvVst] [-r results ] [-i filelist ] old new
-d Print debug messages about the progress
-v Do not truncate observed diffs in results
-V Log *all* ELF sect diffs vs. logging the first diff found
-t Use onbld tools in $SRC/tools
-r Log results and observed differences
-s Produce sorted list of differences
- -i Tell wsdiff which objects to compare via an input file list"""
+ -i Tell wsdiff which objects to compare via an input file list""",
+ file=sys.stderr)
sys.exit(1)
#
@@ -360,7 +364,7 @@ def args() :
# arguments, the paths to the base (old), ptch (new) proto areas
try:
optlist, args = getopt.getopt(sys.argv[1:], validOpts)
- except getopt.error, val:
+ except getopt.error as val:
usage()
if len(args) != 2 :
@@ -508,7 +512,7 @@ def protoCatalog(base, ptch) :
baseFilesList = list(findFiles(base))
baseStringLength = len(base)
debug("Found " + str(len(baseFilesList)) + " files")
-
+
debug("Getting the list of files in the patch area");
ptchFilesList = list(findFiles(ptch))
ptchStringLength = len(ptch)
@@ -546,10 +550,10 @@ def protoCatalog(base, ptch) :
debug("Eliminating deleted files from the list of objects")
for fileName in deletedFiles :
try:
- compFiles.remove(fileName)
+ compFiles.remove(fileName)
except:
error("filelist.remove() failed")
- debug("List for comparison reduced to " + str(len(compFiles)) \
+ debug("List for comparison reduced to " + str(len(compFiles))
+ " files")
# New files appear in the patch area, but not the base
@@ -628,10 +632,10 @@ def flistCatalog(base, ptch, flist) :
elif ptch_present :
newFiles.append(fn)
else :
- if os.path.islink(base + fn) and \
- os.path.islink(ptch + fn) :
+ if (os.path.islink(base + fn) and
+ os.path.islink(ptch + fn)) :
continue
- error(f + " in file list, but not in either tree. " + \
+ error(f + " in file list, but not in either tree. " +
"Skipping...")
return compFiles, newFiles, deletedFiles
@@ -674,7 +678,7 @@ def get_elfheader(f) :
header = {}
- hstring = commands.getoutput(elfdump_cmd + " -c " + f)
+ hstring = subprocess.check_output(elfdump_cmd + " -c " + f)
if len(hstring) == 0 :
error("Failed to dump ELF header for " + f)
@@ -691,7 +695,7 @@ def get_elfheader(f) :
section = sect[datap:].split()[1]
datap = sect.find("sh_type:");
if datap == -1 :
- error("Could not get type for sect: " + section + \
+ error("Could not get type for sect: " + section +
" in " + f)
sh_type = sect[datap:].split()[2]
header[section] = sh_type
@@ -703,10 +707,10 @@ def get_elfheader(f) :
#
def extract_elf_section(f, section) :
- data = commands.getoutput(dump_cmd + " -sn " + section + " " + f)
+ data = subprocess.check_output(dump_cmd + " -sn " + section + " " + f)
if len(data) == 0 :
- error(dump_cmd + "yielded no data on section " + section + \
+ error(dump_cmd + "yielded no data on section " + section +
" of " + f)
raise
return
@@ -754,24 +758,24 @@ def diff_elf_section(f1, f2, section, sh_type) :
cmd1 = elfdump_cmd + " -i " + f1 + " > " + tmpFile1
cmd2 = elfdump_cmd + " -i " + f2 + " > " + tmpFile2
elif (section == ".symtab" or section == ".dynsym") :
- cmd1 = elfdump_cmd + " -s -N " + section + " " + f1 + \
- " > " + tmpFile1
- cmd2 = elfdump_cmd + " -s -N " + section + " " + f2 + \
- " > " + tmpFile2
+ cmd1 = (elfdump_cmd + " -s -N " + section + " " + f1 +
+ " > " + tmpFile1)
+ cmd2 = (elfdump_cmd + " -s -N " + section + " " + f2 +
+ " > " + tmpFile2)
elif (section in text_sections) :
# dis sometimes complains when it hits something it doesn't
# know how to disassemble. Just ignore it, as the output
# being generated here is human readable, and we've already
# correctly flagged the difference.
- cmd1 = dis_cmd + " -t " + section + " " + f1 + \
- " 2>/dev/null | grep -v disassembly > " + tmpFile1
- cmd2 = dis_cmd + " -t " + section + " " + f2 + \
- " 2>/dev/null | grep -v disassembly > " + tmpFile2
+ cmd1 = (dis_cmd + " -t " + section + " " + f1 +
+ " 2>/dev/null | grep -v disassembly > " + tmpFile1)
+ cmd2 = (dis_cmd + " -t " + section + " " + f2 +
+ " 2>/dev/null | grep -v disassembly > " + tmpFile2)
else :
- cmd1 = elfdump_cmd + " -w " + tmpFile1 + " -N " + \
- section + " " + f1
- cmd2 = elfdump_cmd + " -w " + tmpFile2 + " -N " + \
- section + " " + f2
+ cmd1 = (elfdump_cmd + " -w " + tmpFile1 + " -N " +
+ section + " " + f1)
+ cmd2 = (elfdump_cmd + " -w " + tmpFile2 + " -N " +
+ section + " " + f2)
os.system(cmd1)
os.system(cmd2)
@@ -781,12 +785,12 @@ def diff_elf_section(f1, f2, section, sh_type) :
# remove temp files as we no longer need them
try:
os.unlink(tmpFile1)
- except OSError, e:
- error("diff_elf_section: unlink failed %s" % e)
+ except OSError as e:
+ error("diff_elf_section: unlink failed %s" % e)
try:
os.unlink(tmpFile2)
- except OSError, e:
- error("diff_elf_section: unlink failed %s" % e)
+ except OSError as e:
+ error("diff_elf_section: unlink failed %s" % e)
return (data)
@@ -830,7 +834,7 @@ def compareElfs(base, ptch, quiet) :
base_header = get_elfheader(base)
except:
return
- sections = base_header.keys()
+ sections = base_header.keys()
try:
ptch_header = get_elfheader(ptch)
@@ -859,25 +863,25 @@ def compareElfs(base, ptch, quiet) :
slist = ""
for sect in e1_only_sections :
slist = slist + sect + "\t"
- data = "ELF sections found in " + \
- base + " but not in " + ptch + \
- "\n\n" + slist
+ data = ("ELF sections found in " +
+ base + " but not in " + ptch +
+ "\n\n" + slist)
difference(fileName, "ELF", data)
return 1
-
+
if len(e2_only_sections) > 0 :
if quiet :
return 1
-
+
data = ""
if logging :
slist = ""
for sect in e2_only_sections :
slist = slist + sect + "\t"
- data = "ELF sections found in " + \
- ptch + " but not in " + base + \
- "\n\n" + slist
+ data = ("ELF sections found in " +
+ ptch + " but not in " + base +
+ "\n\n" + slist)
difference(fileName, "ELF", data)
return 1
@@ -909,7 +913,7 @@ def compareElfs(base, ptch, quiet) :
if len(s1) != len (s2) or s1 != s2:
if not quiet:
sh_type = base_header[sect]
- data = diff_elf_section(base, ptch, \
+ data = diff_elf_section(base, ptch,
sect, sh_type)
# If all ELF sections are being reported, then
@@ -917,10 +921,10 @@ def compareElfs(base, ptch, quiet) :
# stdout only once. Any other section differences
# should be logged to the results file directly
if not first_section :
- log_difference(fileName, \
+ log_difference(fileName,
"ELF " + sect, data)
else :
- difference(fileName, "ELF " + sect, \
+ difference(fileName, "ELF " + sect,
data)
if not reportAllSects :
@@ -954,7 +958,7 @@ def compareArchives(base, ptch, fileType) :
fileName = fnFormat(base)
t = threading.currentThread()
- ArchTmpDir1 = tmpDir1 + os.path.basename(base) + t.getName()
+ ArchTmpDir1 = tmpDir1 + os.path.basename(base) + t.getName()
ArchTmpDir2 = tmpDir2 + os.path.basename(base) + t.getName()
#
@@ -966,42 +970,44 @@ def compareArchives(base, ptch, fileType) :
try:
os.makedirs(ArchTmpDir1)
- except OSError, e:
- error("compareArchives: makedir failed %s" % e)
+ except OSError as e:
+ error("compareArchives: makedir failed %s" % e)
return -1
try:
os.makedirs(ArchTmpDir2)
- except OSError, e:
- error("compareArchives: makedir failed %s" % e)
+ except OSError as e:
+ error("compareArchives: makedir failed %s" % e)
return -1
# copy over the objects to the temp areas, and
# unpack them
baseCmd = "cp -fp " + base + " " + ArchTmpDir1
- status, output = commands.getstatusoutput(baseCmd)
- if status != 0 :
+ try:
+ output = subprocess.check_output(baseCmd)
+ except CalledProcessError:
error(baseCmd + " failed: " + output)
clearTmpDirs(ArchTmpDir1, ArchTmpDir2)
return -1
ptchCmd = "cp -fp " + ptch + " " + ArchTmpDir2
- status, output = commands.getstatusoutput(ptchCmd)
- if status != 0 :
+ try:
+ output = subprocess.check_output(ptchCmd)
+ except CalledProcessError:
error(ptchCmd + " failed: " + output)
clearTmpDirs(ArchTmpDir1, ArchTmpDir2)
return -1
bname = string.split(fileName, '/')[-1]
if fileType == "Java Archive" :
- baseCmd = "cd " + ArchTmpDir1 + "; " + "jar xf " + bname + \
- "; rm -f " + bname + " META-INF/MANIFEST.MF"
- ptchCmd = "cd " + ArchTmpDir2 + "; " + "jar xf " + bname + \
- "; rm -f " + bname + " META-INF/MANIFEST.MF"
+ baseCmd = ("cd " + ArchTmpDir1 + "; " + "jar xf " + bname +
+ "; rm -f " + bname + " META-INF/MANIFEST.MF")
+ ptchCmd = ("cd " + ArchTmpDir2 + "; " + "jar xf " + bname +
+ "; rm -f " + bname + " META-INF/MANIFEST.MF")
elif fileType == "ELF Object Archive" :
- baseCmd = "cd " + ArchTmpDir1 + "; " + "/usr/ccs/bin/ar x " + \
- bname + "; rm -f " + bname
- ptchCmd = "cd " + ArchTmpDir2 + "; " + "/usr/ccs/bin/ar x " + \
- bname + "; rm -f " + bname
+ baseCmd = ("cd " + ArchTmpDir1 + "; " + "/usr/ccs/bin/ar x " +
+ bname + "; rm -f " + bname)
+ ptchCmd = ("cd " + ArchTmpDir2 + "; " + "/usr/ccs/bin/ar x " +
+ bname + "; rm -f " + bname)
else :
error("unexpected file type: " + fileType)
clearTmpDirs(ArchTmpDir1, ArchTmpDir2)
@@ -1026,22 +1032,22 @@ def compareArchives(base, ptch, fileType) :
for fn in ptchFlist :
if not fn in baseFlist :
- difference(fileName, fileType, \
+ difference(fileName, fileType,
fn + " added to " + fileName)
clearTmpDirs(ArchTmpDir1, ArchTmpDir2)
return 1
for fn in baseFlist :
if not fn in ptchFlist :
- difference(fileName, fileType, \
+ difference(fileName, fileType,
fn + " removed from " + fileName)
clearTmpDirs(ArchTmpDir1, ArchTmpDir2)
return 1
- differs = compareOneFile((ArchTmpDir1 + fn), \
+ differs = compareOneFile((ArchTmpDir1 + fn),
(ArchTmpDir2 + fn), True)
if differs :
- difference(fileName, fileType, \
+ difference(fileName, fileType,
fn + " in " + fileName + " differs")
clearTmpDirs(ArchTmpDir1, ArchTmpDir2)
return 1
@@ -1091,13 +1097,13 @@ def compareBasic(base, ptch, quiet, fileType) :
if needToSnip :
toSnipBegin = string.find(baseData, toSnipBeginStr)
if toSnipBegin != -1 :
- toSnipEnd = string.find(baseData[toSnipBegin:], \
- toSnipEndStr) + \
- len(toSnipEndStr)
- baseData = baseData[:toSnipBegin] + \
- baseData[toSnipBegin + toSnipEnd:]
- ptchData = ptchData[:toSnipBegin] + \
- ptchData[toSnipBegin + toSnipEnd:]
+ toSnipEnd = (string.find(baseData[toSnipBegin:],
+ toSnipEndStr) +
+ len(toSnipEndStr))
+ baseData = (baseData[:toSnipBegin] +
+ baseData[toSnipBegin + toSnipEnd:])
+ ptchData = (ptchData[:toSnipBegin] +
+ ptchData[toSnipBegin + toSnipEnd:])
if quiet :
if baseData != ptchData :
@@ -1126,20 +1132,20 @@ def compareByDumping(base, ptch, quiet, fileType) :
tmpFile2 = tmpDir2 + os.path.basename(ptch) + t.getName()
if fileType == "Lint Library" :
- baseCmd = lintdump_cmd + " -ir " + base + \
- " | egrep -v '(LINTOBJ|LINTMOD):'" + \
- " | grep -v PASS[1-3]:" + \
- " > " + tmpFile1
- ptchCmd = lintdump_cmd + " -ir " + ptch + \
- " | egrep -v '(LINTOBJ|LINTMOD):'" + \
- " | grep -v PASS[1-3]:" + \
- " > " + tmpFile2
+ baseCmd = (lintdump_cmd + " -ir " + base +
+ " | egrep -v '(LINTOBJ|LINTMOD):'" +
+ " | grep -v PASS[1-3]:" +
+ " > " + tmpFile1)
+ ptchCmd = (lintdump_cmd + " -ir " + ptch +
+ " | egrep -v '(LINTOBJ|LINTMOD):'" +
+ " | grep -v PASS[1-3]:" +
+ " > " + tmpFile2)
elif fileType == "Sqlite Database" :
- baseCmd = "echo .dump | " + sqlite_cmd + base + " > " + \
- tmpFile1
- ptchCmd = "echo .dump | " + sqlite_cmd + ptch + " > " + \
- tmpFile2
-
+ baseCmd = ("echo .dump | " + sqlite_cmd + base + " > " +
+ tmpFile1)
+ ptchCmd = ("echo .dump | " + sqlite_cmd + ptch + " > " +
+ tmpFile2)
+
os.system(baseCmd)
os.system(ptchCmd)
@@ -1165,24 +1171,24 @@ def compareByDumping(base, ptch, quiet, fileType) :
data = diffFileData(tmpFile1, tmpFile2);
try:
os.unlink(tmpFile1)
- except OSError, e:
- error("compareByDumping: unlink failed %s" % e)
+ except OSError as e:
+ error("compareByDumping: unlink failed %s" % e)
try:
os.unlink(tmpFile2)
- except OSError, e:
- error("compareByDumping: unlink failed %s" % e)
+ except OSError as e:
+ error("compareByDumping: unlink failed %s" % e)
difference(fileName, fileType, data)
- return 1
+ return 1
# Remove the temporary files now.
try:
os.unlink(tmpFile1)
- except OSError, e:
- error("compareByDumping: unlink failed %s" % e)
+ except OSError as e:
+ error("compareByDumping: unlink failed %s" % e)
try:
os.unlink(tmpFile2)
- except OSError, e:
- error("compareByDumping: unlink failed %s" % e)
+ except OSError as e:
+ error("compareByDumping: unlink failed %s" % e)
return 0
@@ -1194,7 +1200,7 @@ def compareByDumping(base, ptch, quiet, fileType) :
def discontinue_processing(signl, frme):
global keep_processing
- print >> sys.stderr, "Caught Ctrl-C, stopping the threads"
+ print("Caught Ctrl-C, stopping the threads", file=sys.stderr)
keep_processing = False
return 0
@@ -1204,29 +1210,29 @@ def discontinue_processing(signl, frme):
# worker thread for changedFiles processing
#
class workerThread(threading.Thread) :
- def run(self):
- global wset_lock
- global changedFiles
- global baseRoot
- global ptchRoot
- global keep_processing
-
- while (keep_processing) :
- # grab the lock to changedFiles and remove one member
- # and process it
- wset_lock.acquire()
- try :
- fn = changedFiles.pop()
- except IndexError :
- # there is nothing more to do
+ def run(self):
+ global wset_lock
+ global changedFiles
+ global baseRoot
+ global ptchRoot
+ global keep_processing
+
+ while (keep_processing) :
+ # grab the lock to changedFiles and remove one member
+ # and process it
+ wset_lock.acquire()
+ try :
+ fn = changedFiles.pop()
+ except IndexError :
+ # there is nothing more to do
+ wset_lock.release()
+ return
wset_lock.release()
- return
- wset_lock.release()
- base = baseRoot + fn
- ptch = ptchRoot + fn
+ base = baseRoot + fn
+ ptch = ptchRoot + fn
- compareOneFile(base, ptch, False)
+ compareOneFile(base, ptch, False)
#####
@@ -1278,10 +1284,10 @@ def cleanup(ret) :
debug("Performing cleanup (" + str(ret) + ")")
if os.path.isdir(tmpDir1) > 0 :
shutil.rmtree(tmpDir1)
-
+
if os.path.isdir(tmpDir2) > 0 :
shutil.rmtree(tmpDir2)
-
+
if logging :
log.close()
@@ -1352,13 +1358,13 @@ def main() :
if sorted :
differentFiles = []
- #
+ #
# Build paths to the tools required tools
#
# Try to look for tools in $SRC/tools if the "-t" option
# was specified
#
- arch = commands.getoutput("uname -p")
+ arch = subprocess.check_output("uname -p")
if localTools :
try:
src = os.environ['SRC']
@@ -1402,8 +1408,7 @@ def main() :
sys.exit(1)
if not os.path.exists(ptchRoot) :
- error("new proto area: " + ptchRoot + \
- " does not exist")
+ error("new proto area: " + ptchRoot + " does not exist")
sys.exit(1)
#
@@ -1422,12 +1427,12 @@ def main() :
tmpDir2 = "/tmp/wsdiff_tmp2_" + str(pid) + "/"
try:
os.makedirs(tmpDir1)
- except OSError, e:
- error("main: makedir failed %s" % e)
+ except OSError as e:
+ error("main: makedir failed %s" % e)
try:
os.makedirs(tmpDir2)
- except OSError, e:
- error("main: makedir failed %s" % e)
+ except OSError as e:
+ error("main: makedir failed %s" % e)
# Derive a catalog of new, deleted, and to-be-compared objects
# either from the specified base and patch proto areas, or from
@@ -1471,7 +1476,7 @@ def main() :
# the appropriate comparison routine, where the compare
# will happen, and any differences will be reported / logged
- # determine maximum number of worker threads by using
+ # determine maximum number of worker threads by using
# DMAKE_MAX_JOBS environment variable set by nightly(1)
# or get number of CPUs in the system
try:
@@ -1527,4 +1532,3 @@ if __name__ == '__main__' :
except KeyboardInterrupt :
cleanup(1);
-