Merge pull request #90 from sanderland/v1.2.2

v1.2.2: better download errors & layout
This commit is contained in:
sanderland authored and GitHub committed 2020-06-22 18:52:13 +02:00
commit 283e2c840e
20 files changed
+97 -34

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@
"anim_pv_time": 0.5,
"debug_level": 0,
"lang": "en",
"version": "1.2.0"
"version": "1.2.2"
},
"timer": {
"byo_length": 30,
+5 -2
View File
@@ -85,13 +85,16 @@ class KaTrainBase:
config_file = user_config_file
self.log(f"Copied package config to local file {config_file}", OUTPUT_INFO)
else: # user file exists
version = JsonStore(user_config_file, indent=4).get("general")["version"]
try:
version = JsonStore(user_config_file).get("general")["version"]
except Exception: # broken file etc
version = "0.0.0"
if version < CONFIG_MIN_VERSION:
backup = user_config_file + f".{version}.backup"
shutil.copyfile(user_config_file, backup)
shutil.copyfile(package_config_file, user_config_file)
self.log(
f"Copied package config file to {user_config_file} as user file is outdated (<{CONFIG_MIN_VERSION}). Old version stored as {backup}",
f"Copied package config file to {user_config_file} as user file is outdated or broken ({version}<{CONFIG_MIN_VERSION}). Old version stored as {backup}",
OUTPUT_INFO,
)
config_file = user_config_file
+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"
+21 -10
View File
@@ -4,6 +4,7 @@ import re
from typing import Any, Dict, List, Tuple, Union
from kivy.clock import Clock
from kivy.metrics import dp
from kivy.properties import BooleanProperty, NumericProperty, StringProperty
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.boxlayout import BoxLayout
@@ -24,7 +25,7 @@ from katrain.core.constants import (
)
from katrain.core.engine import KataGoEngine
from katrain.core.lang import i18n
from katrain.core.utils import find_package_resource, PATHS
from katrain.core.utils import PATHS, find_package_resource
from katrain.gui.kivyutils import BackgroundMixin, I18NSpinner
from katrain.gui.style import DEFAULT_FONT, EVAL_COLORS
from katrain.gui.widgets.progress_loader import ProgressLoader
@@ -344,12 +345,9 @@ class ConfigPopup(QuickConfigGui):
self.model_files.text = models_available_msg
MODELS = {
# "pure 20b": "https://github.com/lightvector/KataGo/releases/download/v1.4.0/g170-b20c256x2-s4384473088-d968438914.bin.gz",
# "pure 30b": "https://github.com/lightvector/KataGo/releases/download/v1.4.0/g170-b30c320x2-s3530176512-d968463914.bin.gz",
# "pure 40b": "https://github.com/lightvector/KataGo/releases/download/v1.4.0/g170-b40c256x2-s3708042240-d967973220.bin.gz",
"final 20b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170e-b20c256x2-s5303129600-d1228401921.bin.gz",
"final 30b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b30c320x2-s4824661760-d1229536699.bin.gz",
"final 40b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b40c256x2-s5095420928-d1229425124.bin.gz",
"latest 20b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170e-b20c256x2-s5303129600-d1228401921.bin.gz",
"latest 30b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b30c320x2-s4824661760-d1229536699.bin.gz",
"latest 40b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b40c256x2-s5095420928-d1229425124.bin.gz",
}
def download_models(self, *_largs):
@@ -361,6 +359,11 @@ 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:
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):
@@ -370,15 +373,23 @@ class ConfigPopup(QuickConfigGui):
progress = ProgressLoader(
download_url=url,
path_to_file=savepath_tmp,
downloading_text=f"Downloading {name} model: " + "{}%",
downloading_text=f"Downloading {name} model: " + "{}",
label_downloading_text=f"Starting download for {name} model",
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, error, mname=name: self.katrain.log(
f"Download of {mname} failed or cancelled ({error})", 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"),text_size=(None,dp(50) )))
print('x')
def update_config(self, save_to_file=True):
updated = super().update_config(save_to_file=save_to_file)
+36 -16
View File
@@ -1,9 +1,9 @@
# From KivyMD which will remove it in their next version, with some fixes
from kivy.clock import Clock
from kivy.animation import Animation
from kivy.network.urlrequest import UrlRequest
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.properties import StringProperty, ObjectProperty
from kivy.network.urlrequest import UrlRequest
from kivy.properties import ObjectProperty, StringProperty
from kivy.uix.boxlayout import BoxLayout
Builder.load_string(
@@ -14,18 +14,22 @@ Builder.load_string(
<ProgressLoader>
opacity: 0
spacing: 10
size_hint_y: None
height: dp(25)
MDSpinner
id: spinner
size_hint: None, 0.8
width: dp(32)
size: dp(23), dp(23)
color: 0.95,0.95,0.95,1
MDLabel:
id: label_download
max_lines: 2
shorten: True
max_lines: 1
shorten_from: 'right'
halign: 'left'
valign: 'center'
text_size: self.size
height: dp(23)
color: 0.95,0.95,0.95,1
text: root.label_downloading_text
"""
@@ -47,6 +51,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 +62,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,29 +88,42 @@ 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=lambda req, error: self.handle_error(req, error),
on_failure=lambda req, res: self.handle_error(req, "Failure"),
on_cancel=lambda req: self.handle_error(req, "Cancelled"),
)
def redirected(self, request, *_args):
new_url = request.resp_headers.get("location")
def handle_redirect(self, request, *_args):
new_url = request.resp_headers.get("location") or request.resp_headers.get("Location")
if new_url:
self.download_url = new_url
self.request_download_file(self.download_url, self.path_to_file)
else:
self.handle_error()
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, error):
status = f"Error: {error}"
if request.resp_status:
status += f" ({request.resp_status})"
self.label_downloading_text = self.downloading_text.format(status)
self.ids.spinner.active = False
if self.download_error:
self.download_error(request, error)
def update_progress(self, request, current_size, total_size):
if total_size < 1e4:
current_size = 0
percent = current_size * 100 // max(total_size, 1)
self.label_downloading_text = self.downloading_text.format(percent)
percent = current_size / max(total_size, 1)
self.label_downloading_text = self.downloading_text.format(f"{percent:.1%}")
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"
+6 -4
View File
@@ -199,18 +199,20 @@
LabelledFloatInput:
input_property: "engine/wide_root_noise"
hint_text: i18n._("engine:wide_root_noise:hint")
BoxLayout:
MDBoxLayout:
orientation: 'horizontal'
size_hint: 1,1.5
BoxLayout:
MDBoxLayout:
size_hint_x: 4 if self.children else 0.0001
orientation: 'vertical'
id: download_progress_box
AnchorLayout:
AutoSizedRoundedRectangleButton:
padding_x: 15
size_hint: None,0.5
size_hint: None,None
height: dp(40)
text: i18n._("update settings")
on_press: root.update_config(True)
Widget: # for centering
<ConfigTeacherPopup>
options_grid: options_grid