-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make uuids persistent when exporting with Anki 2.1.35 (≥ 2.1.28) #110
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,21 +48,36 @@ def export_to_directory(self, deck: AnkiDeck, output_dir=Path("."), copy_media=T | |
indent=4, | ||
ensure_ascii=False)) | ||
|
||
self._save_changes() | ||
self._save_changes(deck) | ||
|
||
if copy_media: | ||
self._copy_media(deck, deck_directory) | ||
|
||
return deck_directory | ||
|
||
def _save_changes(self): | ||
"""Save updates that were maid during the export. E.g. UUID fields""" | ||
# This saves decks and deck configurations | ||
self.collection.decks.save() | ||
self.collection.decks.flush() | ||
def _save_changes(self, deck, is_export_child=False): | ||
"""Save updates that were made during the export. E.g. UUID fields | ||
|
||
self.collection.models.save() | ||
self.collection.models.flush() | ||
It saves decks, deck configurations and models. | ||
aplaice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
is_export_child refers to whether this deck is a child for the | ||
_purposes of the current export operation_. For instance, if we're | ||
exporting or snapshotting a specific subdeck, then it's considered the | ||
"parent" here. We need the argument to avoid duplicately saving deck | ||
configs and note models. | ||
|
||
""" | ||
|
||
self.collection.decks.save(deck.anki_dict) | ||
for child_deck in deck.children: | ||
self._save_changes(child_deck, is_export_child=True) | ||
|
||
if not is_export_child: | ||
for deck_config in deck.metadata.deck_configs.values(): | ||
self.collection.decks.save(deck_config.anki_dict) | ||
Comment on lines
+76
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this does not seem right? we try to save deck config as a deck? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's pretty weird, but it's how it seems to work, according to Anki's source. FWIW There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. weird indeed |
||
|
||
for model in deck.metadata.models.values(): | ||
self.collection.models.save(model.anki_dict) | ||
|
||
# Notes? | ||
|
||
|
@@ -76,4 +91,4 @@ def _copy_media(self, deck, deck_directory): | |
shutil.copy(os.path.join(self.collection.media.dir(), file_src), | ||
str(media_directory.resolve())) | ||
except IOError as ioerror: | ||
print("Failed to copy a file {}. Full error: {}".format(file_src, ioerror)) | ||
print("Failed to copy a file {}. Full error: {}".format(file_src, ioerror)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this preserve changes to note uuid btw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean note model uuid? (If so, yes, I think so.) (Sorry, I might not have fully woken up yet, which is pretty embarrassing as it's already rather late here...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, I meant actual note uid. but it seems it falls back on using the native guid, nvm :p