#!/usr/bin/python # # pkgdiff -- check slackware package names against installed versions # # usage: See usage method, below. # # 1.0,14-Sep-2007: initial release # # Copyright (c) 2007 Brian "Beej Jorgensen" Hall # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import sys import os import os.path import glob PKGPATH='/var/adm/packages' class AppContext(object): def __init__(self, argv): self.filenamelist = [] self.scriptname = os.path.basename(argv[0]) i = 1 while i < len(argv): if argv[i] == "-h" or argv[i] == "--help": self.usageExit() else: self.filenamelist.append(argv[i]) i += 1 if self.filenamelist == []: self.usageExit() def usageExit(self): sys.stderr.write("usage: %s package1 [ package2 ... ]\n" % \ self.scriptname) sys.exit(1) def msg(self, s): sys.stderr.write("%s: %s\n" % (self.scriptname, s)) def parsePackageName(n): s = n.split("-") l = len(s) if l < 4: raise Exception("package name must be new style: %s" % n) else: # l >= 4 try: i = s[-1].index('.') s[-1] = s[-1][0:i] except: pass return ["-".join(s[0:len(s)-3])] + s[-3:] def main(argv): ac = AppContext(argv) for fn in ac.filenamelist: try: (pname, ver, arch, build) = parsePackageName(fn) except: ac.msg("ignoring non-standard package name: %s" % fn) continue #sys.stdout.write("%s-%s-%s-%s\n" % (pname, ver,arch,build)) candnames = glob.glob(os.sep.join((PKGPATH, '%s-*' % pname))) if len(candnames) == 0: sys.stdout.write("%s: not installed\n" % pname) else: for inspname in candnames: inspname = os.path.basename(inspname) try: (ipname, iver, iarch, ibuild) = parsePackageName(inspname) except: ac.msg("ignoring non-standard package name (installed): %s" % inspname) continue if ipname != pname: continue # not this package (different name) elif iver != ver: sys.stdout.write("%s-%s: installed version: %s\n" % \ (pname, ver, iver)) elif iarch != arch: sys.stdout.write("%s-%s: installed arch: %s\n" % \ (pname, arch, iarch)) elif ibuild != build: sys.stdout.write("%s-%s: installed build: %s\n" % \ (pname, build, ibuild)) else: #ac.msg("%s: installed and current" % (pname)) pass return 0 if __name__ == "__main__": sys.exit(main(sys.argv))