I would like to use a startup.py that is not stored in the default QGIS-user-folder like ~/.qgis2 or a folder used with the configpath option.
The startup.py I want to use should be located in a folder that is write protected for the users and should only be edited by sysadmins.
Boundless has implemented a interesting functionality called "QGIS Initialization scripts" ( https://connect.boundlessgeo.com/docs/desktop/latest/system_admins/init_scripts.html ).
As a workaround I check in the QGIS startup-file (e.g. qgis.bat) if "my" startup.py is located in the users .qgis2\python-folder. If there is no startup.py in the users folder I copy it into this folder. Otherwise I do a md5 check if the startup.py is identical with my startup.py and overwrite the users startup.py if it is not identical:
:start_qgis
set "file=%QGIS_UDIR%\python\startup.py"
set "referenzfile=%OSGEO4W_ROOT%\bwtacheck\startup.py"
if exist "%file%" goto start_bwta_check
copy /Y %referenzfile% %QGIS_UDIR%\python\startup.py
goto start_qgis2
:start_bwta_check
call %OSGEO4W_ROOT%\bwtacheck\md5.bat %file% file_md5
call %OSGEO4W_ROOT%\bwtacheck\md5.bat %referenzfile% referenz_md5
if "%file_md5%" equ "%referenz_md5%" (
echo MD5 identisch
) else (
echo MD5 nicht identisch
copy /Y %QGIS_UDIR%\python\startup.py %QGIS_UDIR%\python\startup_overwritten.py
copy /Y %referenzfile% %QGIS_UDIR%\python\startup.py
)
:start_qgis2
REM Run the central update commmandfile if the variable is set to a location and the file exist.
if *%QGIS_NETCMD%==* exit /b
if exist %QGIS_NETCMD% call %QGIS_NETCMD%
exit /b
Does the plain QGIS also support the use of a startup-script that is stored outside the typical userprofile-folder (the one used by qgis to store the plugins etc.)?
I tried to use a startup.py in the program-folder (like C:\OSGeo4W64\apps\qgis-ltr\python) but this did not work. Is this a bug or meant to be?
PS: It is important that the startup-script gets executed after QGIS has initialised.
No comments:
Post a Comment