Beispiel #1
0
    def download_and_import_zip(self, github_repo, deck_base_name):
        response = urllib2.urlopen(GITHUB_LINK.format(github_repo))
        response_sio = StringIO.StringIO(response.read())
        with zipfile.ZipFile(response_sio) as repo_zip:
            repo_zip.extractall(tempfile.tempdir)

        deck_directory_wb = Path(tempfile.tempdir).joinpath(deck_base_name + "-" + BRANCH_NAME)
        deck_directory = Path(tempfile.tempdir).joinpath(deck_base_name)
        utils.fs_remove(deck_directory)
        deck_directory_wb.rename(deck_directory)
        # Todo progressbar on download
        
        AnkiJsonImporter.import_deck(self.collection, deck_directory)
    def download_and_import(self, repo):
        try:
            response = urllib2.urlopen(GITHUB_LINK.format(repo))
            response_sio = StringIO.StringIO(response.read())
            with zipfile.ZipFile(response_sio) as repo_zip:
                repo_zip.extractall(tempfile.tempdir)

            deck_base_name = repo.split("/")[-1]
            deck_directory_wb = Path(
                tempfile.tempdir).joinpath(deck_base_name + "-" + BRANCH_NAME)
            deck_directory = Path(tempfile.tempdir).joinpath(deck_base_name)
            utils.fs_remove(deck_directory)
            deck_directory_wb.rename(deck_directory)
            # Todo progressbar on download

            AnkiJsonImporter.import_deck(self.collection, deck_directory)

        except (urllib2.URLError, urllib2.HTTPError, OSError) as error:
            aqt.utils.showWarning(
                "Error while trying to get deck from Github: {}".format(error))
            raise
Beispiel #3
0
 def test_rm_nonexistant(self):
     # Should not crash :)
     nonexistant_path = Path("nonexistant_path")
     self.assertFalse(nonexistant_path.exists())
     utils.fs_remove(nonexistant_path)
Beispiel #4
0
 def test_rmdir(self):
     utils.fs_remove(self.dirpath)
     self.assertFalse(self.dirpath.exists())
     self.assertFalse(self.filepath.exists())
Beispiel #5
0
 def test_rmfile(self):
     self.assertTrue(self.filepath.exists())
     utils.fs_remove(self.filepath)
     self.assertFalse(self.filepath.exists())