#!/usr/bin/python -tt # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # #copyright 2011 Red Hat, inc # written by skvidal@fedoraproject.org # returns all the files on paths in the system not owned by a package # import yum import os import sys syspaths = {} # key = set rpmpaths = {} # key = set if len(sys.argv) == 1: paths = ('/etc/', '/usr/', '/lib/', '/lib64/', '/sbin/', '/bin/', '/opt/') else: paths = sys.argv[1:] for p in paths: rpmpaths[p] = set() syspaths[p] = set() rpmdb = yum.rpmsack.RPMDBPackageSack() for pkg in rpmdb: for fn in pkg.filelist + pkg.dirlist: found_path = False for p in paths: if not found_path: if fn.startswith(p): rpmpaths[p].add(fn) found_path = True continue else: break for p in paths: for (base, dirs, fns) in os.walk(p): if base[-1] == '/': base = base[:-1] for fn in dirs + fns: totfn = base + '/' + fn if os.path.islink(totfn): continue if totfn.endswith('~'): continue if totfn.endswith('.bak'): continue if totfn.endswith('.pp'): continue syspaths[p].add(totfn) for p in paths: res = syspaths[p].difference(rpmpaths[p]) if len(res): print 'files on system not in rpmdb in %s' % p print '\n '.join(sorted(res))