Some minor style improvements

This commit is contained in:
Alessandro
2020-02-29 21:43:40 +01:00
parent bcd24cc035
commit ab32fbbf98
4 changed files with 14 additions and 26 deletions

View File

@@ -38,7 +38,4 @@ class Settings:
"""Return the corresponding setting. """Return the corresponding setting.
Return None if there is no such setting yet.""" Return None if there is no such setting yet."""
try: return self._dct.get(attr, None)
return self._dct[attr]
except Exception:
return None

View File

@@ -30,12 +30,12 @@ class UniqueMessageBox(QMessageBox):
"""Overrides QMessageBox.exec. Call the parent method if there are no """Overrides QMessageBox.exec. Call the parent method if there are no
other instances executing exec; also set the current font. other instances executing exec; also set the current font.
Otherwise return None,""" Otherwise return None,"""
if UniqueMessageBox._open_message: if self.__class__._open_message:
return None return None
self.setFont(self._font) self.setFont(self._font)
UniqueMessageBox._open_message = True self.__class__._open_message = True
answer = super().exec() answer = super().exec()
UniqueMessageBox._open_message = False self.__class__._open_message = False
return answer return answer
def show(self): def show(self):

View File

@@ -63,14 +63,9 @@ def _download_versions_file():
} }
} }
""" """
try: return json.load(
version_dict = json.load( BytesIO(download_file(Constants.VERSION_LINK))
BytesIO(download_file(Constants.VERSION_LINK)) ).get(get_os(), None)
)[get_os()]
except Exception:
return None
else:
return version_dict
class VersionController: class VersionController:
@@ -80,7 +75,6 @@ class VersionController:
def __init__(self, dct=None): def __init__(self, dct=None):
"""Initialize the dictionary""" """Initialize the dictionary"""
super().__init__()
self._dct = dct self._dct = dct
def __getattr__(self, attr): def __getattr__(self, attr):
@@ -89,16 +83,14 @@ class VersionController:
if self._dct is None: if self._dct is None:
if not self.update(): if not self.update():
return None return None
try: dct_element = self._dct.get(attr, None)
dct_element = self._dct[attr] if dct_element is None:
except Exception("ERROR: Invalid attribute!"):
return None return None
if isinstance(dct_element, dict):
setattr(self, attr, type(self)(dct_element))
else: else:
if isinstance(dct_element, dict): setattr(self, attr, dct_element)
setattr(self, attr, type(self)(dct_element)) return getattr(self, attr)
else:
setattr(self, attr, dct_element)
return getattr(self, attr)
def update(self): def update(self):
"""Reset the dictionary to the correspondig json file containing """Reset the dictionary to the correspondig json file containing

View File

@@ -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): The downloaded file is a csv file with columns (last version == last line):
data.zip_SHA256 | db.csv_SHA256 | Version | Creation_date""" data.zip_SHA256 | db.csv_SHA256 | Version | Creation_date"""
try: 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: except Exception:
return None return None
return f
def get_folder_hash_code(): def get_folder_hash_code():