Final ieration of the new downloader and update_manager, implemented automatic updates only for windows

This commit is contained in:
Marco Dalla Tiezza
2024-06-13 15:46:25 +02:00
parent 146a5d1605
commit 77c43813a0
5 changed files with 285 additions and 231 deletions

View File

@@ -5,8 +5,8 @@ from packaging.version import Version
from artemis.utils.constants import Constants, Messages
from artemis.utils.sql_utils import ArtemisDatabase
from artemis.utils.sys_utils import is_windows, is_linux, is_macos, delete_file, delete_dir, match_hash, unpack_tar
from artemis.utils.path_utils import DATA_DIR
from artemis.utils.sys_utils import is_windows, is_linux, is_macos, delete_file, delete_dir, match_hash, unpack_tar, open_file
from artemis.utils.path_utils import DATA_DIR, APP_DIR
class UpdateManager:
@@ -26,19 +26,22 @@ class UpdateManager:
self.remote_db_size = None
self.remote_db_file_name = None
self.remote_art_version = None
self.remote_artemis_version = None
self.remote_artemis_url = None
self.remote_artemis_file_name = None
self.check_updates()
def check_updates(self, show_popup=False):
""" Checks if a software or DB update is available.
Prioritize Artemis update over DB one.
Prioritize Artemis updates over the DB one.
Args:
show_popup (bool, optional):
Suppress the "already up-to-date" message on startup.
Defaults to False.
If False, suppress the "already up-to-date" message on startup.
Defaults to False. True is usefull when the user manual check for
updates.
"""
latest_json = self._fetch_remote_json(Constants.LATEST_VERSION_URL, show_popup)
if latest_json:
@@ -52,13 +55,18 @@ class UpdateManager:
self.remote_db_file_name = self.remote_db_url.split('/')[-1]
if is_windows():
self.remote_art_version = latest_json['windows']['version']
self.remote_artemis_version = latest_json['windows']['version']
self.remote_artemis_url = latest_json['windows']['url']
elif is_linux():
self.remote_art_version = latest_json['linux']['version']
self.remote_artemis_version = latest_json['linux']['version']
self.remote_artemis_url = latest_json['linux']['url']
elif is_macos():
self.remote_art_version = latest_json['mac']['version']
self.remote_artemis_version = latest_json['mac']['version']
self.remote_artemis_url = latest_json['mac']['url']
self.remote_artemis_file_name = self.remote_artemis_url.split('/')[-1]
if Version(self.remote_art_version) > Version(Constants.APPLICATION_VERSION):
if Version(self.remote_artemis_version) > Version(Constants.APPLICATION_VERSION):
self.art_update = True
else:
self.art_update = False
@@ -77,6 +85,10 @@ class UpdateManager:
def _fetch_remote_json(self, url, show_popup=False):
""" Fetches the remote json from a url
Args:
show_popup (bool, optional): If false, suppress any error message
Defaults to False (to avoid error if the program is used offline)
"""
try:
response = requests.get(url)
@@ -100,9 +112,25 @@ class UpdateManager:
local_db.load()
return local_db
return None
def download_db(self):
""" Open the downloader and download the sigID database in the
DATA_DIR folder. After a succesfull download the callback function
from the downloader is post_download_db
"""
self._parent.downloader.finished.connect(self.post_download_db)
self._parent.downloader.on_start(
self.remote_db_url,
DATA_DIR
)
def post_download_db(self):
""" After a succesfull DB download, this function check the hash
for possible corrupted data, delete old sigID DB and extract
the new one
"""
latest_db_tar_path = DATA_DIR / self.remote_db_file_name
if match_hash(latest_db_tar_path, self.remote_db_hash):
delete_dir(DATA_DIR / 'SigID')
@@ -114,8 +142,29 @@ class UpdateManager:
delete_file(latest_db_tar_path)
def download_artemis(self):
""" Open the downloader and download Artemis in the
APP_DIR folder. After a succesfull download the callback function
from the downloader is post_download_artemis
"""
self._parent.downloader.finished.connect(self.post_download_artemis)
self._parent.downloader.on_start(
self.remote_artemis_url,
APP_DIR
)
def post_download_artemis(self):
""" After a succesfull Artemis download, this open the installer
and close the application
"""
if is_windows():
open_file(APP_DIR / self.remote_artemis_file_name)
self._parent.close_ui.emit()
def _show_popup_db_update(self):
""" Prompts the user to download the updated version of the database.
""" Prompts the user to download the updated version of the database
"""
self._parent.dialog_download_db(
Messages.DIALOG_TYPE_WARN,
@@ -133,20 +182,20 @@ class UpdateManager:
self._parent.dialog_update_artemis(
Messages.DIALOG_TYPE_QUEST,
Messages.ART_NEW_VER,
Messages.ART_NEW_VER_AUTO_MSG.format(self.remote_art_version),
Messages.ART_NEW_VER_AUTO_MSG.format(self.remote_artemis_version),
True
)
else:
self._parent.dialog_update_artemis(
Messages.DIALOG_TYPE_QUEST,
Messages.ART_NEW_VER,
Messages.ART_NEW_VER_MANUAL_MSG.format(self.remote_art_version),
Messages.ART_NEW_VER_MANUAL_MSG.format(self.remote_artemis_version),
False
)
def _show_popup_up_to_date(self):
""" Notifies the user that the database is up to date.
""" Notifies the user that the database is up to date
"""
self._parent.dialog_popup(
Messages.DIALOG_TYPE_INFO,
@@ -156,7 +205,7 @@ class UpdateManager:
def _show_popup_initial_db_download(self):
""" Prompts the user to download the database for the first time.
""" Prompts the user to download the database for the first time
"""
self._parent.dialog_download_db(
Messages.DIALOG_TYPE_QUEST,