[QGIS-Developer] Using environment variables in QGIS.ini

Thomas Gratier osgeo.mailinglist at gmail.com
Sun Jul 11 18:14:01 PDT 2021


Hi,

I'm not aware QSettings provided by Qt can do it. Your %APPDATA% is not
portable as would only work on Windows

You can always try generate the QGIS.ini file using a templating system

File QGIS.ini.j2 with following content

Configuration\MODELS_FOLDER={{APPDATA}}\\QGIS\\QGIS3\\profiles\\default\\processing\\models
Configuration\SCRIPTS_FOLDERS={{APPDATA}}\\QGIS\\QGIS3\\profiles\\default\\processing\\scripts


File generate_ini.py with following content

import os
import jinja2

templateLoader = jinja2.FileSystemLoader(searchpath="./")
templateEnv = jinja2.Environment(loader=templateLoader)
TEMPLATE_FILE = "QGIS.ini.j2"
template = templateEnv.get_template(TEMPLATE_FILE)
mydict = {
    "APPDATA": os.environ.get("APPDATA")
}
outputText = template.render(**mydict)
with open('QGIS.ini', 'w') as outputfile:
    outputfile.write(outputText)

Then, to write your QGIS.ini file, do


python3 generate_ini.py


The possible deal breakers with this approach are:
- you depend from jinja2, a third party Python library,
- you can't later reuse the mechanism if for instance QGIS changes the
QGIS.ini file later on


Regards

Thomas


Le mar. 6 juil. 2021 à 09:18, Bo Victor Thomsen <bo.victor.thomsen at gmail.com>
a écrit :

> To the list -
>
> Is there a method to use OS (Linux, Windows...) environment variables in
> the QGIS.ini setup file ?
>
> I had a number of customers asking for a method to "generalize" QGIS.ini,
> so it doesn't contain any "user" specific file and directory references, i.e
>
> (From qgis.ini)
>
> Configuration\MODELS_FOLDER=*C:\\Users\\Bo Victor
> Thomsen\\AppData\\Roaming*
> \\QGIS\\QGIS3\\profiles\\default\\processing\\models
> Configuration\SCRIPTS_FOLDERS=*C:\\Users\\Bo Victor
> Thomsen\\AppData\\Roaming*
> \\QGIS\\QGIS3\\profiles\\default\\processing\\scripts
>
> could be:
>
> Configuration\MODELS_FOLDER=*%APPDATA%*
> \\QGIS\\QGIS3\\profiles\\default\\processing\\models
> Configuration\SCRIPTS_FOLDERS=*%APPDATA%*
> \\QGIS\\QGIS3\\profiles\\default\\processing\\scripts
>
> or likewise.
>
> The ultimate reason is to have a method to distribute a "standard" setup
> for QGIS, complete with plugins and specialized setup parameters. This can
> be done by making a standard QGIS installation (which the IT departments
> love, especially with the new .msi package) and afterwards replace the
> "default" profile directory with at  directory specific for the
> organisation. However, the process of making the new profile will place a
> lot of file/directory references in QGIS.ini that is specific for the
> super-user developing the new profile.
>
> --
> Med venlig hilsen / Kind regards
>
> Bo Victor Thomsen
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210712/dbf4090f/attachment.html>


More information about the QGIS-Developer mailing list