Skip to content

Commit

Permalink
Merge branch 'main' into fix/dont-commit-if-there-was-an-exception
Browse files Browse the repository at this point in the history
  • Loading branch information
RisingOrange authored Dec 21, 2023
2 parents 4e63cca + 1ba5dec commit b76d211
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
13 changes: 11 additions & 2 deletions ankihub/gui/media_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,18 @@ def _update_deck_media_and_download_missing_media(self) -> None:
self._client.download_media(missing_media_names, ah_did)

def _update_deck_media(self, ankihub_did: uuid.UUID) -> None:
"""Fetch deck media updates from AnkiHub and update the database and the config."""
media_list: List[DeckMedia] = []
"""Fetch deck media updates from AnkiHub and update the database and the config.
If the deck configuration for the provided AnkiHub deck ID is not found (i.e., is None),
the function logs a warning and returns early without making any updates.
"""
deck_config = config.deck_config(ankihub_did)
if deck_config is None:
# This only happens if the deck gets deleted during the media sync.
LOGGER.warning(f"No deck config for {ankihub_did=}") # pragma: no cover
return # pragma: no cover

media_list: List[DeckMedia] = []
latest_update: Optional[datetime] = None
for chunk in self._client.get_deck_media_updates(
ankihub_did,
Expand Down
6 changes: 4 additions & 2 deletions ankihub/gui/operations/db_check/ah_db_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def check_ankihub_db(on_success: Optional[Callable[[], None]] = None) -> None:

def _fetch_missing_note_types() -> None:
"""Fetches note types which are missing from the database from AnkiHub.
This is necessary because in a previous version of the add-on, note types were not saved in the database."""
This is necessary because in a previous version of the add-on, note types were not saved in the database.
"""
client = AnkiHubClient()
for ah_did in ankihub_db.ankihub_deck_ids():
mids = ankihub_db.list(
Expand Down Expand Up @@ -76,8 +77,9 @@ def _try_reinstall_decks_with_something_missing(
else:
deck_names = sorted(
[
config.deck_config(deck_id).name
deck_config.name
for deck_id in ah_dids_with_missing_values
if (deck_config := config.deck_config(deck_id)) is not None
],
key=str.lower,
)
Expand Down
11 changes: 6 additions & 5 deletions ankihub/gui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,22 @@ def choose_ankihub_deck(
If 'ah_dids' param is provided, only the decks with those UUIDS will be listed.
When left as None (default value), all subscribed decks will be displayed.
"""

ah_dids = ah_dids or config.deck_ids()
deck_configs = [
(config.deck_config(did), did) for did in ah_dids if did in config.deck_ids()
ah_did_deck_config_tuples = [
(ah_did, deck_config)
for ah_did in ah_dids
if (deck_config := config.deck_config(ah_did)) is not None
]
chosen_deck_idx = choose_list(
prompt=prompt,
choices=[deck.name for deck, _ in deck_configs],
choices=[deck.name for _, deck in ah_did_deck_config_tuples],
parent=parent,
)

if chosen_deck_idx is None:
return None

chosen_deck_ah_did = deck_configs[chosen_deck_idx][1]
chosen_deck_ah_did = ah_did_deck_config_tuples[chosen_deck_idx][0]
return chosen_deck_ah_did


Expand Down

0 comments on commit b76d211

Please sign in to comment.