remove dupeOnSchemaChange

no longer required now that anki 1.x importing dropped
This commit is contained in:
Damien Elmes 2017-08-21 13:48:42 +10:00
parent ff2e7b9e81
commit 08e0174f2e
2 changed files with 5 additions and 50 deletions

View File

@ -19,7 +19,6 @@ class Anki2Importer(Importer):
needMapper = False needMapper = False
deckPrefix = None deckPrefix = None
allowUpdate = True allowUpdate = True
dupeOnSchemaChange = False
def run(self, media=None): def run(self, media=None):
self._prepareFiles() self._prepareFiles()
@ -65,9 +64,8 @@ class Anki2Importer(Importer):
# we may need to rewrite the guid if the model schemas don't match, # we may need to rewrite the guid if the model schemas don't match,
# so we need to keep track of the changes for the card import stage # so we need to keep track of the changes for the card import stage
self._changedGuids = {} self._changedGuids = {}
# apart from upgrading from anki1 decks, we ignore updates to changed # we ignore updates to changed schemas. we need to note the ignored
# schemas. we need to note the ignored guids, so we avoid importing # guids, so we avoid importing invalid cards
# invalid cards
self._ignoredGuids = {} self._ignoredGuids = {}
# iterate over source collection # iterate over source collection
add = [] add = []
@ -149,20 +147,9 @@ class Anki2Importer(Importer):
note[MID] = dstMid note[MID] = dstMid
if origGuid not in self._notes: if origGuid not in self._notes:
return True return True
# as the schemas differ and we already have a note with a different # schema changed; don't import
# note type, this note needs a new guid self._ignoredGuids[origGuid] = True
if not self.dupeOnSchemaChange: return False
self._ignoredGuids[origGuid] = True
return False
while True:
note[GUID] = incGuid(note[GUID])
self._changedGuids[origGuid] = note[GUID]
# if we don't have an existing guid, we can add
if note[GUID] not in self._notes:
return True
# if the existing guid shares the same mid, we can reuse
if dstMid == self._notes[note[GUID]][MID]:
return False
# Models # Models
###################################################################### ######################################################################

View File

@ -75,38 +75,6 @@ def test_apkg():
imp.run() imp.run()
assert len(os.listdir(tmp.media.dir())) == 2 assert len(os.listdir(tmp.media.dir())) == 2
def test_anki2_diffmodels():
# create a new empty deck
dst = getEmptyCol()
# import the 1 card version of the model
tmp = getUpgradeDeckPath("diffmodels2-1.apkg")
imp = AnkiPackageImporter(dst, tmp)
imp.dupeOnSchemaChange = True
imp.run()
before = dst.noteCount()
# repeating the process should do nothing
imp = AnkiPackageImporter(dst, tmp)
imp.dupeOnSchemaChange = True
imp.run()
assert before == dst.noteCount()
# then the 2 card version
tmp = getUpgradeDeckPath("diffmodels2-2.apkg")
imp = AnkiPackageImporter(dst, tmp)
imp.dupeOnSchemaChange = True
imp.run()
after = dst.noteCount()
# as the model schemas differ, should have been imported as new model
assert after == before + 1
# and the new model should have both cards
assert dst.cardCount() == 3
# repeating the process should do nothing
imp = AnkiPackageImporter(dst, tmp)
imp.dupeOnSchemaChange = True
imp.run()
after = dst.noteCount()
assert after == before + 1
assert dst.cardCount() == 3
def test_anki2_diffmodel_templates(): def test_anki2_diffmodel_templates():
# different from the above as this one tests only the template text being # different from the above as this one tests only the template text being
# changed, not the number of cards/fields # changed, not the number of cards/fields