diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 7d306c1..d7e1340 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -57,4 +57,3 @@ repos:
ci:
autofix_prs: true
autoupdate_schedule: quarterly
-
diff --git a/pg_service_parser/config.py b/pg_service_parser/config.py
index 65003ad..d294428 100644
--- a/pg_service_parser/config.py
+++ b/pg_service_parser/config.py
@@ -1,4 +1,3 @@
import os.path
-
DEFAULT_PG_SERVICE_PATH = os.path.expanduser("~/.pg_service.conf")
diff --git a/pg_service_parser/gui/dlg_pg_service.py b/pg_service_parser/gui/dlg_pg_service.py
index 7395522..25cddc4 100644
--- a/pg_service_parser/gui/dlg_pg_service.py
+++ b/pg_service_parser/gui/dlg_pg_service.py
@@ -1,15 +1,15 @@
-from qgis.PyQt.QtCore import (Qt,
- pyqtSlot)
-from qgis.PyQt.QtWidgets import (QDialog,
- QSizePolicy)
from qgis.gui import QgsMessageBar
-
-from pg_service_parser.pg_service_parser_wrapper import (conf_path,
- copy_service_settings,
- service_names)
+from qgis.PyQt.QtCore import Qt, pyqtSlot
+from qgis.PyQt.QtWidgets import QDialog, QSizePolicy
+
+from pg_service_parser.pg_service_parser_wrapper import (
+ conf_path,
+ copy_service_settings,
+ service_names,
+)
from pg_service_parser.utils import get_ui_class
-DIALOG_UI = get_ui_class('pg_service_dialog.ui')
+DIALOG_UI = get_ui_class("pg_service_dialog.ui")
COPY_TAB_INDEX = 0
EDIT_TAB_INDEX = 1
@@ -23,7 +23,9 @@ def __init__(self, parent):
conf_file_path = conf_path()
if not conf_file_path:
self.lblConfFile.setText("Config file not found!")
- self.lblConfFile.setToolTip("Set your PGSERVICEFILE environment variable and reopen the dialog.")
+ self.lblConfFile.setToolTip(
+ "Set your PGSERVICEFILE environment variable and reopen the dialog."
+ )
self.txtConfFile.setVisible(False)
self.tabWidget.setEnabled(False)
return
@@ -79,14 +81,20 @@ def __copy_service(self):
self.bar.pushInfo("PG service", "Enter a service name and try again.")
return
elif self.txtNewService.text().strip() in service_names():
- self.bar.pushWarning("PG service", "Service name already exists! Change it and try again.")
+ self.bar.pushWarning(
+ "PG service", "Service name already exists! Change it and try again."
+ )
return
elif self.radOverwrite.isChecked():
if not self.cboTargetService.currentText():
self.bar.pushInfo("PG service", "Select a valid target service and try again.")
return
- target_service = self.cboTargetService.currentText() if self.radOverwrite.isChecked() else self.txtNewService.text().strip()
+ target_service = (
+ self.cboTargetService.currentText()
+ if self.radOverwrite.isChecked()
+ else self.txtNewService.text().strip()
+ )
if copy_service_settings(self.cboSourceService.currentText(), target_service):
self.bar.pushSuccess("PG service", f"PG service copied to '{target_service}'!")
diff --git a/pg_service_parser/images/warning.svg b/pg_service_parser/images/warning.svg
index c6b8c23..539b63e 100644
--- a/pg_service_parser/images/warning.svg
+++ b/pg_service_parser/images/warning.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
diff --git a/pg_service_parser/metadata.txt b/pg_service_parser/metadata.txt
index 366d50f..3e6e196 100644
--- a/pg_service_parser/metadata.txt
+++ b/pg_service_parser/metadata.txt
@@ -14,4 +14,4 @@ tracker=https://github.com/opengisch/qgis-pg-service-parser-plugin/issues
repository=https://github.com/opengisch/qgis-pg-service-parser-plugin
icon=images/icon.png
experimental=False
-deprecated=False
\ No newline at end of file
+deprecated=False
diff --git a/pg_service_parser/pg_service_parser_plugin.py b/pg_service_parser/pg_service_parser_plugin.py
index df0d78f..126586f 100644
--- a/pg_service_parser/pg_service_parser_plugin.py
+++ b/pg_service_parser/pg_service_parser_plugin.py
@@ -3,13 +3,13 @@
from pg_service_parser.gui.dlg_pg_service import PgServiceDialog
-class PgServiceParserPlugin():
+class PgServiceParserPlugin:
def __init__(self, iface):
self.iface = iface
self.action = None
def initGui(self):
- self.action = QAction('Go!', self.iface.mainWindow())
+ self.action = QAction("Go!", self.iface.mainWindow())
self.action.triggered.connect(self.run)
self.iface.addToolBarIcon(self.action)
diff --git a/pg_service_parser/pg_service_parser_wrapper.py b/pg_service_parser/pg_service_parser_wrapper.py
index 5b12bc7..66e3a74 100644
--- a/pg_service_parser/pg_service_parser_wrapper.py
+++ b/pg_service_parser/pg_service_parser_wrapper.py
@@ -1,14 +1,14 @@
import os.path
+from typing import List, Optional
import pgserviceparser
-from typing import (List,
- Optional)
def conf_path() -> str:
path = pgserviceparser.conf_path()
return path if os.path.exists(path) else None
+
def service_names(conf_file_path: Optional[str] = None) -> List[str]:
return pgserviceparser.service_names(conf_file_path)
@@ -18,9 +18,9 @@ def service_config(service_name: str, conf_file_path: Optional[str] = None) -> d
def write_service_settings(
- service_name: str,
- settings: dict,
- conf_file_path: Optional[str] = None,
+ service_name: str,
+ settings: dict,
+ conf_file_path: Optional[str] = None,
) -> bool:
"""Returns true if it could write the settings to the file.
@@ -39,13 +39,15 @@ def write_service_settings(
return False
-def create_service(service_name: str, settings: dict, conf_file_path: Optional[str] = None) -> bool:
+def create_service(
+ service_name: str, settings: dict, conf_file_path: Optional[str] = None
+) -> bool:
config = pgserviceparser.full_config(conf_file_path)
if service_name in config:
return False
config.add_section(service_name)
- with open(conf_file_path or pgserviceparser.conf_path(), 'w') as f:
+ with open(conf_file_path or pgserviceparser.conf_path(), "w") as f:
config.write(f)
if service_name in config:
@@ -54,7 +56,9 @@ def create_service(service_name: str, settings: dict, conf_file_path: Optional[s
return False
-def copy_service_settings(source_service_name: str, target_service_name: str, conf_file_path: Optional[str] = None) -> bool:
+def copy_service_settings(
+ source_service_name: str, target_service_name: str, conf_file_path: Optional[str] = None
+) -> bool:
settings = pgserviceparser.service_config(source_service_name, conf_file_path)
config = pgserviceparser.full_config(conf_file_path)
@@ -67,12 +71,17 @@ def copy_service_settings(source_service_name: str, target_service_name: str, co
return res
-if __name__ == '__main__':
+if __name__ == "__main__":
assert service_names() == []
# Add new service
- _settings = {'host': 'localhost', 'port': '5432', 'user': 'postgres', 'password': 'secret',
- 'dbname': 'qgis_test_db'}
+ _settings = {
+ "host": "localhost",
+ "port": "5432",
+ "user": "postgres",
+ "password": "secret",
+ "dbname": "qgis_test_db",
+ }
assert create_service("qgis-test", _settings)
assert service_names() == ["qgis-test"]
@@ -82,8 +91,13 @@ def copy_service_settings(source_service_name: str, target_service_name: str, co
assert service_config("qgis-demo") == _settings
# Add new service
- _settings = {'host': 'localhost', 'port': '5433', 'user': 'admin', 'password': 'secret',
- 'dbname': 'qgis_test_db2'}
+ _settings = {
+ "host": "localhost",
+ "port": "5433",
+ "user": "admin",
+ "password": "secret",
+ "dbname": "qgis_test_db2",
+ }
assert create_service("qgis-new-test", _settings)
assert service_names() == ["qgis-test", "qgis-demo", "qgis-new-test"]
assert service_config("qgis-new-test") == _settings
diff --git a/pg_service_parser/utils.py b/pg_service_parser/utils.py
index 02a9388..9c7f47f 100644
--- a/pg_service_parser/utils.py
+++ b/pg_service_parser/utils.py
@@ -1,6 +1,6 @@
import os
-from qgis.PyQt.uic import (loadUiType,
- loadUi)
+
+from qgis.PyQt.uic import loadUiType
from pg_service_parser.config import DEFAULT_PG_SERVICE_PATH
@@ -16,14 +16,8 @@ def get_ui_class(ui_file):
def get_ui_file_path(ui_file) -> str:
- os.path.sep.join(ui_file.split('/'))
- ui_file_path = os.path.abspath(
- os.path.join(
- os.path.dirname(__file__),
- 'ui',
- ui_file
- )
- )
+ os.path.sep.join(ui_file.split("/"))
+ ui_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "ui", ui_file))
return ui_file_path