[QGIS-Developer] Modify project before loading

Andreas Neumann a.neumann at carto.net
Thu Nov 26 07:20:20 PST 2020


Hi Jacky, 

I recommend to use PostgreSQL service names instead of hostname/port/db
settings. The projects would connect the layers to a central
pg_service.conf file that you can put on a network drive. On the day the
db hostname changes, you can centrally switch the hostname/port/db in
just a single text-file. 

This also helps to switch between test/integration/production
environments by simply pointing to a different pg_service.conf file (see
Options --> System --> Environment and user defined variables. You can
use either PGSERVICEFILE or PGSYSCONFDIR). 

Seems to me easier and more flexible than what you have in mind with
scripting and signals. 

Greetings, 

Andreas 

On 2020-11-26 16:06, VOLPES-EXT, Jacky wrote:

> Hello QGIS dev team J 
> 
> I need to modify QGIS project file at reading (loading) time. 
> 
> The database hostname used in the company is changing soon, and I need this to be transparent for the users. 
> 
> The problem is that all their layers with the old database connections (uri) will trigger a connection error, having the old hostname. 
> 
> The idea is to update the .qgs file that is being opened with the new hostname with a text-replacement plugin, save the file, and eventually load it in QGIS. 
> 
> So that the user will not see any difference or error message. 
> 
> Sadly, the QgsProject.readLayer signal is sent after the project has been loaded, hence after the connection error messages… 
> 
> Any suggestion/idea welcome! 
> 
> Thanks, 
> 
> Jacky Volpes 
> Développeur python 
> 
> HR-Team pour la Société du Canal de Provence
> Direction des Systèmes d'Information
> 
> Tél. 04 42 66 70 34
> Le Tholonet - CS 70064 - 13182 Aix-en-Provence CEDEX 5
> 
> _______________________________________________
> 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/20201126/0bfb2003/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 4649 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20201126/0bfb2003/attachment-0001.jpg>


More information about the QGIS-Developer mailing list