summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@macaw.me>2020-10-03 17:48:38 +0800
committerFrederick Yin <fkfd@macaw.me>2020-10-03 17:51:53 +0800
commitc786c52c0df11dad10273c73bd5aada10ea8ce62 (patch)
tree5f17e1b9e3c54325f631f6b6c40987a80d81a0d9
parente509856a5a10215f0eb368860efb18a6d6d6e62c (diff)
Rewrite downloader
Deprecate external downloader in favor of native handler Duplicates checking is NYI
-rw-r--r--picross/download.py30
-rw-r--r--picross/gui/controller.py18
2 files changed, 6 insertions, 42 deletions
diff --git a/picross/download.py b/picross/download.py
index 8683d24..bcc1c0c 100644
--- a/picross/download.py
+++ b/picross/download.py
@@ -1,29 +1,9 @@
from . import conf
from pathlib import Path
-import subprocess
-class DownloadConfigIncompleteError(Exception):
- pass
-
-
-class DownloadConfigNotFoundError(Exception):
- pass
-
-
-def download(url):
- # url: GeminiUrl
- try:
- if not conf.get("download-cmd") or not conf.get("download-dest"):
- raise DownloadConfigIncompleteError
- download_dest = Path(conf.get("download-dest")).expanduser()
- download_cmd = (
- conf.get("download-cmd")
- .replace("$URL", str(url))
- .replace("$DEST", str(download_dest))
- )
- except KeyError:
- raise DownloadConfigNotFoundError
-
- proc = subprocess.run(download_cmd, shell=True)
-
+def download(url, body):
+ filename = str(url).split("/")[-1]
+ with open(Path(conf.get("download-dest")).expanduser() / filename, "xb") as f:
+ f.write(body)
+ f.close()
diff --git a/picross/gui/controller.py b/picross/gui/controller.py
index 470d52e..2e900c2 100644
--- a/picross/gui/controller.py
+++ b/picross/gui/controller.py
@@ -252,23 +252,7 @@ class Controller:
return resp
except UnicodeDecodeError:
# try downloading as file instead
- # with the help of an external downloader, e.g. gemget
- try:
- download(url)
- except DownloadConfigIncompleteError:
- await self.put_gui_op(
- statusbar_logger.warn, "Download configuration incomplete"
- )
- return
- except DownloadConfigNotFoundError:
- await self.put_gui_op(
- statusbar_logger.warn, "Download configuration not found"
- )
- return
-
- await self.put_gui_op(
- statusbar_logger.info, f"Download initiated: {url}"
- )
+ download(url, resp.body)
return resp
# Sucessfully decoded body string!