From a67ce58d2a17a1bfe20952bfaceb71cd4bbad541 Mon Sep 17 00:00:00 2001 From: Adam Plaice Date: Sun, 15 May 2022 14:58:47 +0200 Subject: [PATCH 1/2] Adapt to 2.1.50+ backup mechanism Fix #166. It's no longer necessary for the collection to be closed before a backup, and AFAICT a closed collection can't even be backed up. See PR 1728 in Anki itself. Break compatibility with 2.1.49-. --- crowd_anki/importer/anki_importer.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crowd_anki/importer/anki_importer.py b/crowd_anki/importer/anki_importer.py index a3638af..01ef1f3 100644 --- a/crowd_anki/importer/anki_importer.py +++ b/crowd_anki/importer/anki_importer.py @@ -33,9 +33,7 @@ def load_deck(self, directory_path) -> bool: return False if aqt.mw: - aqt.mw.col.close(downgrade=False) - aqt.mw.backup() - aqt.mw.col.reopen(after_full_sync=False) + aqt.mw.create_backup_now() try: deck = deck_initializer.from_json(deck_json) deck.save_to_collection(self.collection, import_config=import_config) From d743f249c828f1c1a62074f1c1f4934324e363c5 Mon Sep 17 00:00:00 2001 From: Adam Plaice Date: Sun, 15 May 2022 15:07:08 +0200 Subject: [PATCH 2/2] Silence most verbose deprecation warnings (in 2.1.50+) I've left the Qt warnings alone for now, since the behaviour varies between Qt5 and Qt6. --- crowd_anki/anki/overrides/exporting.py | 2 +- crowd_anki/representation/deck.py | 2 +- crowd_anki/representation/note.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crowd_anki/anki/overrides/exporting.py b/crowd_anki/anki/overrides/exporting.py index aa10713..d8e5ad7 100644 --- a/crowd_anki/anki/overrides/exporting.py +++ b/crowd_anki/anki/overrides/exporting.py @@ -23,7 +23,7 @@ def get_save_file(parent, title, dir_description, key, ext, fname=None): directory = str(QFileDialog.getExistingDirectory(caption="Select Export Directory", directory=fname)) if directory: - return os.path.join(directory, str(anki.utils.intTime())) + return os.path.join(directory, str(anki.utils.int_time())) return None return aqt.utils.getSaveFile_old(parent, title, dir_description, key, ext, fname) diff --git a/crowd_anki/representation/deck.py b/crowd_anki/representation/deck.py index 769fcc3..acf39d7 100644 --- a/crowd_anki/representation/deck.py +++ b/crowd_anki/representation/deck.py @@ -107,7 +107,7 @@ def get_media_file_list(self, data_from_models=True, include_children=True): # TODO Remove compatibility shims for Anki 2.1.46 and # lower. join_fields = anki_object.joined_fields if hasattr(anki_object, 'joined_fields') else anki_object.joinedFields - for media_file in self.collection.media.filesInStr(anki_object.mid, join_fields()): + for media_file in self.collection.media.files_in_str(anki_object.mid, join_fields()): media.add(media_file) if include_children: diff --git a/crowd_anki/representation/note.py b/crowd_anki/representation/note.py index 34be171..3d34926 100644 --- a/crowd_anki/representation/note.py +++ b/crowd_anki/representation/note.py @@ -122,7 +122,7 @@ def save_to_collection(self, collection, deck, model_map_cache, import_config): self.anki_object.__dict__.update(self.anki_object_dict) self.anki_object.mid = note_model.anki_dict["id"] - self.anki_object.mod = anki.utils.intTime() + self.anki_object.mod = anki.utils.int_time() if new_note: collection.add_note(self.anki_object, deck.anki_dict["id"])