Skip to content

Commit

Permalink
Add helper to handle common error on exe name (#206)
Browse files Browse the repository at this point in the history
To make @EmilieEPLoire's lfe easier 😉 

Use case:

```yaml
[...]
settings:
  QGIS_EXE_PATH:
    linux: /usr/bin/qgis
    mac: /usr/bin/qgis
    windows: "%PROGRAMFILES%/QGIS/3_22/bin/qgis-bin.exe"
[...]
```

Common error on executable name which is `/qgis-ltr-bin.exe` when LTR
version is installed. This PR adds an helper to check if
`qgis-ltr-bin.exe` exists when `qgis-bin.exe` is set. And vice-versa.
  • Loading branch information
Guts authored Mar 2, 2023
2 parents 88dbecf + 7dd996a commit e3b1d1d
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion qgis_deployment_toolbelt/profiles/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@
# logs
logger = logging.getLogger(__name__)


# #############################################################################
# ########## Classes ###############
# ##################################


class ApplicationShortcut:
def __init__(
self,
Expand Down Expand Up @@ -87,7 +90,32 @@ def __init__(
if isinstance(exec_path, (str, Path)):
self.exec_path = Path(exec_path)
if not self.exec_path.exists():
logger.warning(f"Executable does not exist: {self.exec_path}")
# helper to handle common typo error on executable name on Windows
if (
self.exec_path.name.endswith("qgis-bin.exe")
and self.exec_path.with_name("qgis-ltr-bin.exe").exists()
):
logger.warning(
f"Executable set does not exist: {self.exec_path} "
f"but {self.exec_path.with_name('qgis-ltr-bin.exe')} does, so "
"this one will be used instead. Check and fix your scenario."
)
self.exec_path = self.exec_path.with_name("qgis-ltr-bin.exe")
elif (
self.exec_path.name.endswith("qgis-ltr-bin.exe")
and self.exec_path.with_name("qgis-bin.exe").exists()
):
logger.warning(
f"Executable set does not exist: {self.exec_path} "
f"but {self.exec_path.with_name('qgis-bin.exe')} does, so "
"this one will be used instead. Check and fix your scenario."
)
self.exec_path = self.exec_path.with_name("qgis-bin.exe")
else:
logger.warning(
f"Executable does not exist: {self.exec_path}. "
"Shortcuts might not work. Check and fix your scenario."
)
else:
raise TypeError(
f"exec_path must be a string or pathlib.Path, not {type(exec_path)}"
Expand Down

0 comments on commit e3b1d1d

Please sign in to comment.