From 3e269ee2dfceb005b7418336cf0f3a5d821c3027 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Mon, 23 Oct 2023 15:01:08 +0200 Subject: [PATCH 1/3] fix: correctly sync dirs in bind mounts --- application/main.py | 17 ++++++++++++----- docker_cmd.sh | 5 ++++- .../exporters/anki/sync.py | 11 +++++++---- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/application/main.py b/application/main.py index e1b00eb..90de492 100644 --- a/application/main.py +++ b/application/main.py @@ -26,14 +26,20 @@ def request(action: Any, **params: Any) -> Dict[str, Any]: def main( - recur_dir: Path, - project_dir: Path, + input_dir: Path, + host_output_dir: Path, watch: Annotated[ bool, typer.Option(help="Keep running, updating Anki deck every 15 seconds"), ], ): """Run the thing.""" + if not input_dir.exists(): + raise FileNotFoundError(f"Input directory {input_dir} does not exist") + + if not host_output_dir.exists(): + msg.info(f"Creating output directory {host_output_dir}") + host_output_dir.mkdir(parents=True, exist_ok=True) sentry_sdk.init( dsn="https://37f17d6aa7742424652663a04154e032@o4506053997166592.ingest.sentry.io/4506053999984640", @@ -54,7 +60,7 @@ def main( ], card_exporter=AnkiPackageGenerator(), # Step 3, get the cards from the prompts ).run( - input_path=recur_dir, + input_path=input_dir, ) decks = defaultdict(list) @@ -66,7 +72,8 @@ def main( deck_bundle = AnkiPackageGenerator().cards_to_deck_bundle(cards=decks[deck]) sync_deck( deck_bundle=deck_bundle, - dir_path=Path(__file__).parent, + sync_dir_path=host_output_dir, + save_dir_path=Path("/output"), max_wait_for_ankiconnect=30, ) @@ -74,7 +81,7 @@ def main( sleep_seconds = 60 msg.good(f"Sync complete, sleeping for {sleep_seconds} seconds") sleep(sleep_seconds) - main(recur_dir=recur_dir, project_dir=project_dir, watch=watch) + main(input_dir=input_dir, watch=watch) if __name__ == "__main__": diff --git a/docker_cmd.sh b/docker_cmd.sh index 4d137cf..5061a08 100755 --- a/docker_cmd.sh +++ b/docker_cmd.sh @@ -1,7 +1,10 @@ docker build . -t personal-mnemonic-medium -f Dockerfile +docker volume create ankidecks + docker run -itd \ -v $HOME/Library/Mobile\ Documents/iCloud~md~obsidian/Documents/Life\ Lessons\ iCloud/:/input \ + -v $HOME/ankidecks:/output \ --restart unless-stopped \ personal-mnemonic-medium \ - python application/main.py /input/ Life.apkg --watch \ No newline at end of file + python application/main.py /input/ $HOME/ankidecks --watch \ No newline at end of file diff --git a/src/personal_mnemonic_medium/exporters/anki/sync.py b/src/personal_mnemonic_medium/exporters/anki/sync.py index 0de09fc..33cbc21 100644 --- a/src/personal_mnemonic_medium/exporters/anki/sync.py +++ b/src/personal_mnemonic_medium/exporters/anki/sync.py @@ -63,7 +63,8 @@ def anki_connect_is_live() -> bool: # Borrowed from https://github.com/lukesmurray/markdown-anki-decks/blob/de6556d7ecd2d39335607c05171f8a9c39c8f422/markdown_anki_decks/sync.py#L64 def sync_deck( deck_bundle: DeckBundle, - dir_path: Path, + save_dir_path: Path, + sync_dir_path: Path, delete_cards: bool = True, max_wait_for_ankiconnect: int = 30, ): @@ -101,9 +102,10 @@ def sync_deck( msg.info("\tNotes removed: ") msg.info(f"\t\t{removed_note_guids}") - package_path = deck_bundle.save_deck_to_file(dir_path / "deck.apkg") + package_path = deck_bundle.save_deck_to_file(save_dir_path / "deck.apkg") try: - invoke("importPackage", path=str(package_path)) + sync_path = str(sync_dir_path / "deck.apkg") + invoke("importPackage", path=sync_path) print(f"Imported {deck_bundle.deck.name}!") if delete_cards: @@ -127,7 +129,8 @@ def sync_deck( traceback.print_exc() except Exception as e: print(f"Unable to sync {package_path} to anki") - print(f"\t{e}") + print(f"{e}") + traceback.print_exc() else: msg.info("Skipped") msg.info(f"{deck_bundle.deck.name}") From f91f319e46935ce423489d49289f8715fa5c13b4 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Wed, 25 Oct 2023 16:40:17 +0200 Subject: [PATCH 2/3] misc. --- application/main.py | 2 +- makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/main.py b/application/main.py index 90de492..3feed92 100644 --- a/application/main.py +++ b/application/main.py @@ -81,7 +81,7 @@ def main( sleep_seconds = 60 msg.good(f"Sync complete, sleeping for {sleep_seconds} seconds") sleep(sleep_seconds) - main(input_dir=input_dir, watch=watch) + main(input_dir=input_dir, watch=watch, host_output_dir=host_output_dir) if __name__ == "__main__": diff --git a/makefile b/makefile index c5232d6..ad13edd 100644 --- a/makefile +++ b/makefile @@ -22,7 +22,7 @@ validate: @make lint && make type-check && make test pr: + gh pr create make validate git push - gh pr create gh pr merge --auto --merge \ No newline at end of file From 654349a36bab5bd1ef9015a572dab176fcdecb09 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Wed, 25 Oct 2023 14:42:59 +0000 Subject: [PATCH 3/3] ci: create pr on web --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index ad13edd..a547efa 100644 --- a/makefile +++ b/makefile @@ -22,7 +22,7 @@ validate: @make lint && make type-check && make test pr: - gh pr create + gh pr create -w make validate git push gh pr merge --auto --merge \ No newline at end of file