diff options
Diffstat (limited to 'usr/src/tools/scripts/validate_pkg.py')
-rw-r--r-- | usr/src/tools/scripts/validate_pkg.py | 92 |
1 files changed, 47 insertions, 45 deletions
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]) |