check-pci-ids.py 952 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python
  2. import re
  3. import sys
  4. # Check that the sorting order is preserved in pci.ids
  5. vendor_id = None
  6. device_id = None
  7. lineno = 1
  8. file = open("pci.ids")
  9. hexnum = '([0-9a-fA-F]{4})'
  10. desc = '(.*\\S)'
  11. for line in file:
  12. m = re.match(hexnum + '\\s+' + desc, line)
  13. if m:
  14. new_id = int('0x' + m.group (1), 16)
  15. if vendor_id is not None and new_id <= vendor_id:
  16. print ("%d: Vendor ID (0x%04x) is less that previous ID (0x%04x)" %
  17. (lineno, new_id, vendor_id))
  18. sys.exit (-1)
  19. vendor_id = new_id
  20. device_id = -1
  21. m = re.match('\t' + hexnum + '\\s+' + desc, line)
  22. if m:
  23. new_id = int('0x' + m.group (1), 16)
  24. if new_id <= device_id:
  25. print ("%d: Device ID (0x%04x) is less that previous ID (0x%04x)" %
  26. (lineno, new_id, device_id))
  27. sys.exit (-1)
  28. device_id = new_id
  29. lineno = lineno + 1