[QGIS-Developer] Modify project before loading

VOLPES-EXT, Jacky Jacky.VOLPES-EXT at canal-de-provence.com
Thu Nov 26 08:56:23 PST 2020


Thanks Regis and Andeas ☺

The big sed on the filesystem could work on .qgs files, but what about .qgz files ? ☺

Regards

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
[cid:image001.png at 01D34C22.F8A861A0]

De : Régis Haubourg [mailto:regis.haubourg at gmail.com]
Envoyé : jeudi 26 novembre 2020 17:52
À : Andreas Neumann <a.neumann at carto.net>
Cc : VOLPES-EXT, Jacky <Jacky.VOLPES-EXT at canal-de-provence.com>; QGIS Developers List <qgis-developer at lists.osgeo.org>
Objet : Re: [QGIS-Developer] Modify project before loading

I can't agree more with Andreas.
The best path is to migrate your project pgservicefile. You will have to handle this as a migration , saving before all project files, and applying a script to replace datasource definitions ( a shell or python script can help, but a big sed on the file system also does the job).

As you are on this, I suggest you add some default connection options as you are on it to preserve your database and speed up table listing as suggested here :
[image.png]

Best regards
Régis
m/RegisHaubourg/status/https://pbs.twimg.com/media/Eats5wgWkAA0VdV?format=png&name=900x9001273231305199804417?s=20https://twitter.com/RegisHaubourg/status/1273231305199804417?s=2https://pbs.twimg.com/media/Eats5wgWkAA0VdV?format=png&name=900x900ttps://twitter.com/RegisHaubourg/status/1273231305199804417?s=20

Le jeu. 26 nov. 2020 à 16:20, Andreas Neumann <a.neumann at carto.net<mailto:a.neumann at carto.net>> a écrit :

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 ☺



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
[cid:image001.png at 01D34C22.F8A861A0]



_______________________________________________
QGIS-Developer mailing list
QGIS-Developer at lists.osgeo.org<mailto: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


_______________________________________________
QGIS-Developer mailing list
QGIS-Developer at lists.osgeo.org<mailto: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/eab62c6a/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 4649 bytes
Desc: image001.jpg
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20201126/eab62c6a/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 79211 bytes
Desc: image002.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20201126/eab62c6a/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.jpg
Type: image/jpeg
Size: 4649 bytes
Desc: image003.jpg
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20201126/eab62c6a/attachment-0003.jpg>


More information about the QGIS-Developer mailing list