[Qgis-developer] Using environment variables in path definitions in QGIS

Bo Victor Thomsen bo.victor.thomsen at gmail.com
Mon Jun 22 02:31:38 PDT 2015


To the QGIS developers list -

I have a goal of making a fully portable Windows edition of QGIS. "Fully 
portable" means that I simply can install QGIS by copying the QGIS 
program directory to a location on the users PC and  start QGIS by 
double clicking on the QGIS.bat file in the "..\bin" directory.

I've reached 95% of my target by using the OSGeo4W installation as a 
template and making some modification the the start-up bat file. Mostly 
by using the --configpath qualifier to 1) redefine the location of the 
QGIS user directory .qgis2 and 2) not using the registry to save option 
values.

By using the --configpath qualifier QGIS creates and uses the 
.qgis2\QGIS\QGIS2.ini file to store option values normally located in 
the registry. Some of these values are path definitions:

example:

Configuration\SAGA_FOLDER=C:/OSGeo4W/apps\\saga
Configuration\GRASS_WIN_SHELL=C:/OSGeo4W/apps\\msys
Configuration\R_SCRIPTS_FOLDER=C:\\OSGeo4W\\.qgis2\\processing\\rscripts

I would like to use environment variables as part of the path definition 
in the ini file like this:

Configuration\SAGA_FOLDER=%OSGEO4W_HOME%/apps\\saga
Configuration\GRASS_WIN_SHELL=%OSGEO4W_HOME%/apps\\msys
Configuration\R_SCRIPTS_FOLDER=%QGIS_USERDIR%\\processing\\rscripts

(OSGEO4W_HOME and QGIS_USERDIR is environment variables, that contains 
the path for the QGIS program directory and the QGIS user directory)

The problem is, that QGIS doesn't interpret the %......% as a 
environment variable and replace it with the value of the variable but 
simply interprets it literally resulting in paths containing "%" - signs 
and environment variable names.

Is there a method to get QGIS to interpret the environment variable and 
replace it with the content of the variable ? Or should a put it on the 
wish list in the bug tracker ?

Regards
Bo Victor Thomsen
AestasGIS
Denmark





More information about the Qgis-developer mailing list