From 2fbaa941091891dd31927317b10891ddd86bba78 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Tue, 4 Apr 2023 16:43:14 +0000 Subject: [PATCH] catch strange behavior of strptime in get_zsync --- src/gui_qt/lib/utils.py | 46 ++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/gui_qt/lib/utils.py b/src/gui_qt/lib/utils.py index 768b848..436e656 100644 --- a/src/gui_qt/lib/utils.py +++ b/src/gui_qt/lib/utils.py @@ -1,6 +1,5 @@ from __future__ import annotations -import sys from functools import lru_cache from os import getenv, stat from os.path import exists @@ -116,28 +115,28 @@ class UpdateDialog(QtWidgets.QDialog): # Download zsync file of latest Appimage, look for SHA-1 hash and compare with hash of AppImage is_updateble, m_time_file, m_time_zsync = self.updater.get_update_information(filename) - if m_time_zsync is None: - label_text = '

Retrieval of version information failed.

' \ - '

Please try later (or complain to people that it does not work).

' + label_text = '' + + if is_updateble is None: + label_text += '

Could not determine if this version is newer, please update manually (if necessary).

' dialog_bttns = QtWidgets.QDialogButtonBox.Close + elif is_updateble: + label_text += '

Newer version available. Press Ok to download new version, Cancel to ignore.

' + dialog_bttns = QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel else: - label_text = f'

Date of most recent AppImage: {m_time_zsync.strftime("%d %B %Y %H:%M")}

' + label_text += '

Version may be already up-to-date.

' + dialog_bttns = QtWidgets.QDialogButtonBox.Close - if m_time_file is None: - label_text += 'No AppImage file found, press Ok to download latest version.' - dialog_bttns = QtWidgets.QDialogButtonBox.Ok|QtWidgets.QDialogButtonBox.Close - else: - label_text += f'

Date of used AppImage: {m_time_file.strftime("%d %B %Y %H:%M")}

' + if m_time_zsync is None: + label_text += '

Creation date of remote version is unknown.

' + else: + label_text += f'

Date of most recent AppImage: {m_time_zsync.strftime("%d %B %Y %H:%M")}

' - if is_updateble is None: - self.status.setText('Could not determine if this version is newer, please update manually (if necessary).') - dialog_bttns = QtWidgets.QDialogButtonBox.Close - elif is_updateble: - self.status.setText(f'

Newer version available. Press Ok to download new version, Cancel to ignore.') - dialog_bttns = QtWidgets.QDialogButtonBox.Ok|QtWidgets.QDialogButtonBox.Cancel - else: - self.status.setText(f'Version may be already up-to-date.') - dialog_bttns = QtWidgets.QDialogButtonBox.Close + if m_time_file is None: + label_text += 'No AppImage file found, press Ok to download latest version.' + dialog_bttns = QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Close + else: + label_text += f'

Date of used AppImage: {m_time_file.strftime("%d %B %Y %H:%M")}

' self.label.setText(label_text) self.dialog_button.setStandardButtons(dialog_bttns) @@ -241,8 +240,13 @@ class Updater: for line in zsync_file.split(b'\n'): try: kw, val = line.split(b': ') + time_string = str(val, encoding='utf-8') + time_format = '%a, %d %b %Y %H:%M:%S %z' if kw == b'MTime': - m_time_zsync = datetime.strptime(str(val, encoding='utf-8'), '%a, %d %b %Y %H:%M:%S %z').astimezone(None) + try: + m_time_zsync = datetime.strptime(time_string, time_format).astimezone(None) + except ValueError: + logger.warning(f'zsync time "{time_string}" does not match "{time_format}"') elif kw == b'SHA-1': checksum_zsync = str(val, encoding='utf-8') elif kw == b'Filename': @@ -277,7 +281,7 @@ class Updater: m_time_file, checksum_file = Updater.get_appimage_info(filename) logger.info(f'zsync information {m_time_zsync}, {checksum_zsync}, {appname}') - logger.info(f'file information {m_time_file}, {checksum_zsync}') + logger.info(f'file information {m_time_file}, {checksum_file}') if not ((checksum_file is not None) and (checksum_zsync is not None)): return None, m_time_file, m_time_zsync