Skip to content

Commit

Permalink
Replace modelbaker plugin with modelbaker library
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Dec 13, 2023
1 parent 89dc802 commit 87ab188
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
1 change: 1 addition & 0 deletions plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
teksi_wastewater/libs/
30 changes: 30 additions & 0 deletions plugin/scripts/package_pip_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
LIBS_DIR="plugin/teksi_wastewater/libs"

MODELBAKER_LIBRARY=("modelbaker" "1.6.0")

PACKAGES=(
MODELBAKER_LIBRARY[@]
)

#create lib folder
mkdir -p $LIBS_DIR

for PACKAGE in ${PACKAGES[@]}; do
echo download and unpack ${!PACKAGE:0:1} with version ${!PACKAGE:1:1}
#create temp folder
mkdir -p temp
#download the wheel
pip download -v ${!PACKAGE:0:1}==${!PACKAGE:1:1} --only-binary :all: -d temp/
#unpack all the wheels found (means including dependencies)
unzip -o "temp/*.whl" -d $LIBS_DIR
#remove temp folder
rm -r temp
#set write rights to group (because qgis-plugin-ci needs it)
chmod -R g+w $LIBS_DIR
done

#create the __init__.py in libs folder
cd $LIBS_DIR
touch __init__.py
chmod g+w __init__.py
4 changes: 0 additions & 4 deletions plugin/teksi_wastewater/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@ icon=icons/teksi-abwasser-logo.svg

experimental=False
deprecated=False

# DISABLED: under QGIS 3.22, this throws `KeyError: 'use_stable_version' (qgsplugindependenciesdialog.py", line 63)`
# unfortunately this doesn't support >= yet...
# plugin_dependencies=QGIS Model Baker==v6.4.0
39 changes: 9 additions & 30 deletions plugin/teksi_wastewater/tww2ili/tww2ili/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import webbrowser
from types import SimpleNamespace

from pkg_resources import parse_version
from qgis import processing
from qgis.core import Qgis, QgsProject, QgsSettings
from qgis.PyQt.QtWidgets import QApplication, QFileDialog, QProgressDialog, QPushButton
from qgis.utils import iface, plugins
from QgisModelBaker.libs.modelbaker.iliwrapper import globals, ili2dbconfig, ili2dbutils
from qgis.utils import iface
from teksi_wastewater.libs.modelbaker.iliwrapper import (
globals,
ili2dbconfig,
ili2dbutils,
)

from ....utils.twwlayermanager import TwwLayerManager
from .. import config
Expand Down Expand Up @@ -52,8 +55,7 @@ def action_import(plugin):
"""
global import_dialog # avoid garbage collection

if not configure_from_modelbaker(plugin.iface):
return
configure_from_modelbaker()

default_folder = QgsSettings().value(
"tww_plugin/last_interlis_path", QgsProject.instance().absolutePath()
Expand Down Expand Up @@ -164,8 +166,7 @@ def action_export(plugin):
Is executed when the user clicks the exportAction tool
"""

if not configure_from_modelbaker(plugin.iface):
return
configure_from_modelbaker()

export_dialog = GuiExport(plugin.iface.mainWindow())

Expand Down Expand Up @@ -332,30 +333,10 @@ def action_do_export():
export_dialog.show()


def configure_from_modelbaker(iface):
def configure_from_modelbaker():
"""
Configures config.JAVA/ILI2PG paths using modelbaker.
Returns whether modelbaker is available, and displays instructions if not.
"""
REQUIRED_VERSION = "v6.4.0" # TODO : update once https://github.com/opengisch/QgisModelBaker/pull/473 is released
modelbaker = plugins.get("QgisModelBaker")
if modelbaker is None:
iface.messageBar().pushMessage(
"Error",
"This feature requires the ModelBaker plugin. Please install and activate it from the plugin manager.",
level=Qgis.Critical,
)
return False

elif modelbaker.__version__ != "dev" and parse_version(modelbaker.__version__) < parse_version(
REQUIRED_VERSION
):
iface.messageBar().pushMessage(
"Error",
f"This feature requires a more recent version of the ModelBaker plugin (currently : {modelbaker.__version__}). Please install and activate version {REQUIRED_VERSION} or newer from the plugin manager.",
level=Qgis.Critical,
)
return False

# We reuse modelbaker's logic to get the java path and ili2pg executables from withing QGIS
# Maybe we could reuse even more (IliExecutable...) ?
Expand All @@ -367,5 +348,3 @@ def configure_from_modelbaker(iface):

config.JAVA = ili2dbutils.get_java_path(ili2dbconfig.BaseConfiguration())
config.ILI2PG = ili2dbutils.get_ili2db_bin(globals.DbIliMode.ili2pg, 4, stdout, stderr)

return True

0 comments on commit 87ab188

Please sign in to comment.