dbfixup: duplicate line workaround

Signed-off-by: John McMaster <JohnDMcMaster@gmail.com>
Signed-off-by: Tim 'mithro' Ansell <mithro@mithis.com>
This commit is contained in:
John McMaster 2017-12-11 18:39:17 -08:00 committed by Tim 'mithro' Ansell
parent baa9bb0d02
commit 534c2930c7
1 changed files with 6 additions and 0 deletions

View File

@ -35,8 +35,13 @@ def add_zero_bits(tile_type):
assert os.getenv("XRAY_DATABASE") == "artix7"
dbfile = "%s/%s/segbits_%s.db" % (os.getenv("XRAY_DATABASE_DIR"), os.getenv("XRAY_DATABASE"), tile_type)
new_lines = set()
llast = None
with open(dbfile, "r") as f:
for line in f:
# Hack: skip duplicate lines
# This happens while merging a new multibit entry
if line == llast:
continue
line = line.split()
tag = line[0]
bits = set(line[1:])
@ -69,6 +74,7 @@ def add_zero_bits(tile_type):
if bit not in bits:
bits.add("!" + bit)
new_lines.add(" ".join([tag] + sorted(bits)))
llast = line
with open(dbfile, "w") as f:
for line in sorted(new_lines):
print(line, file=f)