forked from litghost/prjxray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbcheck.py
47 lines (34 loc) · 1.21 KB
/
dbcheck.py
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
#!/usr/bin/env python3
import sys, re
database = dict()
database_r = dict()
for arg in sys.argv[1:]:
with open(arg, "r") as f:
for line in f:
if "<" in line:
raise Exception("Found '<' in this line: %s" % line)
line = line.split()
key = line[0]
bits = tuple(sorted(set(line[1:])))
if key in database:
print("Warning: Duplicate key: %s %s" % (key, bits))
if bits in database_r:
print("Warning: Duplicate bits: %s %s" % (key, bits))
database[key] = bits
database_r[bits] = key
def get_subsets(bits):
retval = list()
retval.append(bits)
for i in range(len(bits)):
for s in get_subsets(bits[i + 1:]):
retval.append(bits[0:i] + s)
return retval
def check_subsets(bits):
for sub_bits in sorted(get_subsets(bits)):
if sub_bits != bits and sub_bits != ():
if sub_bits in database_r:
print(
"Warning: Entry %s %s is a subset of entry %s %s." %
(database_r[sub_bits], sub_bits, database_r[bits], bits))
for key, bits in database.items():
check_subsets(bits)