-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow CrowdAnki export for the default 2.1.55+ exporter
Fix #169. The old, legacy exporter (Tools > Preferences > Legacy import/export handling) had worked before this commit and now still works. AFAICT compatibility with Anki 2.1.50+ has been maintained (2.1.50, 2.1.54 and 2.1.55 explicitly tested). Note that in Anki 2.1.54, CrowdAnki export is only available for the old, then default (non-beta) export method, since the hook that allows easy CrowdAnki to work with the new method was AFAICT only added in 2.1.55.
- Loading branch information
Showing
6 changed files
with
224 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Compat for Anki 2.1.54- | ||
# | ||
# This is copied verbatim from `qt/aqt/import_export/exporting.py` (in | ||
# Anki 2.1.55). We need it for our tests, which still assume that we | ||
# have Anki 2.1.26 and where the above module is missing. We can't | ||
# upgrade our dependency to Anki 2.1.55 which has the module, because | ||
# we're still using Python 3.7 with which latest Anki is incompatible. | ||
# | ||
# We could instead mock the imports from aqt.import_export.exporting | ||
# (Exporter), but given that AnkiJsonExporterWrapperNew inherits from | ||
# Exporter, this feels a bit too magical. Also, using the way in this | ||
# file, we keep compatibility for Anki 2.1.50+ (the oldest we support | ||
# atm), for a while longer. | ||
|
||
from abc import ABC, abstractmethod | ||
from dataclasses import dataclass | ||
|
||
from typing import Any | ||
|
||
import aqt.main | ||
|
||
ExportLimit = Any | ||
|
||
@dataclass | ||
class ExportOptions: | ||
out_path: str | ||
include_scheduling: bool | ||
include_media: bool | ||
include_tags: bool | ||
include_html: bool | ||
include_deck: bool | ||
include_notetype: bool | ||
include_guid: bool | ||
legacy_support: bool | ||
limit: ExportLimit | ||
|
||
class Exporter(ABC): | ||
extension: str | ||
show_deck_list = False | ||
show_include_scheduling = False | ||
show_include_media = False | ||
show_include_tags = False | ||
show_include_html = False | ||
show_legacy_support = False | ||
show_include_deck = False | ||
show_include_notetype = False | ||
show_include_guid = False | ||
|
||
@abstractmethod | ||
def export(self, mw: aqt.main.AnkiQt, options: ExportOptions) -> None: | ||
pass | ||
|
||
@staticmethod | ||
@abstractmethod | ||
def name() -> str: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CrowdAnkiException(Exception): | ||
"""Base class for CrowdAnki's exceptions.""" | ||
pass | ||
|
||
class UnexportableDeckException(CrowdAnkiException): | ||
"""Exception for decks that are not CrowdAnki-exportable. | ||
This is currently the set of all decks and filtered decks. | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters