mirror of
https://github.com/ARUP-CAS/aiscr-qgis-amcr-viewer.git
synced 2026-10-10 04:47:36 +02:00
chore: úklid nálezů z lintů
Bez změny chování. Kontroly, které pouští plugins.qgis.org (flake8), plus ruff. flake8: odstraněny koncové bílé znaky, srovnány nadbytečné prázdné řádky a zalomeno 12 řádků přes 79 znaků. Hlášku o HTTP chybě v login_to_api() si nešlo jen zalomit – tělo odpovědi je nově v proměnné `telo`, výsledný text je stejný. ruff: odstraněny zbytečné prefixy u'' u překládaných řetězců (6×), .format() nahrazen f-stringem, str() uvnitř f-stringu převedeno na !s, `k in dict.keys()` na `k in dict`, prázdný komentář; nepoužitá rozbalená proměnná `existing_cfg` nahrazena `_`. Vědomě neřešeno: - resources.py (5 zbylých nálezů flake8) je generovaný výstup pyrcc, nese hlavičku "All changes made in this file will be lost", není nikde importovaný a v repu k němu chybí zdrojový .qrc. - ruff BLE001 (10×) hlásí `except Exception`. Ty jsou v pluginu záměrné: drží pád mimo QGIS a chybu ukážou v liště zpráv. Změna by byla zásah do chování, ne úklid. - ruff SIM103 (2×) navrhuje sloučit strážní podmínky do jednoho výrazu. Obě místa mají ke každé větvi vysvětlující komentář, sloučením by se staly hůř čitelnými. - ruff UP009 a I001 (coding hlavička a řazení importů) jsou celoprojektová konvence; jejich změna patří do samostatného rozhodnutí, ne sem. Ověřeno v QGIS 3.44.13 (Qt5) i QGIS 4.2.1 (Qt6): importy, vytvoření tasku i všechny tři filtrační dialogy fungují shodně. Bandit, detect-secrets i pyqgis4-checker hlásí nula nálezů.
This commit is contained in:
1 parent
d398d2cd1b
commit
048ffe4e2a
5 files changed
+39
-28
No files matched your search
@@ -31,6 +31,5 @@ def classFactory(iface): # pylint: disable=invalid-name
|
|||||||
:param iface: A QGIS interface instance.
|
:param iface: A QGIS interface instance.
|
||||||
:type iface: QgsInterface
|
:type iface: QgsInterface
|
||||||
"""
|
"""
|
||||||
#
|
|
||||||
from .amcr_viewer import AmcrViewer
|
from .amcr_viewer import AmcrViewer
|
||||||
return AmcrViewer(iface)
|
return AmcrViewer(iface)
|
||||||
@@ -98,7 +98,7 @@ def parse_codelist_file(filename, target_dict=None):
|
|||||||
def load_all_data():
|
def load_all_data():
|
||||||
"""Loads the codelist during plugin startup."""
|
"""Loads the codelist during plugin startup."""
|
||||||
ensure_codelists_dir()
|
ensure_codelists_dir()
|
||||||
categorized_data = {k: {} for k in slovnicek.keys()}
|
categorized_data = {k: {} for k in slovnicek}
|
||||||
parse_codelist_file('heslar.csv', categorized_data)
|
parse_codelist_file('heslar.csv', categorized_data)
|
||||||
return categorized_data
|
return categorized_data
|
||||||
|
|
||||||
@@ -124,7 +124,9 @@ def fetch_set(base_url, internal_name, api_set, task=None):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if "digiarchiv" not in base_url:
|
if "digiarchiv" not in base_url:
|
||||||
response = requests.get(base_url, params=params_amcr, timeout=30)
|
response = requests.get(
|
||||||
|
base_url, params=params_amcr, timeout=30
|
||||||
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
root = ET.fromstring(response.content) # nosec
|
root = ET.fromstring(response.content) # nosec
|
||||||
|
|
||||||
|
|||||||
@@ -608,7 +608,7 @@ class AmcrFilterDialog(QDialog):
|
|||||||
# This will show exactly what went wrong (e.g. PermissionError)
|
# This will show exactly what went wrong (e.g. PermissionError)
|
||||||
msg = (
|
msg = (
|
||||||
"Aktualizace selhala z důvodu chyby:\n"
|
"Aktualizace selhala z důvodu chyby:\n"
|
||||||
f"{str(task.exception)}"
|
f"{task.exception!s}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
msg = "Aktualizace byla zrušena uživatelem."
|
msg = "Aktualizace byla zrušena uživatelem."
|
||||||
@@ -669,7 +669,9 @@ class AmcrFilterDialog(QDialog):
|
|||||||
if self.selection_cache['jistota']:
|
if self.selection_cache['jistota']:
|
||||||
filters['f_jistota'] = self.selection_cache['jistota']
|
filters['f_jistota'] = self.selection_cache['jistota']
|
||||||
if self.selection_cache['lokalita_zachovalost']:
|
if self.selection_cache['lokalita_zachovalost']:
|
||||||
filters['f_lokalita_zachovalost'] = self.selection_cache['lokalita_zachovalost']
|
filters['f_lokalita_zachovalost'] = (
|
||||||
|
self.selection_cache['lokalita_zachovalost']
|
||||||
|
)
|
||||||
|
|
||||||
# Samostatné nálezy
|
# Samostatné nálezy
|
||||||
if self.selection_cache['nalez_kategorie']:
|
if self.selection_cache['nalez_kategorie']:
|
||||||
@@ -679,7 +681,9 @@ class AmcrFilterDialog(QDialog):
|
|||||||
if self.selection_cache['specifikace']:
|
if self.selection_cache['specifikace']:
|
||||||
filters['f_specifikace'] = self.selection_cache['specifikace']
|
filters['f_specifikace'] = self.selection_cache['specifikace']
|
||||||
if self.selection_cache['nalezove_okolnosti']:
|
if self.selection_cache['nalezove_okolnosti']:
|
||||||
filters['f_nalezove_okolnosti'] = self.selection_cache['nalezove_okolnosti']
|
filters['f_nalezove_okolnosti'] = (
|
||||||
|
self.selection_cache['nalezove_okolnosti']
|
||||||
|
)
|
||||||
if self.selection_cache['nalezce']:
|
if self.selection_cache['nalezce']:
|
||||||
filters['f_nalezce'] = self.selection_cache['nalezce']
|
filters['f_nalezce'] = self.selection_cache['nalezce']
|
||||||
|
|
||||||
@@ -718,7 +722,8 @@ class LoginDialog(QDialog):
|
|||||||
- storeAuthenticationConfig() and loadAuthenticationConfig() both have
|
- storeAuthenticationConfig() and loadAuthenticationConfig() both have
|
||||||
SIP_INOUT on their config parameter, so Python bindings return a tuple
|
SIP_INOUT on their config parameter, so Python bindings return a tuple
|
||||||
(bool, QgsAuthMethodConfig) rather than just bool. Always unpack both.
|
(bool, QgsAuthMethodConfig) rather than just bool. Always unpack both.
|
||||||
- loadAuthenticationConfig() with full=False loads only metadata (name, method,
|
- loadAuthenticationConfig() with full=False loads only metadata
|
||||||
|
(name, method,
|
||||||
id) but NOT the config() values like username/password. Use full=True to
|
id) but NOT the config() values like username/password. Use full=True to
|
||||||
access those.
|
access those.
|
||||||
"""
|
"""
|
||||||
@@ -949,7 +954,7 @@ class LoginDialog(QDialog):
|
|||||||
# We skip hasConfigId() as it may return False
|
# We skip hasConfigId() as it may return False
|
||||||
# despite the config existing
|
# despite the config existing
|
||||||
# (in-memory cache may not be populated yet in QGIS 4).
|
# (in-memory cache may not be populated yet in QGIS 4).
|
||||||
ok_load, existing_cfg = (
|
ok_load, _ = (
|
||||||
self._load_config(existing_id, full=False)
|
self._load_config(existing_id, full=False)
|
||||||
if existing_id
|
if existing_id
|
||||||
else (False, None)
|
else (False, None)
|
||||||
@@ -978,7 +983,9 @@ class LoginDialog(QDialog):
|
|||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
existing_id = settings.value(self.SETTINGS_KEY, "")
|
existing_id = settings.value(self.SETTINGS_KEY, "")
|
||||||
if existing_id:
|
if existing_id:
|
||||||
QgsApplication.authManager().removeAuthenticationConfig(existing_id)
|
QgsApplication.authManager().removeAuthenticationConfig(
|
||||||
|
existing_id
|
||||||
|
)
|
||||||
settings.remove(self.SETTINGS_KEY)
|
settings.remove(self.SETTINGS_KEY)
|
||||||
QMessageBox.information(
|
QMessageBox.information(
|
||||||
self,
|
self,
|
||||||
@@ -1013,4 +1020,5 @@ class LoginDialog(QDialog):
|
|||||||
if not ok:
|
if not ok:
|
||||||
return "", ""
|
return "", ""
|
||||||
|
|
||||||
return cfg.config("username", ""), cfg.config("password", "") # nosec B106
|
return (cfg.config("username", ""),
|
||||||
|
cfg.config("password", "")) # nosec B106
|
||||||
+11
-10
@@ -109,8 +109,9 @@ def login_to_api(username: str, password: str):
|
|||||||
|
|
||||||
except requests.exceptions.HTTPError as e:
|
except requests.exceptions.HTTPError as e:
|
||||||
status = e.response.status_code if e.response is not None else None
|
status = e.response.status_code if e.response is not None else None
|
||||||
_log(f"CHYBA HTTP {status if status else '?'}: "
|
telo = (e.response.text[:300] if e.response is not None
|
||||||
f"{e.response.text[:300] if e.response is not None else 'žádná odpověď'}",
|
else "žádná odpověď")
|
||||||
|
_log(f"CHYBA HTTP {status if status else '?'}: {telo}",
|
||||||
Qgis.MessageLevel.Critical)
|
Qgis.MessageLevel.Critical)
|
||||||
LAST_LOGIN_ERROR = 'auth' if status in (401, 403) else 'network'
|
LAST_LOGIN_ERROR = 'auth' if status in (401, 403) else 'network'
|
||||||
return None
|
return None
|
||||||
@@ -623,7 +624,8 @@ def load_amcr_data(canvas, bb, filters=None,
|
|||||||
|
|
||||||
for dj in djs:
|
for dj in djs:
|
||||||
# Skip negative evidence units if requested
|
# Skip negative evidence units if requested
|
||||||
if skip_negativni and dj.get('dj_negativni_jednotka') is True:
|
if (skip_negativni
|
||||||
|
and dj.get('dj_negativni_jednotka') is True):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
komps = dj.get('dj_komponenta', [])
|
komps = dj.get('dj_komponenta', [])
|
||||||
@@ -643,7 +645,8 @@ def load_amcr_data(canvas, bb, filters=None,
|
|||||||
dj_id = dj.get('ident_cely')
|
dj_id = dj.get('ident_cely')
|
||||||
dj_typ = dj.get('dj_typ')
|
dj_typ = dj.get('dj_typ')
|
||||||
|
|
||||||
# Merge shared metadata with documentation unit-specific fields
|
# Merge shared metadata with documentation
|
||||||
|
# unit-specific fields
|
||||||
dj_meta = {
|
dj_meta = {
|
||||||
**meta,
|
**meta,
|
||||||
'dj_id': dj_id,
|
'dj_id': dj_id,
|
||||||
@@ -690,7 +693,8 @@ def load_amcr_data(canvas, bb, filters=None,
|
|||||||
or {}
|
or {}
|
||||||
).get('value', ""),
|
).get('value', ""),
|
||||||
}
|
}
|
||||||
pian_lookup[dj_pian_value].append(komp_meta)
|
pian_lookup[dj_pian_value].append(
|
||||||
|
komp_meta)
|
||||||
target_pian_ids_count += 1
|
target_pian_ids_count += 1
|
||||||
else:
|
else:
|
||||||
# DJ without components — still include
|
# DJ without components — still include
|
||||||
@@ -704,7 +708,8 @@ def load_amcr_data(canvas, bb, filters=None,
|
|||||||
'komponenta_areal': "",
|
'komponenta_areal': "",
|
||||||
'komponenta_obdobi': "",
|
'komponenta_obdobi': "",
|
||||||
}
|
}
|
||||||
pian_lookup[dj_pian_value].append(empty_meta)
|
pian_lookup[dj_pian_value].append(
|
||||||
|
empty_meta)
|
||||||
target_pian_ids_count += 1
|
target_pian_ids_count += 1
|
||||||
else:
|
else:
|
||||||
target_pian_ids_count += 1
|
target_pian_ids_count += 1
|
||||||
@@ -907,9 +912,6 @@ def load_amcr_data(canvas, bb, filters=None,
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
# D) LAYER CREATION (QGIS Memory Layers)
|
# D) LAYER CREATION (QGIS Memory Layers)
|
||||||
# ==========================================
|
# ==========================================
|
||||||
@@ -947,7 +949,6 @@ def load_amcr_data(canvas, bb, filters=None,
|
|||||||
QgsField("typ_dj", QMetaType.Type.QString),
|
QgsField("typ_dj", QMetaType.Type.QString),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
cols += [
|
cols += [
|
||||||
QgsField(typ_dat, QMetaType.Type.QString),
|
QgsField(typ_dat, QMetaType.Type.QString),
|
||||||
QgsField("definicni_body", QMetaType.Type.QString),
|
QgsField("definicni_body", QMetaType.Type.QString),
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class AmcrViewer:
|
|||||||
locale_path = os.path.join(
|
locale_path = os.path.join(
|
||||||
self.plugin_dir,
|
self.plugin_dir,
|
||||||
'i18n',
|
'i18n',
|
||||||
'AmcrViewer_{}.qm'.format(locale)
|
f'AmcrViewer_{locale}.qm'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Install the translator if a translation file
|
# Install the translator if a translation file
|
||||||
@@ -41,7 +41,7 @@ class AmcrViewer:
|
|||||||
|
|
||||||
# Initialize internal state
|
# Initialize internal state
|
||||||
self.actions = []
|
self.actions = []
|
||||||
self.menu = self.tr(u'&AMČR Viewer')
|
self.menu = self.tr('&AMČR Viewer')
|
||||||
self.first_start = None
|
self.first_start = None
|
||||||
|
|
||||||
def tr(self, message):
|
def tr(self, message):
|
||||||
@@ -102,7 +102,7 @@ class AmcrViewer:
|
|||||||
# custom dropdown menu
|
# custom dropdown menu
|
||||||
self.action_download_akce = self.add_action(
|
self.action_download_akce = self.add_action(
|
||||||
icon_path=icon_akce_path,
|
icon_path=icon_akce_path,
|
||||||
text=self.tr(u'Stáhnout data akcí | AMČR Viewer'),
|
text=self.tr('Stáhnout data akcí | AMČR Viewer'),
|
||||||
callback=lambda checked=False: self.run_download('akce'),
|
callback=lambda checked=False: self.run_download('akce'),
|
||||||
parent=self.iface.mainWindow(),
|
parent=self.iface.mainWindow(),
|
||||||
add_to_menu=False,
|
add_to_menu=False,
|
||||||
@@ -112,8 +112,9 @@ class AmcrViewer:
|
|||||||
|
|
||||||
self.action_download_pas = self.add_action(
|
self.action_download_pas = self.add_action(
|
||||||
icon_path=icon_pas_path,
|
icon_path=icon_pas_path,
|
||||||
text=self.tr(u'Stáhnout data samostatných nálezů | AMČR Viewer'),
|
text=self.tr('Stáhnout data samostatných nálezů | AMČR Viewer'),
|
||||||
callback=lambda checked=False: self.run_download('samostatny_nalez'),
|
callback=lambda checked=False: self.run_download(
|
||||||
|
'samostatny_nalez'),
|
||||||
parent=self.iface.mainWindow(),
|
parent=self.iface.mainWindow(),
|
||||||
add_to_menu=False,
|
add_to_menu=False,
|
||||||
add_to_toolbar=False
|
add_to_toolbar=False
|
||||||
@@ -122,7 +123,7 @@ class AmcrViewer:
|
|||||||
|
|
||||||
self.action_download_lokality = self.add_action(
|
self.action_download_lokality = self.add_action(
|
||||||
icon_path=icon_lokality_path,
|
icon_path=icon_lokality_path,
|
||||||
text=self.tr(u'Stáhnout data lokalit | AMČR Viewer'),
|
text=self.tr('Stáhnout data lokalit | AMČR Viewer'),
|
||||||
callback=lambda checked=False: self.run_download('lokalita'),
|
callback=lambda checked=False: self.run_download('lokalita'),
|
||||||
parent=self.iface.mainWindow(),
|
parent=self.iface.mainWindow(),
|
||||||
add_to_menu=False,
|
add_to_menu=False,
|
||||||
@@ -132,7 +133,7 @@ class AmcrViewer:
|
|||||||
|
|
||||||
self.action_login_dialog = self.add_action(
|
self.action_login_dialog = self.add_action(
|
||||||
icon_path=icon_pas_path,
|
icon_path=icon_pas_path,
|
||||||
text=self.tr(u'Přihlásit se | AMČR Viewer'),
|
text=self.tr('Přihlásit se | AMČR Viewer'),
|
||||||
callback=lambda checked=False: self.login(),
|
callback=lambda checked=False: self.login(),
|
||||||
parent=self.iface.mainWindow(),
|
parent=self.iface.mainWindow(),
|
||||||
add_to_menu=False,
|
add_to_menu=False,
|
||||||
@@ -142,7 +143,7 @@ class AmcrViewer:
|
|||||||
|
|
||||||
self.action_amcr_help = self.add_action(
|
self.action_amcr_help = self.add_action(
|
||||||
icon_path=icon_amcr_help_path,
|
icon_path=icon_amcr_help_path,
|
||||||
text=self.tr(u'Nápověda AMČR Help | AMČR Viewer'),
|
text=self.tr('Nápověda AMČR Help | AMČR Viewer'),
|
||||||
callback=lambda checked=False: self.open_help(),
|
callback=lambda checked=False: self.open_help(),
|
||||||
parent=self.iface.mainWindow(),
|
parent=self.iface.mainWindow(),
|
||||||
add_to_menu=False,
|
add_to_menu=False,
|
||||||
|
|||||||
Reference in new issue
Block a user