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

Bo Victor Thomsen bo.victor.thomsen at gmail.com
Mon Jun 22 06:11:42 PDT 2015


Hi Stefan -

Thanks for the answer.

My "Plan B" was to manually create a "QGIS2.ref", which is identical 
with the original "qgis2.ini", but with every occurrence of  the program 
path and the user profile path replaced with references to environment 
variable names. And then use the sed editor to exchange the variable 
names in qgis2.ref with the actual paths on-the-fly under start-up. More 
or less the solution you suggested.

Sed is luckily included in the OSGeo4W package by default, so I'll have 
a go on "plan B" :-)

And I will add a request about environment variable substitution to the 
existing issue 12623.

Regards
Bo Victor Thomsen
AestasGIS
Denmark

On 22-06-2015 11:55, Blumentrath, Stefan wrote:
> See also:
> http://hub.qgis.org/issues/12623
>
> Maybe it is a bit tricky for a general solution, since variables are defined and named differently on the different OSes?...
>
> As a workaround you could probably put a string replacement procedure into your QGIS.bat?
> We used e.g. a "#USERPROFILE#" string, as a placeholder, which got replaced when a custom QGIS2 folder template - containing the QGIS.ini - was copied to a new user...
>
> Not too trivial to replace a string in a text-file on Windows using batch (I understood from my colleagues)...
>
> Cheers
> Stefan
>
> -----Original Message-----
> From: qgis-developer-bounces at lists.osgeo.org [mailto:qgis-developer-bounces at lists.osgeo.org] On Behalf Of Bo Victor Thomsen
> Sent: 22. juni 2015 11:32
> To: qgis-developer at lists.osgeo.org
> Subject: [Qgis-developer] Using environment variables in path definitions in QGIS
>
> 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
>
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer



More information about the Qgis-developer mailing list