Message posté par : Vauchey Vincent (vincent.vauchey(a)iea45.fr)
----------------------------------------
Re
Je rebondis sur le sujet, car la macro et top, mais je voudrais savoir s'il est
possible en changeant le paramètre "copyfile" par un autre, que je ne trouve
pas, de fermer le projet au lieu de faire une copie.
je joins le code pour les amateurs de défis
-----------------
Code :
def openProject():
pass
def saveProject():
pass
def closeProject():
pass
import os
import socket
from qgis.core import QgsProject
from PyQt5.QtWidgets import QMessageBox
### utility functions ###
# get the executing machine and process id #
def _getId():
return socket.getfqdn()+'.'+str(os.getpid())
# read machine and process id holding lock from lock file #
def _getLockerId(file):
try:
with open(file) as _file:
return _file.readline()
except:
return
# create lock file path #
def _getLockFile():
_path, _file = __getProjectPath()
return os.path.join(_path,'.'+_file+'.lock')
# create current project file path root and name #
def __getProjectPath():
return os.path.split(QgsProject.instance().absoluteFilePath())
### QGIS macros ###
def openProject():
lockfile = _getLockFile()
try:
with open(lockfile, "x") as _file:
_file.write(_getId())
except OSError:
_path, _file = __getProjectPath()
copyfile = os.path.join(_path, _getId() + "__" + _file)
QMessageBox.warning(
None,
"Project déja ouvert",
"Impossible d'ouvrir le projet, il est en cours d'utilisation
par: "+
"\n\n"+_getLockerId(lockfile)+
"\nUne copie automatique va être généré\n\n"+copyfile
)
QgsProject.instance().write(copyfile)
QgsProject.instance().read()
QgsProject.instance().setDirty()
def saveProject():
pass
def closeProject():
lockfile = _getLockFile()
if _getId() == _getLockerId(lockfile):
os.remove(lockfile)
-----------------
Par avance merci
----------------------------------------
Le message est situé
https://georezo.net/forum/viewtopic.php?pid=363884#p363884
Pour y répondre : qgis_fr(a)ml.georezo.net ou reply de votre messagerie
Pour vous désabonner connectez-vous sur le forum puis Profil / Abonnement
--
Association GeoRezo - le portail géomatique
https://georezo.net