better download errors

This commit is contained in:
Sander Land committed 2020-06-21 22:44:56 +02:00
1 parent 97ba67c2e4
commit e697cbe329
17 files changed
+60 -11

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
VERSION = "1.2.1"
VERSION = "1.2.2"
HOMEPAGE = "https://github.com/sanderland/katrain"
CONFIG_MIN_VERSION = "1.2.0"
+14 -2
View File
@@ -361,6 +361,12 @@ class ConfigPopup(QuickConfigGui):
self.katrain.log(f"Download of {model} model complete, but could not move file: {e}", OUTPUT_ERROR)
self.check_models()
for c in self.download_progress_box.children:
print(c,c.request)
if isinstance(c,ProgressLoader) and c.request:
c.request.cancel()
self.download_progress_box.clear_widgets()
downloading = False
for name, url in self.MODELS.items():
filename = os.path.split(url)[1]
if not any(os.path.split(f)[1] == filename for f in self.model_files.values):
@@ -374,11 +380,17 @@ class ConfigPopup(QuickConfigGui):
download_complete=lambda req, tmp=savepath_tmp, path=savepath, model=name: download_complete(
req, tmp, path, model
),
download_redirected=lambda req: self.katrain.log(
f"Download {name} redirected {req.resp_headers}", OUTPUT_DEBUG
download_redirected=lambda req,mname=name: self.katrain.log(
f"Download {mname} redirected {req.resp_headers}", OUTPUT_DEBUG
),
download_error=lambda req,mname=name: self.katrain.log(
f"Download of {mname} failed or cancelled {req.resp_headers}", OUTPUT_ERROR
),
)
progress.start(self.download_progress_box)
downloading = True
if not downloading:
self.download_progress_box.add_widget(Label(text=i18n._("All models downloaded")))
def update_config(self, save_to_file=True):
updated = super().update_config(save_to_file=save_to_file)
+18 -8
View File
@@ -47,6 +47,8 @@ class ProgressLoader(BoxLayout):
download_complete = ObjectProperty()
"""Function, called after a successful file upload."""
download_error = ObjectProperty()
"""Function, called after an error in downloading."""
download_redirected = ObjectProperty()
"""Function, called after a redirect event."""
@@ -56,6 +58,7 @@ class ProgressLoader(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.root_instance = None
self.request = None
def start(self, root_instance):
self.root_instance = root_instance
@@ -81,12 +84,14 @@ class ProgressLoader(BoxLayout):
file_path=path,
chunk_size=102400,
on_progress=self.update_progress,
on_success=self.on_success,
on_redirect=self.redirected,
on_error=self.download_error,
on_success=self.handle_success,
on_redirect=self.handle_redirect,
on_error=self.handle_error,
on_failure=self.handle_error,
on_cancel=self.handle_error,
)
def redirected(self, request, *_args):
def handle_redirect(self, request, *_args):
new_url = request.resp_headers.get("location")
if new_url:
self.download_url = new_url
@@ -94,8 +99,13 @@ class ProgressLoader(BoxLayout):
if self.download_redirected:
self.download_redirected(request)
def download_error(self, request, *_args):
pass
def cleanup(self):
self.root_instance.remove_widget(self)
def handle_error(self, request, *_args):
self.cleanup()
if self.download_error:
self.download_error(request)
def update_progress(self, request, current_size, total_size):
if total_size < 1e4:
@@ -103,7 +113,7 @@ class ProgressLoader(BoxLayout):
percent = current_size * 100 // max(total_size, 1)
self.label_downloading_text = self.downloading_text.format(percent)
def on_success(self, request, result):
self.root_instance.remove_widget(self)
def handle_success(self, request, result):
self.cleanup()
if self.download_complete:
self.download_complete(request)
Binary file not shown.
@@ -564,3 +564,7 @@ msgstr "{num} available model(s) found"
#. TODO
msgid "download models button"
msgstr "Download Models"
#. TODO
msgid "All models downloaded"
msgstr "All available models already downloaded"
Binary file not shown.
@@ -607,3 +607,7 @@ msgstr "{num} available model(s) found"
#. TODO
msgid "download models button"
msgstr "Download Models"
#. TODO
msgid "All models downloaded"
msgstr "All available models already downloaded"
Binary file not shown.
@@ -598,3 +598,6 @@ msgstr "Download Models"
msgid "models available"
msgstr "{num} available model(s) found"
msgid "All models downloaded"
msgstr "All available models already downloaded"
Binary file not shown.
@@ -602,3 +602,7 @@ msgstr "{num} available model(s) found"
#. TODO
msgid "download models button"
msgstr "Download Models"
#. TODO
msgid "All models downloaded"
msgstr "All available models already downloaded"
Binary file not shown.
@@ -641,3 +641,7 @@ msgstr "{num} available model(s) found"
#. TODO
msgid "download models button"
msgstr "Download Models"
#. TODO
msgid "All models downloaded"
msgstr "All available models already downloaded"
Binary file not shown.
@@ -579,3 +579,7 @@ msgstr "{num} available model(s) found"
#. TODO
msgid "download models button"
msgstr "Download Models"
#. TODO
msgid "All models downloaded"
msgstr "All available models already downloaded"
Binary file not shown.
@@ -604,3 +604,7 @@ msgstr "{num} available model(s) found"
#. TODO
msgid "download models button"
msgstr "Download Models"
#. TODO
msgid "All models downloaded"
msgstr "All available models already downloaded"