diff --git a/src/settings.py b/src/settings.py index 0bd2ec1..ac3aa2a 100644 --- a/src/settings.py +++ b/src/settings.py @@ -38,7 +38,4 @@ class Settings: """Return the corresponding setting. Return None if there is no such setting yet.""" - try: - return self._dct[attr] - except Exception: - return None + return self._dct.get(attr, None) diff --git a/src/utilities.py b/src/utilities.py index 6565f11..dd08758 100644 --- a/src/utilities.py +++ b/src/utilities.py @@ -30,12 +30,12 @@ class UniqueMessageBox(QMessageBox): """Overrides QMessageBox.exec. Call the parent method if there are no other instances executing exec; also set the current font. Otherwise return None,""" - if UniqueMessageBox._open_message: + if self.__class__._open_message: return None self.setFont(self._font) - UniqueMessageBox._open_message = True + self.__class__._open_message = True answer = super().exec() - UniqueMessageBox._open_message = False + self.__class__._open_message = False return answer def show(self): diff --git a/src/versioncontroller.py b/src/versioncontroller.py index cfe9a2c..5712083 100644 --- a/src/versioncontroller.py +++ b/src/versioncontroller.py @@ -63,14 +63,9 @@ def _download_versions_file(): } } """ - try: - version_dict = json.load( - BytesIO(download_file(Constants.VERSION_LINK)) - )[get_os()] - except Exception: - return None - else: - return version_dict + return json.load( + BytesIO(download_file(Constants.VERSION_LINK)) + ).get(get_os(), None) class VersionController: @@ -80,7 +75,6 @@ class VersionController: def __init__(self, dct=None): """Initialize the dictionary""" - super().__init__() self._dct = dct def __getattr__(self, attr): @@ -89,16 +83,14 @@ class VersionController: if self._dct is None: if not self.update(): return None - try: - dct_element = self._dct[attr] - except Exception("ERROR: Invalid attribute!"): + dct_element = self._dct.get(attr, None) + if dct_element is None: return None + if isinstance(dct_element, dict): + setattr(self, attr, type(self)(dct_element)) else: - if isinstance(dct_element, dict): - setattr(self, attr, type(self)(dct_element)) - else: - setattr(self, attr, dct_element) - return getattr(self, attr) + setattr(self, attr, dct_element) + return getattr(self, attr) def update(self): """Reset the dictionary to the correspondig json file containing diff --git a/src/web_utilities.py b/src/web_utilities.py index 2efa362..70bd702 100644 --- a/src/web_utilities.py +++ b/src/web_utilities.py @@ -37,10 +37,9 @@ def _download_multiline_file_as_list(url=Database.LINK_REF): The downloaded file is a csv file with columns (last version == last line): data.zip_SHA256 | db.csv_SHA256 | Version | Creation_date""" try: - f = download_file(url, encoding="UTF-8").splitlines()[-1].split(Database.DELIMITER) + return download_file(url, encoding="UTF-8").splitlines()[-1].split(Database.DELIMITER) except Exception: return None - return f def get_folder_hash_code():