Skip to content

Commit

Permalink
be more verbose in importing dialog
Browse files Browse the repository at this point in the history
Many users seem to get confused when duplicates are not imported,
so we list out what's being skipped now to help the users to be able
to search for the content.
  • Loading branch information
dae committed Nov 14, 2018
1 parent 66bbb76 commit beaca57
Showing 1 changed file with 48 additions and 15 deletions.
63 changes: 48 additions & 15 deletions anki/importing/anki2.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def _import(self):
# Notes
######################################################################

def _logNoteRow(self, action, noteRow):
self.log.append("[%s] %s" % (
action,
noteRow[6].replace("\x1f", ", ")
))

def _importNotes(self):
# build guid -> (id,mod,mid) hash & map of existing note ids
self._notes = {}
Expand All @@ -82,10 +88,12 @@ def _importNotes(self):
update = []
dirty = []
usn = self.dst.usn()
dupes = 0
dupesIdentical = []
dupesIgnored = []
total = 0
for note in self.src.db.execute(
"select * from notes"):
total += 1
# turn the db result into a mutable list
note = list(note)
shouldAdd = self._uniquifyNote(note)
Expand All @@ -104,7 +112,6 @@ def _importNotes(self):
self._notes[note[GUID]] = (note[0], note[3], note[MID])
else:
# a duplicate or changed schema - safe to update?
dupes += 1
if self.allowUpdate:
oldNid, oldMod, oldMid = self._notes[note[GUID]]
# will update if incoming note more recent
Expand All @@ -118,20 +125,47 @@ def _importNotes(self):
update.append(note)
dirty.append(note[0])
else:
dupesIgnored.append("%s: %s" % (
self.col.models.get(oldMid)['name'],
note[6].replace("\x1f", ",")
))
dupesIgnored.append(note)
self._ignoredGuids[note[GUID]] = True
if dupes:
up = len(update)
self.log.append(_("Updated %(a)d of %(b)d existing notes.") % dict(
a=len(update), b=dupes))
if dupesIgnored:
self.log.append(_("Some updates were ignored because note type has changed:"))
self.log.extend(dupesIgnored)
else:
dupesIdentical.append(note)

self.log.append(_("Notes found in file: %d") % total)

if dupesIgnored:
self.log.append(
_("Notes that could not be imported as note type has changed: %d") %
len(dupesIgnored))
if update:
self.log.append(
_("Notes updated, as file had newer version: %d") %
len(update))
if add:
self.log.append(
_("Notes added from file: %d") %
len(add))
if dupesIdentical:
self.log.append(
_("Notes skipped, as they're already in your collection: %d") %
len(dupesIdentical))

self.log.append("")

if dupesIgnored:
for row in dupesIgnored:
self._logNoteRow(_("Skipped"), row)
if update:
for row in update:
self._logNoteRow(_("Updated"), row)
if add:
for row in add:
self._logNoteRow(_("Added"), row)
if dupesIdentical:
for row in dupesIdentical:
self._logNoteRow(_("Identical"), row)

# export info for calling code
self.dupes = dupes
self.dupes = len(dupesIdentical)
self.added = len(add)
self.updated = len(update)
# add to col
Expand Down Expand Up @@ -335,7 +369,6 @@ def _importCards(self):
insert or ignore into cards values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""", cards)
self.dst.db.executemany("""
insert or ignore into revlog values (?,?,?,?,?,?,?,?,?)""", revlog)
self.log.append(ngettext("%d card imported.", "%d cards imported.", cnt) % cnt)

# Media
######################################################################
Expand Down

0 comments on commit beaca57

Please sign in to comment.