Fix bugs, add update system + tests + fix deployment/build system
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import os
|
||||
import webbrowser
|
||||
from webpicdownloader.controller.Frames import Frames
|
||||
from webpicdownloader.util.UpdateUtils import check_for_update
|
||||
|
||||
|
||||
class MainController:
|
||||
@@ -11,8 +13,8 @@ class MainController:
|
||||
|
||||
@author Jérémi Nihart / EndMove
|
||||
@link https://git.endmove.eu/EndMove/WebPicDownloader
|
||||
@version 1.0.0
|
||||
@since 2022-08-30
|
||||
@version 1.0.1
|
||||
@since 2022-09-11
|
||||
"""
|
||||
# Variables
|
||||
__config: dict = None
|
||||
@@ -64,8 +66,13 @@ class MainController:
|
||||
[event function for view]
|
||||
=> Event launched when a check for available updates is requested.
|
||||
"""
|
||||
# TODO write the function
|
||||
self.show_information_dialog(self.get_config('app_name'), "Oupss, this functionality isn't available yet!\nTry it again later.")
|
||||
try:
|
||||
if check_for_update(self.get_config('app_version'), self.get_config('app_depo_version'), self.get_config('sys_version_matcher')):
|
||||
if self.show_question_dialog(self.get_config('app_name'), "An update is available! Would you like to visit the release page to download the latest version?"):
|
||||
webbrowser.open(self.get_config('app_depo_releases'))
|
||||
else: self.show_information_dialog(self.get_config('app_name'), "No update available.")
|
||||
except Exception as e:
|
||||
self.show_information_dialog(self.get_config('app_name'), f"An error occured: {e}.", 'error')
|
||||
|
||||
def on_about(self) -> None:
|
||||
"""
|
||||
@@ -85,12 +92,13 @@ class MainController:
|
||||
"""
|
||||
self.__view.show_frame(frame)
|
||||
|
||||
def get_config(self, name: str) -> str|int:
|
||||
def get_config(self, name: str):
|
||||
"""
|
||||
[function for controller]
|
||||
=> Allows controllers to access the application's configuration.
|
||||
|
||||
* :name: -> The name of the configuration parameter for which we want to access the configured value.
|
||||
* THROWABLE -> If the key is wrong, throw a ValueError.
|
||||
"""
|
||||
if self.__config.get(name):
|
||||
return self.__config.get(name)
|
||||
|
||||
@@ -6,19 +6,23 @@ from urllib.error import HTTPError
|
||||
def fetch_version(url: str) -> str:
|
||||
"""
|
||||
Retrieve the latest webpicdownloader version available.
|
||||
This method, only accept 200 http response.
|
||||
|
||||
* :url: -> Url of the "VERSION" file on the repository.
|
||||
* RETURN -> the latests 'VERSION' file content.
|
||||
* THROWABLE -> can raise HTTP or URL error see urllib doc.
|
||||
"""
|
||||
headers = {'User-Agent': "Mozilla/5.0 (Windows NT 11.0; Win64; x64) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/604.1"}
|
||||
request = http.Request(url=url, headers=headers, method='GET')
|
||||
request = http.Request(
|
||||
url=url,
|
||||
headers={'User-Agent': "Mozilla/5.0 (Windows NT 11.0; Win64; x64) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/604.1"},
|
||||
method='GET'
|
||||
)
|
||||
response = http.urlopen(request)
|
||||
if response.getcode() != 200:
|
||||
raise HTTPError("Bad response returned by server")
|
||||
return response.read().decode('utf-8')
|
||||
|
||||
def is_new_version_available(version_current: str, version_url: str, version_pattern: Pattern) -> bool:
|
||||
def check_for_update(version_current: str, version_url: str, version_pattern: Pattern) -> bool:
|
||||
"""
|
||||
Verify if a new version is available.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user