borrowed from ubuntu git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux-firmware
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

check_whence.py 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/python
  2. import os, re, sys
  3. def list_whence():
  4. with open('WHENCE') as whence:
  5. for line in whence:
  6. match = re.match(r'(?:File|Link|Source):\s*(\S*)', line)
  7. if match:
  8. yield match.group(1)
  9. continue
  10. match = re.match(r'Licen[cs]e: (?:.*\bSee (.*) for details\.?|(\S*))\n',
  11. line)
  12. if match:
  13. if match.group(1):
  14. for name in re.split(r', | and ', match.group(1)):
  15. yield name
  16. continue
  17. if match.group(2):
  18. # Just one word - may or may not be a filename
  19. if not re.search(r'unknown|distributable', match.group(2),
  20. re.IGNORECASE):
  21. yield match.group(2)
  22. continue
  23. def list_git():
  24. with os.popen('git ls-files') as git_files:
  25. for line in git_files:
  26. yield line.rstrip('\n')
  27. def main():
  28. whence_list = list(list_whence())
  29. known_files = set(name for name in whence_list if not name.endswith('/')) | \
  30. set(['check_whence.py', 'configure', 'Makefile',
  31. 'README', 'WHENCE'])
  32. known_prefixes = set(name for name in whence_list if name.endswith('/'))
  33. git_files = set(list_git())
  34. for name in sorted(list(known_files - git_files)):
  35. sys.stderr.write('E: %s listed in WHENCE does not exist\n' % name)
  36. for name in sorted(list(git_files - known_files)):
  37. # Ignore subdirectory changelogs and GPG detached signatures
  38. if (name.endswith('/ChangeLog') or
  39. (name.endswith('.asc') and name[:-4] in known_files)):
  40. continue
  41. # Ignore unknown files in known directories
  42. for prefix in known_prefixes:
  43. if name.startswith(prefix):
  44. break
  45. else:
  46. sys.stderr.write('E: %s not listed in WHENCE\n' % name)
  47. if __name__ == '__main__':
  48. main()