Stvad / CrowdAnki

Plugin for Anki SRS designed to facilitate cooperation on creation of notes and decks.
MIT License
533 stars 44 forks source link

Git import that involves a redirect (uses a non-canonical path) fails #206

Open aplaice opened 10 months ago

aplaice commented 10 months ago

(Very minor, accidentally discovered while manually testing...)

If you try to import from a git repository via a non-canonical path (e.g. with different capitalisation — for instance https://github.com/Stvad/software_Engineering__git instead of https://github.com/Stvad/Software_Engineering__git), such that there is a redirect, then the import fails.

Details ``` Error: There is no /home/adam/test_crowdanki/addons21/1788670778/user_files/User 1/software_Engineering__git/software_Engineering__git.json file inside of the selected directory. While trying to import deck from directory /home/adam/test_crowdanki/addons21/1788670778/user_files/User 1/software_Engineering__git Anki 23.12.1 (1a1d4d54) (ao) Python 3.9.15 Qt 6.6.1 PyQt 6.6.1 Platform: Linux-6.2.0-39-generic-x86_64-with-glibc2.35 Traceback (most recent call last): File "/home/adam/test_crowdanki/addons21/1788670778/anki/ui/action_vendor.py", line 36, in lambda: GitImporter.on_git_import_action(self.window.col)) File "/home/adam/test_crowdanki/addons21/1788670778/github/github_importer.py", line 28, in on_git_import_action GitImporter(collection).import_from_git() File "/home/adam/test_crowdanki/addons21/1788670778/github/github_importer.py", line 33, in import_from_git self.clone_repository_and_import(repo_url) File "/home/adam/test_crowdanki/addons21/1788670778/github/github_importer.py", line 48, in clone_repository_and_import AnkiJsonImporter.import_deck_from_path(self.collection, repo_local_path) File "/home/adam/test_crowdanki/addons21/1788670778/importer/anki_importer.py", line 101, in import_deck_from_path if importer.load_deck(directory_path): File "/home/adam/test_crowdanki/addons21/1788670778/importer/anki_importer.py", line 29, in load_deck deck_json = self.read_deck(self.get_deck_path(directory_path)) File "/home/adam/test_crowdanki/addons21/1788670778/importer/anki_importer.py", line 76, in read_deck raise ValueError("There is no {} file inside of the selected directory".format(file_path)) ValueError: There is no /home/adam/test_crowdanki/addons21/1788670778/user_files/User 1/software_Engineering__git/software_Engineering__git.json file inside of the selected directory ===Add-ons (active)=== (add-on provided name [Add-on folder, installed at, version, is config changed]) CrowdAnki JSON exportimport Edit history Collaborate on deck creation ['1788670778', 2023-10-30T19:57, 'None', mod] ===IDs of active AnkiWeb add-ons=== 1788670778 ===Add-ons (inactive)=== (add-on provided name [Add-on folder, installed at, version, is config changed]) ```

I believe that the issue is that we git clone to a path given by the canonical name (i.e. "redirected name"), but then try to import the deck.json from a path given by the final part of the user-provided (non-canonical) name.

Presumably we should either:

  1. clone to the final part of the user-provided (non-canonical) name
  2. get the name of the successful clone and use that.

2 is probably preferable.