check-uniq-files 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python
  2. import sys
  3. import csv
  4. import argparse
  5. from collections import defaultdict
  6. warn = 'Warning: {0} file "{1}" is touched by more than one package: {2}\n'
  7. def main():
  8. parser = argparse.ArgumentParser()
  9. parser.add_argument('packages_file_list', nargs='*',
  10. help='The packages-file-list to check from')
  11. parser.add_argument('-t', '--type', metavar="TYPE",
  12. help='Report as a TYPE file (TYPE is either target, staging, or host)')
  13. args = parser.parse_args()
  14. if not len(args.packages_file_list) == 1:
  15. sys.stderr.write('No packages-file-list was provided.\n')
  16. return False
  17. if args.type is None:
  18. sys.stderr.write('No type was provided\n')
  19. return False
  20. file_to_pkg = defaultdict(list)
  21. with open(args.packages_file_list[0], 'rb') as pkg_file_list:
  22. for line in pkg_file_list.readlines():
  23. pkg, _, file = line.rstrip(b'\n').partition(b',')
  24. file_to_pkg[file].append(pkg)
  25. for file in file_to_pkg:
  26. if len(file_to_pkg[file]) > 1:
  27. # If possible, try to decode the binary strings with
  28. # the default user's locale
  29. try:
  30. sys.stderr.write(warn.format(args.type, file.decode(),
  31. [p.decode() for p in file_to_pkg[file]]))
  32. except UnicodeDecodeError:
  33. # ... but fallback to just dumping them raw if they
  34. # contain non-representable chars
  35. sys.stderr.write(warn.format(args.type, file,
  36. file_to_pkg[file]))
  37. if __name__ == "__main__":
  38. sys.exit(main())