summaryrefslogtreecommitdiffstats
path: root/utils/checkcards.py
blob: 6ac81755be1d74f2b30860074f8de32cc1ee440a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
import sys
import string

def usage():
    print "Usage: checkcards.py [pcitable] [Cards]"

if len(sys.argv) < 2:
    usage ()
    sys.exit (1)

pcifile = sys.argv[1]
cardsfile = sys.argv[2]

def getcards (cardsfile):
    cards = {}
    db = open (cardsfile)
    lines = db.readlines ()
    db.close ()
    card = {}
    name = None
    for line in lines:
        line = string.strip (line)
        if not line and name:
            cards[name] = card
            card = {}
            name = None
            continue

        if line and line[0] == '#':
            continue

        if len (line) > 4 and line[0:4] == 'NAME':
            name = line[5:]

        info = string.splitfields (line, ' ')
        if card.has_key (info[0]):
            card[info[0]] = card[info[0]] + '\n' + (string.joinfields (info[1:], ' '))
        else:
            card[info[0]] = string.joinfields (info[1:], ' ')

    return cards

pcitable = open (pcifile, 'r')
lines = pcitable.readlines()
cards = []
for line in lines:
    if line[0] == '#':
        continue
    fields = string.split(line, '\t')
    if len (fields) < 4:
        continue
    card = fields[2]
    if card[1:6] == "Card:":
        cards.append (card[6:-1])

carddb = getcards (cardsfile)

rc = 0
for card in cards:
    if not carddb.has_key(card):
        print "*** pcitable error *** Card not found:", card
        rc = 1

sys.exit(rc)