Skip to content

Commit

Permalink
feat: support QGIS in OSGeo4W install dir
Browse files Browse the repository at this point in the history
  • Loading branch information
bchartier committed Oct 24, 2023
1 parent 449cdce commit 2bd20c3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/config/templates/pip-install.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python -m pip install -r "{{ file_path }}"
py3_env & python -m ensurepip & python -m pip install -r "{{ file_path }}"
34 changes: 33 additions & 1 deletion src/qgis_apps/find_qgis_apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import winreg
import pathlib


QGIS = "QGIS"
Expand Down Expand Up @@ -32,6 +33,33 @@ def get_qgis_apps() -> list[Software]:
list[Software]: list of QGIS apps
"""

def _update_software_list_from_default_osgeo4w_dir() -> None:
"""Add to the software list the QGIS apps found in the OSGeo4W and OSGeo4W64
directories.
"""
qgis_default_dir_paths = [
r"C:\OSGeo4W64",
r"C:\OSGeo4W",
]

for qgis_default_dir_path in qgis_default_dir_paths:
osgeo4w_bat_file = pathlib.Path(qgis_default_dir_path) / "OSGeo4W.bat"

if not osgeo4w_bat_file.exists():
continue

osgeo4w_bin_dir = pathlib.Path(qgis_default_dir_path) / "bin"
if not osgeo4w_bin_dir.exists():
continue

for qgis_exe_file in osgeo4w_bin_dir.glob("qgis*.exe"):
software: Software = Software("QGIS")
software.publisher = "OSGeo4W"
software.path = qgis_default_dir_path

software_list.append(software)
break

def _create_software_from_info_key(sub_key) -> Software:
"""Create a Software object from one key found in the Widnows registry.
Return None if the app is not a version of QGIS.
Expand Down Expand Up @@ -126,14 +154,18 @@ def _update_software_path_from_installer_folder_info(hive, flag):
value_name, _, _ = winreg.EnumValue(key, count)
if QGIS in value_name:
for software in software_list:
if value_name.endswith(software.path_end_part):
if software.path_end_part and value_name.endswith(
software.path_end_part
):
software.path = value_name
count = count + 1
except WindowsError:
pass

software_list = []

_update_software_list_from_default_osgeo4w_dir()

_update_software_list_from_uninstall_info(
winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_32KEY
)
Expand Down

0 comments on commit 2bd20c3

Please sign in to comment.