Friday 8 February 2019

pyqgis - Central deployment of startup.py in QGIS


In QGIS 3 on Win10 we use a startup.py script for setting up e.g. database connections and a couple of other things, residing in C:\Users\me\AppData\Roaming\QGIS\QGIS3


What we are after is to centrally deploy the startup.py without having to distribute it to each of our clients at every script change.


First try was to make use of the PYQGIS_STARTUP environment variable, but this fails, because startup.py makes use of qgis.* modules which are of course not available before QGIS initialization is complete.


How can we centrally deploy our startup.py in order to apply changes on every client without having to distribute it?



Answer



Our solution is to let the environment variable PYQGIS_STARTUP point to a very simple pre-startup.py script that copies the startup.py from a central location to the required users QGIS 3 directory:


import os, shutil
account = os.getlogin()
shutil.copy2('X:/central/location/for/startup.py', 'C:/Users/{0}/AppData/Roaming/QGIS/QGIS3'.format(account))


QGIS 3 then executes this previously copied startup.py.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...