Minor refactoring

This commit is contained in:
alessandro90
2019-04-26 10:37:06 +02:00
parent 00ae41f584
commit f45d36dc6d
5 changed files with 56 additions and 56 deletions

View File

@@ -606,7 +606,7 @@ class Artemis(QMainWindow, Ui_MainWindow):
query += self.gfd_line_edit.text() query += self.gfd_line_edit.text()
try: try:
webbrowser.open(Constants.GFD_SITE + query.lower()) webbrowser.open(Constants.GFD_SITE + query.lower())
except: except Exception:
pass pass
@pyqtSlot(QListWidgetItem) @pyqtSlot(QListWidgetItem)
@@ -713,12 +713,12 @@ class Artemis(QMainWindow, Ui_MainWindow):
try: try:
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 Exception:
self.download_db() self.download_db()
else: else:
try: try:
is_checksum_ok = checksum_ok(db, ChecksumWhat.DB) is_checksum_ok = checksum_ok(db, ChecksumWhat.DB)
except: except Exception:
pop_up(self, title = Messages.NO_CONNECTION, pop_up(self, title = Messages.NO_CONNECTION,
text = Messages.NO_CONNECTION_MSG).show() text = Messages.NO_CONNECTION_MSG).show()
else: else:
@@ -741,7 +741,7 @@ class Artemis(QMainWindow, Ui_MainWindow):
try: try:
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 Exception:
answer = pop_up(self, title = Messages.NO_DB, answer = pop_up(self, title = Messages.NO_DB,
text = Messages.NO_DB_AVAIL, text = Messages.NO_DB_AVAIL,
informative_text = Messages.DOWNLOAD_NOW_QUESTION, informative_text = Messages.DOWNLOAD_NOW_QUESTION,
@@ -751,7 +751,7 @@ class Artemis(QMainWindow, Ui_MainWindow):
else: else:
try: try:
is_checksum_ok = checksum_ok(db, ChecksumWhat.DB) is_checksum_ok = checksum_ok(db, ChecksumWhat.DB)
except: except Exception:
pop_up(self, title = Messages.NO_CONNECTION, pop_up(self, title = Messages.NO_CONNECTION,
text = Messages.NO_CONNECTION_MSG).show() text = Messages.NO_CONNECTION_MSG).show()
else: else:

View File

@@ -131,30 +131,30 @@ class Constants(object):
REMOVE = "Remove" REMOVE = "Remove"
UNKNOWN = "N/A" UNKNOWN = "N/A"
MODULATIONS = ("8VSB", MODULATIONS = ("8VSB",
"AFSK", "AFSK",
"AM", "AM",
"BFSK", "BFSK",
"C4FM", "C4FM",
"CDMA", "CDMA",
"COFDM", "COFDM",
"CW", "CW",
"FFSK", "FFSK",
"FM", "FM",
"FMCW", "FMCW",
"FMOP", "FMOP",
"FSK", "FSK",
"GFSK", "GFSK",
"GMSK", "GMSK",
"IFK", "IFK",
"MFSK", "MFSK",
"MSK", "MSK",
"OFDM", "OFDM",
"OOK", "OOK",
"PAM", "PAM",
"PPM", "PPM",
"PSK", "PSK",
"QAM", "QAM",
"TDMA",) "TDMA",)
LOCATIONS = (UNKNOWN, LOCATIONS = (UNKNOWN,
"Australia", "Australia",
"Canada", "Canada",

View File

@@ -38,13 +38,13 @@ class Theme(object):
ThemeConstants.DEFAULT, ThemeConstants.DEFAULT,
ThemeConstants.ICONS_FOLDER) ThemeConstants.ICONS_FOLDER)
self.__forecast_labels = SwitchableLabelsIterable(*list(chain(self.__parent.switchable_r_labels, self.__forecast_labels = SwitchableLabelsIterable(*list(chain(self.__parent.switchable_r_labels,
self.__parent.switchable_s_labels, self.__parent.switchable_s_labels,
self.__parent.switchable_g_now_labels, self.__parent.switchable_g_now_labels,
self.__parent.switchable_g_today_labels, self.__parent.switchable_g_today_labels,
self.__parent.k_storm_labels, self.__parent.k_storm_labels,
self.__parent.a_storm_labels, self.__parent.a_storm_labels,
[self.__parent.expected_noise_lbl]))) [self.__parent.expected_noise_lbl])))
self.__forecast_labels.set("switch_on_colors", ThemeConstants.DEFAULT_ON_COLORS) self.__forecast_labels.set("switch_on_colors", ThemeConstants.DEFAULT_ON_COLORS)
self.__forecast_labels.set("switch_off_colors", ThemeConstants.DEFAULT_OFF_COLORS) self.__forecast_labels.set("switch_off_colors", ThemeConstants.DEFAULT_OFF_COLORS)
@@ -209,7 +209,7 @@ class Theme(object):
with open(os.path.join(ThemeConstants.FOLDER, with open(os.path.join(ThemeConstants.FOLDER,
ThemeConstants.CURRENT), "w") as current_theme: ThemeConstants.CURRENT), "w") as current_theme:
current_theme.write(self.__theme_path) current_theme.write(self.__theme_path)
except: except Exception:
pass pass
def initialize(self): def initialize(self):

View File

@@ -1,6 +1,5 @@
from enum import Enum, auto from enum import Enum, auto
from io import BytesIO from io import BytesIO
from os import mkdir
import os.path import os.path
from shutil import rmtree from shutil import rmtree
import urllib3 import urllib3
@@ -42,7 +41,7 @@ class DownloadThread(QThread):
return return
try: try:
is_checksum_ok = checksum_ok(db.data, ChecksumWhat.FOLDER) is_checksum_ok = checksum_ok(db.data, ChecksumWhat.FOLDER)
except: except Exception:
self.__status = ThreadStatus.NO_CONNECTION_ERR self.__status = ThreadStatus.NO_CONNECTION_ERR
return return
else: else:
@@ -54,7 +53,7 @@ class DownloadThread(QThread):
try: try:
with ZipFile(BytesIO(db.data)) as zipped: with ZipFile(BytesIO(db.data)) as zipped:
zipped.extractall() zipped.extractall()
except: except Exception:
self.__status = ThreadStatus.UNKNOWN_ERR self.__status = ThreadStatus.UNKNOWN_ERR
else: else:
self.__status = ThreadStatus.OK self.__status = ThreadStatus.OK
@@ -75,22 +74,23 @@ class UpadteSpaceWeatherThread(QThread):
self.wait() self.wait()
def run(self): def run(self):
get_request_data = lambda link: urllib3.PoolManager().request('GET', link).data
try: try:
self.__space_weather_data.xray = str(urllib3.PoolManager().request('GET', Constants.FORECAST_XRAY).data, 'utf-8') self.__space_weather_data.xray = str(get_request_data(Constants.FORECAST_XRAY), 'utf-8')
self.__space_weather_data.prot_el = str(urllib3.PoolManager().request('GET', Constants.FORECAST_PROT).data, 'utf-8') self.__space_weather_data.prot_el = str(get_request_data(Constants.FORECAST_PROT), 'utf-8')
self.__space_weather_data.ak_index = str(urllib3.PoolManager().request('GET', Constants.FORECAST_AK_IND).data, 'utf-8') self.__space_weather_data.ak_index = str(get_request_data(Constants.FORECAST_AK_IND), 'utf-8')
self.__space_weather_data.sgas = str(urllib3.PoolManager().request('GET', Constants.FORECAST_SGAS).data, 'utf-8') self.__space_weather_data.sgas = str(get_request_data(Constants.FORECAST_SGAS), 'utf-8')
self.__space_weather_data.geo_storm = str(urllib3.PoolManager().request('GET', Constants.FORECAST_G).data, 'utf-8') self.__space_weather_data.geo_storm = str(get_request_data(Constants.FORECAST_G), 'utf-8')
self.__space_weather_data.images[0].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_0).data) self.__space_weather_data.images[0].loadFromData(get_request_data(Constants.FORECAST_IMG_0))
self.__space_weather_data.images[1].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_1).data) self.__space_weather_data.images[1].loadFromData(get_request_data(Constants.FORECAST_IMG_1))
self.__space_weather_data.images[2].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_2).data) self.__space_weather_data.images[2].loadFromData(get_request_data(Constants.FORECAST_IMG_2))
self.__space_weather_data.images[3].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_3).data) self.__space_weather_data.images[3].loadFromData(get_request_data(Constants.FORECAST_IMG_3))
self.__space_weather_data.images[4].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_4).data) self.__space_weather_data.images[4].loadFromData(get_request_data(Constants.FORECAST_IMG_4))
self.__space_weather_data.images[5].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_5).data) self.__space_weather_data.images[5].loadFromData(get_request_data(Constants.FORECAST_IMG_5))
self.__space_weather_data.images[6].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_6).data) self.__space_weather_data.images[6].loadFromData(get_request_data(Constants.FORECAST_IMG_6))
self.__space_weather_data.images[7].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_7).data) self.__space_weather_data.images[7].loadFromData(get_request_data(Constants.FORECAST_IMG_7))
self.__space_weather_data.images[8].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_8).data) self.__space_weather_data.images[8].loadFromData(get_request_data(Constants.FORECAST_IMG_8))
except: except Exception:
self.__status = ThreadStatus.UNKNOWN_ERR self.__status = ThreadStatus.UNKNOWN_ERR
else: else:
self.__status = ThreadStatus.OK self.__status = ThreadStatus.OK

View File

@@ -50,7 +50,7 @@ def checksum_ok(data, what):
try: try:
reference = read_csv(Database.LINK_REF, reference = read_csv(Database.LINK_REF,
delimiter = Database.DELIMITER).iat[-1, n] delimiter = Database.DELIMITER).iat[-1, n]
except: except Exception:
raise raise
return code.hexdigest() == reference return code.hexdigest() == reference