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