Updater now accepts updates from the gitlab repo URL
This commit is contained in:
parent
b9bb17dd69
commit
729b410d63
@ -16,18 +16,15 @@ except ImportError:
|
|||||||
|
|
||||||
from platform_utils import paths
|
from platform_utils import paths
|
||||||
|
|
||||||
def perform_update(endpoint, current_version, app_name='', password=None, update_available_callback=None, progress_callback=None, update_complete_callback=None):
|
def perform_update(endpoint, current_version, update_type="stable", app_name='', password=None, update_available_callback=None, progress_callback=None, update_complete_callback=None):
|
||||||
requests_session = create_requests_session(app_name=app_name, version=current_version)
|
requests_session = create_requests_session(app_name=app_name, version=current_version)
|
||||||
available_update = find_update(endpoint, requests_session=requests_session)
|
available_update = find_update(endpoint, requests_session=requests_session)
|
||||||
if not available_update:
|
if not available_update:
|
||||||
logger.debug("No update available")
|
logger.debug("No update available")
|
||||||
return False
|
return False
|
||||||
available_version = float(available_update['current_version'])
|
available_version, available_description, update_url = find_version_data(update_type, current_version, available_update)
|
||||||
if not float(available_version) > float(current_version) or platform.system()+platform.architecture()[0][:2] not in available_update['downloads']:
|
if available_version == False:
|
||||||
logger.debug("No update for this architecture")
|
return
|
||||||
return False
|
|
||||||
available_description = available_update.get('description', None)
|
|
||||||
update_url = available_update ['downloads'][platform.system()+platform.architecture()[0][:2]]
|
|
||||||
logger.info("A new update is available. Version %s" % available_version)
|
logger.info("A new update is available. Version %s" % available_version)
|
||||||
if callable(update_available_callback) and not update_available_callback(version=available_version, description=available_description): #update_available_callback should return a falsy value to stop the process
|
if callable(update_available_callback) and not update_available_callback(version=available_version, description=available_description): #update_available_callback should return a falsy value to stop the process
|
||||||
logger.info("User canceled update.")
|
logger.info("User canceled update.")
|
||||||
@ -57,6 +54,29 @@ def find_update(endpoint, requests_session):
|
|||||||
content = response.json()
|
content = response.json()
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
def find_version_data(update_type, current_version, available_update):
|
||||||
|
if update_type == "stable":
|
||||||
|
available_version = float(available_update['current_version'])
|
||||||
|
if not float(available_version) > float(current_version) or platform.system()+platform.architecture()[0][:2] not in available_update['downloads']:
|
||||||
|
logger.debug("No update for this architecture")
|
||||||
|
return (False, False, False)
|
||||||
|
available_description = available_update.get('description', None)
|
||||||
|
update_url = available_update ['downloads'][platform.system()+platform.architecture()[0][:2]]
|
||||||
|
return (available_version, available_description, update_url)
|
||||||
|
else: # Unstable versions, based in commits instead of version numbers.
|
||||||
|
# A condition for this to work is a successful ran of a pipeline.
|
||||||
|
if "status" not in available_update:
|
||||||
|
return (False, False, False)
|
||||||
|
if "status" in available_update and available_update["status"] != "success":
|
||||||
|
return (False, False, False)
|
||||||
|
available_version = available_update["short_id"]
|
||||||
|
if available_version == current_version:
|
||||||
|
return (False, False, False)
|
||||||
|
available_description = available_update["message"]
|
||||||
|
# ToDo: simplify this so it can be reused in other projects.
|
||||||
|
update_url = "https://code.manuelcortez.net/manuelcortez/socializer/-/jobs/artifacts/master/raw/socializer.zip?job=production"
|
||||||
|
return (available_version, available_description, update_url)
|
||||||
|
|
||||||
def download_update(update_url, update_destination, requests_session, progress_callback=None, chunk_size=io.DEFAULT_BUFFER_SIZE):
|
def download_update(update_url, update_destination, requests_session, progress_callback=None, chunk_size=io.DEFAULT_BUFFER_SIZE):
|
||||||
total_downloaded = total_size = 0
|
total_downloaded = total_size = 0
|
||||||
with io.open(update_destination, 'w+b') as outfile:
|
with io.open(update_destination, 'w+b') as outfile:
|
||||||
|
@ -8,9 +8,15 @@ from requests.exceptions import ConnectionError
|
|||||||
from wxUpdater import *
|
from wxUpdater import *
|
||||||
logger = logging.getLogger("updater")
|
logger = logging.getLogger("updater")
|
||||||
|
|
||||||
def do_update(endpoint=application.update_url):
|
def do_update(update_type="stable"):
|
||||||
|
if update_type == "stable":
|
||||||
|
endpoint = application.update_stable_url
|
||||||
|
version = application.version
|
||||||
|
else:
|
||||||
|
endpoint = application.update_next_url
|
||||||
|
version = application.update_next_version
|
||||||
try:
|
try:
|
||||||
return update.perform_update(endpoint=endpoint, current_version=application.version, app_name=application.name, update_available_callback=available_update_dialog, progress_callback=progress_callback, update_complete_callback=update_finished)
|
return update.perform_update(endpoint=endpoint, current_version=version, app_name=application.name, update_type=update_type, update_available_callback=available_update_dialog, progress_callback=progress_callback, update_complete_callback=update_finished)
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
logger.exception("Update failed.")
|
logger.exception("Update failed.")
|
||||||
output.speak("An exception occurred while attempting to update " + application.name + ". If this message persists, contact the " + application.name + " developers. More information about the exception has been written to the error log.",True)
|
output.speak("An exception occurred while attempting to update " + application.name + ". If this message persists, contact the " + application.name + " developers. More information about the exception has been written to the error log.",True)
|
Loading…
Reference in New Issue
Block a user