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