Fix checksum_ok if no internet connection
This commit is contained in:
@@ -22,7 +22,7 @@ class Messages(object):
|
||||
NO_DB = "No database"
|
||||
DOWNLOAD_NOW_QUESTION = "Do you want to download it now?"
|
||||
DOWNLOAD_ANYWAY_QUESTION = "Do you want to download it anyway?"
|
||||
NO_CONNECTION = "No internet connection"
|
||||
NO_CONNECTION = "No connection"
|
||||
NO_CONNECTION_MSG = "Unable to establish an internet connection."
|
||||
BAD_DOWNLOAD = "Something went wrong"
|
||||
BAD_DOWNLOAD_MSG = "Something went wrong with the downaload.\nCheck your internet connection and try again."
|
||||
|
||||
@@ -2,7 +2,7 @@ from PyQt5 import uic
|
||||
from PyQt5.QtCore import Qt, pyqtSlot
|
||||
from PyQt5.QtWidgets import QWidget
|
||||
from threads import DownloadThread, ThreadStatus
|
||||
from utilities import throwable_message
|
||||
from utilities import pop_up
|
||||
from constants import Messages
|
||||
|
||||
Ui_Download_window, _ = uic.loadUiType("download_db_window.ui")
|
||||
@@ -20,13 +20,13 @@ class DownloadWindow(QWidget, Ui_Download_window):
|
||||
)
|
||||
self.everything_ok = True
|
||||
|
||||
self.no_internet_msg = throwable_message(self, title = Messages.NO_CONNECTION,
|
||||
text = Messages.NO_CONNECTION_MSG,
|
||||
connection = self.close)
|
||||
self.no_internet_msg = pop_up(self, title = Messages.NO_CONNECTION,
|
||||
text = Messages.NO_CONNECTION_MSG,
|
||||
connection = self.close)
|
||||
|
||||
self.bad_db_download_msg = throwable_message(self, title = Messages.BAD_DOWNLOAD,
|
||||
text = Messages.BAD_DOWNLOAD_MSG,
|
||||
connection = self.close)
|
||||
self.bad_db_download_msg = pop_up(self, title = Messages.BAD_DOWNLOAD,
|
||||
text = Messages.BAD_DOWNLOAD_MSG,
|
||||
connection = self.close)
|
||||
|
||||
self.download_thread = DownloadThread()
|
||||
self.download_thread.finished.connect(self.wait_close)
|
||||
|
||||
66
main.py
66
main.py
@@ -32,7 +32,7 @@ from themes import Theme
|
||||
|
||||
from utilities import (checksum_ok,
|
||||
uncheck_and_emit,
|
||||
throwable_message,
|
||||
pop_up,
|
||||
connect_to,
|
||||
filters_ok,
|
||||
is_undef_freq,
|
||||
@@ -497,16 +497,22 @@ class MyApp(QMainWindow, Ui_MainWindow):
|
||||
except:
|
||||
self.download_db()
|
||||
else:
|
||||
if not checksum_ok(db, constants.ChecksumWhat.DB):
|
||||
self.download_db()
|
||||
try:
|
||||
is_checksum_ok = checksum_ok(db, constants.ChecksumWhat.DB)
|
||||
except:
|
||||
pop_up(self, title = constants.Messages.NO_CONNECTION,
|
||||
text = constants.Messages.NO_CONNECTION_MSG).show()
|
||||
else:
|
||||
answer = throwable_message(self, title = constants.Messages.DB_UP_TO_DATE,
|
||||
text = constants.Messages.DB_UP_TO_DATE_MSG,
|
||||
informative_text = constants.Messages.DOWNLOAD_ANYWAY_QUESTION,
|
||||
is_question = True,
|
||||
default_btn = QMessageBox.No).exec()
|
||||
if answer == QMessageBox.Yes:
|
||||
if not is_checksum_ok:
|
||||
self.download_db()
|
||||
else:
|
||||
answer = pop_up(self, title = constants.Messages.DB_UP_TO_DATE,
|
||||
text = constants.Messages.DB_UP_TO_DATE_MSG,
|
||||
informative_text = constants.Messages.DOWNLOAD_ANYWAY_QUESTION,
|
||||
is_question = True,
|
||||
default_btn = QMessageBox.No).exec()
|
||||
if answer == QMessageBox.Yes:
|
||||
self.download_db()
|
||||
|
||||
@pyqtSlot()
|
||||
def check_db_ver(self):
|
||||
@@ -517,22 +523,28 @@ class MyApp(QMainWindow, Ui_MainWindow):
|
||||
with open(db_path, "rb") as file_db:
|
||||
db = file_db.read()
|
||||
except:
|
||||
answer = throwable_message(self, title = constants.Messages.NO_DB,
|
||||
text = constants.Messages.NO_DB_AVAIL,
|
||||
informative_text = constants.Messages.DOWNLOAD_NOW_QUESTION,
|
||||
is_question = True).exec()
|
||||
answer = pop_up(self, title = constants.Messages.NO_DB,
|
||||
text = constants.Messages.NO_DB_AVAIL,
|
||||
informative_text = constants.Messages.DOWNLOAD_NOW_QUESTION,
|
||||
is_question = True).exec()
|
||||
else:
|
||||
if checksum_ok(db, constants.ChecksumWhat.DB):
|
||||
throwable_message(self, title = constants.Messages.DB_UP_TO_DATE,
|
||||
text = constants.Messages.DB_UP_TO_DATE_MSG).show()
|
||||
|
||||
try:
|
||||
is_checksum_ok = checksum_ok(db, constants.ChecksumWhat.DB)
|
||||
except:
|
||||
pop_up(self, title = constants.Messages.NO_CONNECTION,
|
||||
text = constants.Messages.NO_CONNECTION_MSG).show()
|
||||
else:
|
||||
answer = throwable_message(self, title = constants.Messages.DB_NEW_VER,
|
||||
text = constants.Messages.DB_NEW_VER_MSG,
|
||||
informative_text = constants.Messages.DOWNLOAD_NOW_QUESTION,
|
||||
is_question = True).exec()
|
||||
if answer == QMessageBox.Yes:
|
||||
self.download_db()
|
||||
if is_checksum_ok:
|
||||
pop_up(self, title = constants.Messages.DB_UP_TO_DATE,
|
||||
text = constants.Messages.DB_UP_TO_DATE_MSG).show()
|
||||
|
||||
else:
|
||||
answer = pop_up(self, title = constants.Messages.DB_NEW_VER,
|
||||
text = constants.Messages.DB_NEW_VER_MSG,
|
||||
informative_text = constants.Messages.DOWNLOAD_NOW_QUESTION,
|
||||
is_question = True).exec()
|
||||
if answer == QMessageBox.Yes:
|
||||
self.download_db()
|
||||
|
||||
@pyqtSlot()
|
||||
def show_downloaded_signals(self):
|
||||
@@ -552,10 +564,10 @@ class MyApp(QMainWindow, Ui_MainWindow):
|
||||
names = names,)
|
||||
except FileNotFoundError:
|
||||
self.search_bar.setDisabled(True)
|
||||
answer = throwable_message(self, title = constants.Messages.NO_DB,
|
||||
text = constants.Messages.NO_DB_AVAIL,
|
||||
informative_text = constants.Messages.DOWNLOAD_NOW_QUESTION,
|
||||
is_question = True).exec()
|
||||
answer = pop_up(self, title = constants.Messages.NO_DB,
|
||||
text = constants.Messages.NO_DB_AVAIL,
|
||||
informative_text = constants.Messages.DOWNLOAD_NOW_QUESTION,
|
||||
is_question = True).exec()
|
||||
if answer == QMessageBox.Yes:
|
||||
self.download_db()
|
||||
else:
|
||||
|
||||
11
themes.py
11
themes.py
@@ -4,8 +4,7 @@ from PyQt5.QtWidgets import QAction
|
||||
from PyQt5.QtCore import pyqtSlot
|
||||
from PyQt5.QtGui import QPixmap
|
||||
import constants
|
||||
from utilities import (throwable_message,
|
||||
is_valid_html_color,)
|
||||
from utilities import pop_up, is_valid_html_color
|
||||
|
||||
class ThemeConstants(object):
|
||||
FOLDER = "themes"
|
||||
@@ -81,13 +80,13 @@ class Theme(object):
|
||||
try:
|
||||
with open(os.path.join(
|
||||
self.__theme_path,
|
||||
os.path.basename(self.__theme_path).split('-')[1] + ThemeConstants.EXTENSION)) as stylesheet:
|
||||
os.path.basename(self.__theme_path).split('-')[1] + ThemeConstants.EXTENSION), "r") as stylesheet:
|
||||
style = stylesheet.read()
|
||||
self.__parent.setStyleSheet(style)
|
||||
self.__parent.download_window.setStyleSheet(style)
|
||||
except FileNotFoundError:
|
||||
throwable_message(self.__parent, title = ThemeConstants.THEME_NOT_FOUND,
|
||||
text = ThemeConstants.MISSING_THEME).show()
|
||||
pop_up(self.__parent, title = ThemeConstants.THEME_NOT_FOUND,
|
||||
text = ThemeConstants.MISSING_THEME).show()
|
||||
else:
|
||||
icons_path = os.path.join(self.__theme_path, ThemeConstants.ICONS_FOLDER)
|
||||
default_icons_path = os.path.join(ThemeConstants.FOLDER,
|
||||
@@ -160,7 +159,7 @@ class Theme(object):
|
||||
def initialize(self):
|
||||
current_theme_file = os.path.join(ThemeConstants.FOLDER, ThemeConstants.CURRENT)
|
||||
if os.path.exists(current_theme_file):
|
||||
with open(current_theme_file) as current_theme_path:
|
||||
with open(current_theme_file, "r") as current_theme_path:
|
||||
theme_path = current_theme_path.read()
|
||||
if theme_path != ThemeConstants.DEFAULT:
|
||||
self.__apply(theme_path)
|
||||
10
threads.py
10
threads.py
@@ -42,9 +42,15 @@ class DownloadThread(QThread):
|
||||
self.reason = db.reason
|
||||
self.__status = ThreadStatus.BAD_DOWNLOAD_ERR
|
||||
return
|
||||
if not checksum_ok(db.data, constants.ChecksumWhat.FOLDER):
|
||||
self.__status = ThreadStatus.BAD_DOWNLOAD_ERR
|
||||
try:
|
||||
is_checksum_ok = checksum_ok(db.data, constants.ChecksumWhat.FOLDER)
|
||||
except:
|
||||
self.__status = ThreadStatus.NO_CONNECTION_ERR
|
||||
return
|
||||
else:
|
||||
if not is_checksum_ok:
|
||||
self.__status = ThreadStatus.BAD_DOWNLOAD_ERR
|
||||
return
|
||||
if os.path.exists(constants.DATA_FOLDER):
|
||||
rmtree(constants.DATA_FOLDER)
|
||||
try:
|
||||
|
||||
22
utilities.py
22
utilities.py
@@ -13,11 +13,11 @@ def uncheck_and_emit(button):
|
||||
button.setChecked(False)
|
||||
button.clicked.emit()
|
||||
|
||||
def throwable_message(cls, title, text,
|
||||
informative_text = None,
|
||||
connection = None,
|
||||
is_question = False,
|
||||
default_btn = QMessageBox.Yes):
|
||||
def pop_up(cls, title, text,
|
||||
informative_text = None,
|
||||
connection = None,
|
||||
is_question = False,
|
||||
default_btn = QMessageBox.Yes):
|
||||
msg = QMessageBox(cls)
|
||||
msg.setWindowTitle(title)
|
||||
msg.setText(text)
|
||||
@@ -43,8 +43,8 @@ def checksum_ok(data, what):
|
||||
try:
|
||||
reference = read_csv(constants.Database.LINK_REF,
|
||||
delimiter = constants.Database.DELIMITER).iat[-1, n]
|
||||
except HTTPError:
|
||||
return False
|
||||
except:
|
||||
raise
|
||||
return code.hexdigest() == reference
|
||||
|
||||
def is_valid_html_color(color):
|
||||
@@ -52,11 +52,11 @@ def is_valid_html_color(color):
|
||||
|
||||
def connect_to(events_to_connect, fun_to_connect, fun_args):
|
||||
if fun_args:
|
||||
for signal in events_to_connect:
|
||||
signal.connect(partial(fun_to_connect, *fun_args))
|
||||
for event in events_to_connect:
|
||||
event.connect(partial(fun_to_connect, *fun_args))
|
||||
else:
|
||||
for signal in events_to_connect:
|
||||
signal.connect(fun_to_connect)
|
||||
for event in events_to_connect:
|
||||
event.connect(fun_to_connect)
|
||||
|
||||
def filters_ok(spinbox, filter_unit, confidence, sign = 1):
|
||||
band_filter = spinbox.value() * constants.CONVERSION_FACTORS[filter_unit.currentText()]
|
||||
|
||||
Reference in New Issue
Block a user