rempips: support generate without existing db

Signed-off-by: John McMaster <johndmcmaster@gmail.com>
This commit is contained in:
John McMaster 2018-11-27 14:27:05 -08:00
parent 3e7bad6f3f
commit 2477aecd8f
1 changed files with 16 additions and 13 deletions

View File

@ -12,19 +12,22 @@ def maketodo(pipfile, dbfile, strict=True):
line = line.split() line = line.split()
todos.add(line[0]) todos.add(line[0])
print('%s: %u entries' % (pipfile, len(todos)), file=sys.stderr) print('%s: %u entries' % (pipfile, len(todos)), file=sys.stderr)
with open(dbfile, "r") as f: # Support generate without existing DB
for line in f: if os.path.exists(dbfile) or strict:
line = line.split() with open(dbfile, "r") as f:
pip = line[0] for line in f:
try: line = line.split()
todos.remove(pip) pip = line[0]
except KeyError: try:
# DB (incorrectly) had multiple entries todos.remove(pip)
# Workaround for testing on old DB revision except KeyError:
if strict: # DB (incorrectly) had multiple entries
raise # Workaround for testing on old DB revision
print( if strict:
'WARNING: failed to remove pip %s' % pip, file=sys.stderr) raise
print(
'WARNING: failed to remove pip %s' % pip,
file=sys.stderr)
print('Remove %s: %u entries' % (dbfile, len(todos)), file=sys.stderr) print('Remove %s: %u entries' % (dbfile, len(todos)), file=sys.stderr)
drops = 0 drops = 0
lines = 0 lines = 0