Last active
February 1, 2016 15:37
-
-
Save frafra/c1f6267f532970339979 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# https://fedoraproject.org/wiki/Packaging:Guidelines#File_and_Directory_Ownership | |
# Made by Frafra | |
import collections | |
import rpm | |
def depchain_check(pkg, pkgs): | |
ts = rpm.TransactionSet() | |
ts.addErase(pkg) | |
ts.setFlags(rpm.RPMTRANS_FLAG_TEST) | |
ts.run(lambda *args: None, []) | |
rdep = [problem[0][0] for problem in ts.check()] | |
return sorted(pkgs.intersection(rdep)) | |
depchain_cache = {} | |
thefts = collections.defaultdict(list) | |
def look_for_thieves(filename, pkgs): | |
for pkg in pkgs: | |
if pkg not in depchain_cache: | |
depchain = depchain_check(pkg, pkgs) | |
depchain_cache[pkg] = depchain | |
else: | |
depchain = depchain_cache[pkg] | |
if depchain: | |
thefts[pkg].append(filename) | |
def multiple_pkgs_filter(dictionary): | |
for filename, pkgs in dictionary.items(): | |
if len(pkgs) > 1: | |
if not pkgs in srpm_rpm.values(): | |
yield filename, pkgs | |
srpm_rpm = collections.defaultdict(set) | |
def main(): | |
files_rpms = collections.defaultdict(set) | |
ts = rpm.TransactionSet() | |
mi = ts.dbMatch() | |
for h in mi: | |
pkg = h['name'].decode() | |
for filename in h['filenames']: | |
files_rpms[filename.decode()].add(pkg) | |
srpm_rpm[h['sourcerpm'].decode()].add(pkg) | |
for filename, pkgs in multiple_pkgs_filter(files_rpms): | |
look_for_thieves(filename, pkgs) | |
for pkg, files in thefts.items(): | |
print("%s require(s) %s but they own:" % (' '.join(depchain_cache[pkg]), pkg)) | |
for filename in sorted(files): | |
print(' - '+filename) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment