source: projects/hwdata/trunk/check-pci-ids.py @ 7989

Revision 7989, 923 bytes checked in by daisuke, 10 years ago (diff)

forked.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3import re
4import sys
5
6# Check that the sorting order is preserved in pci.ids
7
8vendor_id = None
9device_id = None
10lineno    = 1
11
12file = open("pci.ids")
13hexnum = '([0-9a-fA-F]{4})'
14desc = '(.*\S)'
15
16for 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 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
Note: See TracBrowser for help on using the repository browser.