flake8 postgis
This commit is contained in:
parent
133e785568
commit
7df08ae02a
@ -4,9 +4,9 @@ __email__ = "info@3liz.org"
|
|||||||
|
|
||||||
|
|
||||||
from qgis.core import QgsApplication
|
from qgis.core import QgsApplication
|
||||||
from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator, QUrl
|
from qgis.PyQt.QtCore import QUrl
|
||||||
from qgis.PyQt.QtGui import QDesktopServices, QIcon
|
from qgis.PyQt.QtGui import QDesktopServices, QIcon
|
||||||
from qgis.PyQt.QtWidgets import QAction, QMessageBox
|
from qgis.PyQt.QtWidgets import QAction
|
||||||
from qgis.utils import iface
|
from qgis.utils import iface
|
||||||
import qgis
|
import qgis
|
||||||
|
|
||||||
@ -15,8 +15,10 @@ import qgis
|
|||||||
|
|
||||||
import socket
|
import socket
|
||||||
import os
|
import os
|
||||||
|
from qgis.PyQt.QtCore import QSettings
|
||||||
|
from .about_form import AboutDialog
|
||||||
from .tools.resources import (
|
from .tools.resources import (
|
||||||
plugin_path,
|
# plugin_path,
|
||||||
pyperclip,
|
pyperclip,
|
||||||
resources_path,
|
resources_path,
|
||||||
maj_verif,
|
maj_verif,
|
||||||
@ -26,13 +28,11 @@ pyperclip()
|
|||||||
from .postgis_editor import Postgis_Editor
|
from .postgis_editor import Postgis_Editor
|
||||||
from .postgis_creator import Postgis_Creator
|
from .postgis_creator import Postgis_Creator
|
||||||
from .postgis_rename import Postgis_Rename
|
from .postgis_rename import Postgis_Rename
|
||||||
from .about_form import AboutDialog
|
|
||||||
|
|
||||||
from qgis.PyQt.QtCore import *
|
|
||||||
|
|
||||||
|
|
||||||
IPAddr = socket.gethostbyname(socket.gethostname())
|
IPAddr = socket.gethostbyname(socket.gethostname())
|
||||||
|
|
||||||
|
|
||||||
class PgPostgis:
|
class PgPostgis:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
""" Constructor. """
|
""" Constructor. """
|
||||||
@ -121,6 +121,7 @@ class PgPostgis:
|
|||||||
"""
|
"""
|
||||||
dialog = AboutDialog(iface)
|
dialog = AboutDialog(iface)
|
||||||
dialog.exec()
|
dialog.exec()
|
||||||
|
|
||||||
def open_help():
|
def open_help():
|
||||||
""" Open the online help. """
|
""" Open the online help. """
|
||||||
QDesktopServices.openUrl(QUrl('https://plateformesig.cenra-outils.org/'))
|
QDesktopServices.openUrl(QUrl('https://plateformesig.cenra-outils.org/'))
|
||||||
|
|||||||
@ -2,50 +2,50 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
# Import the PyQt and QGIS libraries
|
# Import the PyQt and QGIS libraries
|
||||||
from builtins import next
|
# from builtins import next
|
||||||
from builtins import str
|
# from builtins import str
|
||||||
from builtins import object
|
# from builtins import object
|
||||||
import qgis
|
# import qgis
|
||||||
from qgis.PyQt.QtCore import QSettings
|
from qgis.PyQt.QtCore import QSettings
|
||||||
from qgis.PyQt.QtWidgets import QAction, QMenu, QDialog,QMessageBox
|
from qgis.PyQt.QtWidgets import QDialog, QMessageBox
|
||||||
from qgis.PyQt.QtGui import QIcon
|
# from qgis.PyQt.QtGui import QIcon
|
||||||
|
|
||||||
from qgis.PyQt.QtCore import *
|
# from qgis.PyQt.QtCore import *
|
||||||
from qgis.PyQt.QtGui import *
|
# from qgis.PyQt.QtGui import *
|
||||||
from qgis.PyQt import QtGui
|
from qgis.PyQt import QtGui
|
||||||
|
|
||||||
from qgis.core import *
|
# from qgis.core import *
|
||||||
from qgis.core import QgsDataSourceUri
|
from qgis.core import QgsSettings
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from .tools.PythonSQL import login_base
|
from .tools.PythonSQL import login_base
|
||||||
except:
|
except ValueError:
|
||||||
print('Pas de fichier PythonSQL')
|
print('Pas de fichier PythonSQL')
|
||||||
|
|
||||||
from .tools.SQLRequet import *
|
# from .tools.SQLRequet import *
|
||||||
|
|
||||||
from .tools.resources import (
|
from .tools.resources import (
|
||||||
load_ui,
|
load_ui,
|
||||||
resources_path,
|
resources_path,
|
||||||
send_issues,
|
# send_issues,
|
||||||
create_vierge,
|
create_vierge,
|
||||||
create_contour,
|
create_contour,
|
||||||
create_travaux,
|
create_travaux,
|
||||||
create_habita
|
create_habita
|
||||||
)
|
)
|
||||||
from .issues import CenRa_Issues
|
# from .issues import CenRa_Issues
|
||||||
|
|
||||||
from qgis.utils import iface
|
from qgis.utils import iface
|
||||||
import os.path
|
# import os.path
|
||||||
import webbrowser, os
|
# import webbrowser, os
|
||||||
import psycopg2
|
# import psycopg2
|
||||||
import psycopg2.extras
|
# import psycopg2.extras
|
||||||
import base64
|
# import base64
|
||||||
|
|
||||||
EDITOR_CLASS = load_ui('CenRa_Postgis_base.ui')
|
EDITOR_CLASS = load_ui('CenRa_Postgis_base.ui')
|
||||||
|
|
||||||
class Postgis_Creator(QDialog, EDITOR_CLASS):
|
|
||||||
|
|
||||||
|
class Postgis_Creator(QDialog, EDITOR_CLASS):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
_ = parent
|
_ = parent
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -64,14 +64,14 @@ class Postgis_Creator(QDialog, EDITOR_CLASS):
|
|||||||
result = self.exec()
|
result = self.exec()
|
||||||
# See if OK was pressed
|
# See if OK was pressed
|
||||||
if result == 1:
|
if result == 1:
|
||||||
|
|
||||||
# **********************************Debut_script****************************************
|
# **********************************Debut_script****************************************
|
||||||
|
# Creation du schema pour le nouveau site
|
||||||
### Creation du schema pour le nouveau site
|
|
||||||
if self.at.isChecked():
|
if self.at.isChecked():
|
||||||
schema = "_" + self.dept.currentText() + "_at_" + self.nom.text().lower() # Ajout de "_" pour eviter pb de numero en premier caractere
|
# Ajout de "_" pour eviter pb de numero en premier caractere
|
||||||
|
schema = "_" + self.dept.currentText() + "_at_" + self.nom.text().lower()
|
||||||
else:
|
else:
|
||||||
schema = "_" + self.dept.currentText() + "_" + self.nom.text().lower() # Ajout de "_" pour eviter pb de numero en premier caractere
|
# Ajout de "_" pour eviter pb de numero en premier caractere
|
||||||
|
schema = "_" + self.dept.currentText() + "_" + self.nom.text().lower()
|
||||||
|
|
||||||
if self.nom.text() == "" or self.nom.text() == "NULL":
|
if self.nom.text() == "" or self.nom.text() == "NULL":
|
||||||
QMessageBox.warning(None, "Oups :", "Veuillez renseigner un nom de dossier.")
|
QMessageBox.warning(None, "Oups :", "Veuillez renseigner un nom de dossier.")
|
||||||
@ -98,13 +98,12 @@ class Postgis_Creator(QDialog, EDITOR_CLASS):
|
|||||||
cur.execute(SQL_schema)
|
cur.execute(SQL_schema)
|
||||||
cur.execute(SQL_GRANT_SCHEMA)
|
cur.execute(SQL_GRANT_SCHEMA)
|
||||||
else:
|
else:
|
||||||
iface.messageBar().pushMessage("POSTGRESQL :", "Pas de couche sélectionnée, création refusée.", level=Qgis.Warning, duration=30)
|
iface.messageBar().pushMessage("POSTGRESQL :", "Pas de couche sélectionnée, création refusée.", level=1, duration=30)
|
||||||
|
|
||||||
create_contour(self, schema, cur, con, host, port, dbname, user, mdp)
|
create_contour(self, schema, cur, con, host, port, dbname, user, mdp)
|
||||||
create_habita(self, schema, cur, con, host, port, dbname, user, mdp)
|
create_habita(self, schema, cur, con, host, port, dbname, user, mdp)
|
||||||
create_travaux(self, schema, cur, con, host, port, dbname, user, mdp)
|
create_travaux(self, schema, cur, con, host, port, dbname, user, mdp)
|
||||||
create_vierge(self, schema, cur, con, host, port, dbname, user, mdp)
|
create_vierge(self, schema, cur, con, host, port, dbname, user, mdp)
|
||||||
|
|
||||||
|
|
||||||
con.close()
|
con.close()
|
||||||
pass
|
pass
|
||||||
@ -4,47 +4,45 @@ from __future__ import absolute_import
|
|||||||
# Import the PyQt and QGIS libraries
|
# Import the PyQt and QGIS libraries
|
||||||
from builtins import next
|
from builtins import next
|
||||||
from builtins import str
|
from builtins import str
|
||||||
from builtins import object
|
# from builtins import object
|
||||||
import qgis
|
# import qgis
|
||||||
from qgis.PyQt.QtCore import QSettings
|
from qgis.PyQt.QtCore import QSettings
|
||||||
from qgis.PyQt.QtWidgets import QAction, QMenu, QDialog
|
from qgis.PyQt.QtWidgets import QDialog, QMessageBox
|
||||||
from qgis.PyQt.QtGui import QIcon
|
# from qgis.PyQt.QtGui import QIcon
|
||||||
|
|
||||||
from qgis.PyQt.QtCore import *
|
|
||||||
from qgis.PyQt.QtGui import *
|
|
||||||
from qgis.PyQt import QtGui
|
from qgis.PyQt import QtGui
|
||||||
|
|
||||||
from qgis.core import *
|
# from qgis.core import *
|
||||||
from qgis.core import QgsDataSourceUri
|
from qgis.core import QgsSettings
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from .tools.PythonSQL import login_base
|
from .tools.PythonSQL import login_base
|
||||||
except:
|
except ValueError:
|
||||||
print('Pas de fichier PythonSQL')
|
print('Pas de fichier PythonSQL')
|
||||||
from .tools.SQLRequet import *
|
# from .tools.SQLRequet import *
|
||||||
|
|
||||||
from .tools.resources import (
|
from .tools.resources import (
|
||||||
load_ui,
|
load_ui,
|
||||||
resources_path,
|
resources_path,
|
||||||
send_issues,
|
# send_issues,
|
||||||
create_vierge,
|
create_vierge,
|
||||||
create_contour,
|
create_contour,
|
||||||
create_travaux,
|
create_travaux,
|
||||||
create_habita
|
create_habita
|
||||||
)
|
)
|
||||||
from .issues import CenRa_Issues
|
# from .issues import CenRa_Issues
|
||||||
|
|
||||||
import os.path
|
# import os.path
|
||||||
import webbrowser, os
|
# import webbrowser
|
||||||
import psycopg2
|
# import psycopg2
|
||||||
import psycopg2.extras
|
# import psycopg2.extras
|
||||||
import base64
|
# import base64
|
||||||
from qgis.utils import iface
|
from qgis.utils import iface
|
||||||
|
|
||||||
EDITOR_CLASS = load_ui('CenRa_PostgisTable_base.ui')
|
EDITOR_CLASS = load_ui('CenRa_PostgisTable_base.ui')
|
||||||
|
|
||||||
class Postgis_Editor(QDialog, EDITOR_CLASS):
|
|
||||||
|
|
||||||
|
class Postgis_Editor(QDialog, EDITOR_CLASS):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
_ = parent
|
_ = parent
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -54,7 +52,7 @@ class Postgis_Editor(QDialog, EDITOR_CLASS):
|
|||||||
self.setWindowIcon(QtGui.QIcon(resources_path('icons', 'icon.png')))
|
self.setWindowIcon(QtGui.QIcon(resources_path('icons', 'icon.png')))
|
||||||
self.iface = iface
|
self.iface = iface
|
||||||
|
|
||||||
### Outil Ajout de nouvelles couche a un dossier
|
# Outil Ajout de nouvelles couche a un dossier
|
||||||
def raise_(self):
|
def raise_(self):
|
||||||
self.activateWindow()
|
self.activateWindow()
|
||||||
account = login_base("account")
|
account = login_base("account")
|
||||||
@ -71,7 +69,6 @@ class Postgis_Editor(QDialog, EDITOR_CLASS):
|
|||||||
where schemaname ~ E'^_(0|1|2|3|4|6|7|f)'
|
where schemaname ~ E'^_(0|1|2|3|4|6|7|f)'
|
||||||
group by schemaname
|
group by schemaname
|
||||||
order by schemaname)
|
order by schemaname)
|
||||||
|
|
||||||
select string_agg(schemaname,',')
|
select string_agg(schemaname,',')
|
||||||
from list_schema
|
from list_schema
|
||||||
group by "group";"""
|
group by "group";"""
|
||||||
@ -86,7 +83,8 @@ class Postgis_Editor(QDialog, EDITOR_CLASS):
|
|||||||
|
|
||||||
self.schema.clear()
|
self.schema.clear()
|
||||||
self.schema.addItems(listItems)
|
self.schema.addItems(listItems)
|
||||||
self.schema.setCurrentIndex(-1) # Pour ne pas commencer la liste au premier schema
|
# Pour ne pas commencer la liste au premier schema
|
||||||
|
self.schema.setCurrentIndex(-1)
|
||||||
|
|
||||||
# show the dialog
|
# show the dialog
|
||||||
self.show()
|
self.show()
|
||||||
|
|||||||
@ -2,43 +2,39 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
# Import the PyQt and QGIS libraries
|
# Import the PyQt and QGIS libraries
|
||||||
from builtins import next
|
# from builtins import next
|
||||||
from builtins import str
|
from builtins import str
|
||||||
from builtins import object
|
# from builtins import object
|
||||||
import qgis
|
# import qgis
|
||||||
from qgis.PyQt.QtCore import QSettings
|
from qgis.PyQt.QtCore import QSettings
|
||||||
from qgis.PyQt.QtWidgets import QAction, QMenu, QDialog, QMessageBox,QDialogButtonBox
|
from qgis.PyQt.QtWidgets import QDialog, QMessageBox, QDialogButtonBox
|
||||||
from qgis.PyQt.QtGui import QIcon
|
# from qgis.PyQt.QtGui import QIcon
|
||||||
|
|
||||||
from qgis.PyQt.QtCore import *
|
# from qgis.PyQt.QtCore import *
|
||||||
from qgis.PyQt.QtGui import *
|
# from qgis.PyQt.QtGui import *
|
||||||
from qgis.PyQt import QtGui
|
from qgis.PyQt import QtGui
|
||||||
|
|
||||||
from qgis.core import *
|
# from qgis.core import *
|
||||||
from qgis.core import QgsDataSourceUri
|
from qgis.core import QgsSettings, QgsDataSourceUri, QgsProject
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from .tools.PythonSQL import login_base
|
from .tools.PythonSQL import login_base
|
||||||
except:
|
except ValueError:
|
||||||
print('Pas de fichier PythonSQL')
|
print('Pas de fichier PythonSQL')
|
||||||
from .tools.SQLRequet import *
|
# from .tools.SQLRequet import *
|
||||||
|
|
||||||
from .tools.resources import (
|
from .tools.resources import (
|
||||||
load_ui,
|
load_ui,
|
||||||
resources_path,
|
resources_path,
|
||||||
send_issues,
|
# send_issues,
|
||||||
create_vierge,
|
|
||||||
create_contour,
|
|
||||||
create_travaux,
|
|
||||||
create_habita
|
|
||||||
)
|
)
|
||||||
from .issues import CenRa_Issues
|
# from .issues import CenRa_Issues
|
||||||
|
|
||||||
import os.path
|
# import os.path
|
||||||
import webbrowser, os
|
# import webbrowser
|
||||||
import psycopg2
|
# import psycopg2
|
||||||
import psycopg2.extras
|
# import psycopg2.extras
|
||||||
import base64
|
# import base64
|
||||||
from qgis.utils import iface
|
from qgis.utils import iface
|
||||||
|
|
||||||
EDITOR_CLASS = load_ui('CenRa_PostgisRename_base.ui')
|
EDITOR_CLASS = load_ui('CenRa_PostgisRename_base.ui')
|
||||||
@ -52,10 +48,11 @@ try:
|
|||||||
dbname = account[4]
|
dbname = account[4]
|
||||||
cur = account[7]
|
cur = account[7]
|
||||||
con = account[8]
|
con = account[8]
|
||||||
except:
|
except ValueError:
|
||||||
print('')
|
print('')
|
||||||
class Postgis_Rename(QDialog, EDITOR_CLASS):
|
|
||||||
|
|
||||||
|
|
||||||
|
class Postgis_Rename(QDialog, EDITOR_CLASS):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
_ = parent
|
_ = parent
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -67,7 +64,8 @@ class Postgis_Rename(QDialog, EDITOR_CLASS):
|
|||||||
|
|
||||||
self.schema.currentIndexChanged.connect(self.Test)
|
self.schema.currentIndexChanged.connect(self.Test)
|
||||||
self.buttonBox.accepted.connect(self.msgBox)
|
self.buttonBox.accepted.connect(self.msgBox)
|
||||||
### Outil Ajout de nouvelles couche a un dossier
|
# Outil Ajout de nouvelles couche a un dossier
|
||||||
|
|
||||||
def raise_(self):
|
def raise_(self):
|
||||||
self.activateWindow()
|
self.activateWindow()
|
||||||
self.groupBox_3.hide()
|
self.groupBox_3.hide()
|
||||||
@ -188,12 +186,10 @@ class Postgis_Rename(QDialog, EDITOR_CLASS):
|
|||||||
SQL_RENAME_SCHEMA = 'ALTER SCHEMA ' + oldSchemaName + ' RENAME TO ' + newSchemaName
|
SQL_RENAME_SCHEMA = 'ALTER SCHEMA ' + oldSchemaName + ' RENAME TO ' + newSchemaName
|
||||||
allSQLrun = allSQLrun + SQL_RENAME_SCHEMA
|
allSQLrun = allSQLrun + SQL_RENAME_SCHEMA
|
||||||
cur.execute(SQL_RENAME_SCHEMA)
|
cur.execute(SQL_RENAME_SCHEMA)
|
||||||
#print(allSQLrun)
|
|
||||||
con.commit()
|
con.commit()
|
||||||
for LayerOpen in allTableList:
|
for LayerOpen in allTableList:
|
||||||
self.UnloadLoadLayers(LayerOpen[0], LayerOpen[1], LayerOpen[2])
|
self.UnloadLoadLayers(LayerOpen[0], LayerOpen[1], LayerOpen[2])
|
||||||
|
|
||||||
|
|
||||||
def UnloadLoadLayers(self, OldName, NewSchema, NewTable):
|
def UnloadLoadLayers(self, OldName, NewSchema, NewTable):
|
||||||
allLayers = (QgsProject.instance().mapLayers().values())
|
allLayers = (QgsProject.instance().mapLayers().values())
|
||||||
listLayers = []
|
listLayers = []
|
||||||
@ -210,7 +206,7 @@ class Postgis_Rename(QDialog, EDITOR_CLASS):
|
|||||||
host = QgsDataSourceUri(provider.dataSourceUri()).host()
|
host = QgsDataSourceUri(provider.dataSourceUri()).host()
|
||||||
port = QgsDataSourceUri(provider.dataSourceUri()).port()
|
port = QgsDataSourceUri(provider.dataSourceUri()).port()
|
||||||
|
|
||||||
### Affichage de la table
|
# Affichage de la table
|
||||||
uri = QgsDataSourceUri()
|
uri = QgsDataSourceUri()
|
||||||
# set host name, port, database name, username and password
|
# set host name, port, database name, username and password
|
||||||
uri.setConnection(host, port, dbname, user, mdp)
|
uri.setConnection(host, port, dbname, user, mdp)
|
||||||
|
|||||||
@ -3,13 +3,13 @@
|
|||||||
import configparser
|
import configparser
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import base64
|
# import base64
|
||||||
import psycopg2
|
# import psycopg2
|
||||||
import psycopg2.extras
|
# import psycopg2.extras
|
||||||
import os
|
import os
|
||||||
from os.path import abspath, join, pardir, dirname
|
from os.path import abspath, join, pardir, dirname
|
||||||
from qgis.core import QgsDataSourceUri
|
from qgis.core import QgsDataSourceUri
|
||||||
from .SQLRequet import *
|
from .SQLRequet import geom, champ_contour, champ_travaux_prevus_multilinestring, champ_travaux_prevus_point, champ_travaux_prevus_multipolygon, champ_vegethab_multipolygon, champ_vegethab_multilinestring, champ_vegethab_point, champ_viergeLigne, champ_viergePoint, champ_viergePolygone
|
||||||
from qgis.PyQt import uic
|
from qgis.PyQt import uic
|
||||||
|
|
||||||
__copyright__ = "Copyright 2019, 3Liz"
|
__copyright__ = "Copyright 2019, 3Liz"
|
||||||
@ -109,46 +109,51 @@ def load_ui(*args):
|
|||||||
|
|
||||||
return ui_class
|
return ui_class
|
||||||
|
|
||||||
|
|
||||||
def pyperclip():
|
def pyperclip():
|
||||||
dst = dirname(dirname(__file__)) + "\\tools\\"
|
dst = dirname(dirname(__file__)) + "\\tools\\"
|
||||||
if os.access('N:/', os.R_OK):
|
if os.access('N:/', os.R_OK):
|
||||||
src = 'N:/SI_Systeme d information/Z_QGIS/PLUGIN/PythonSQL.py'
|
src = 'N:/SI_Systeme d information/Z_QGIS/PLUGIN/PythonSQL.py'
|
||||||
try:
|
try:
|
||||||
shutil.copy(src, dst)
|
shutil.copy(src, dst)
|
||||||
except:
|
except FileNotFoundError:
|
||||||
print('404')
|
print('404')
|
||||||
|
except UnboundLocalError:
|
||||||
|
print('404')
|
||||||
|
|
||||||
|
|
||||||
def send_issues(url, titre, body, labels):
|
def send_issues(url, titre, body, labels):
|
||||||
import requests
|
import requests
|
||||||
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
import os
|
# import os
|
||||||
import qgis
|
# import qgis
|
||||||
|
|
||||||
usr = os.environ['USERNAME']
|
# usr = os.environ['USERNAME']
|
||||||
token = '9d0a4e0bea561710e0728f161f7edf4e5201e112'
|
token = '9d0a4e0bea561710e0728f161f7edf4e5201e112'
|
||||||
url = url + '?token=' + token
|
url = url + '?token=' + token
|
||||||
|
|
||||||
headers = {'Authorization': 'token ' + token, 'accept': 'application/json', 'Content-Type': 'application/json'}
|
headers = {'Authorization': 'token ' + token, 'accept': 'application/json', 'Content-Type': 'application/json'}
|
||||||
|
|
||||||
|
|
||||||
payload = {'title': titre, 'body': body, 'labels': labels}
|
payload = {'title': titre, 'body': body, 'labels': labels}
|
||||||
try:
|
try:
|
||||||
urllib.request.urlopen('https://google.com')
|
urllib.request.urlopen('https://google.com')
|
||||||
binar = True
|
binar = True
|
||||||
except:
|
except ValueError:
|
||||||
binar = False
|
binar = False
|
||||||
r = ''
|
r = ''
|
||||||
if binar:
|
if binar:
|
||||||
r = requests.post(url, data=json.dumps(payload), headers=headers)
|
r = requests.post(url, data=json.dumps(payload), headers=headers)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def maj_verif(NAME):
|
def maj_verif(NAME):
|
||||||
import qgis
|
import qgis
|
||||||
import urllib.request
|
import urllib.request
|
||||||
iface = qgis.utils.iface
|
iface = qgis.utils.iface
|
||||||
from qgis.core import Qgis
|
from qgis.core import Qgis
|
||||||
|
|
||||||
url = qgis.utils.pluginMetadata(NAME,'repository')
|
# url = qgis.utils.pluginMetadata(NAME, 'repository')
|
||||||
# URL = url+'/raw/branch/main/plugins.xml'
|
# URL = url+'/raw/branch/main/plugins.xml'
|
||||||
URL = 'https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS/releases/download/latest/plugins.xml'
|
URL = 'https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS/releases/download/latest/plugins.xml'
|
||||||
# print(URL)
|
# print(URL)
|
||||||
@ -157,7 +162,7 @@ def maj_verif(NAME):
|
|||||||
try:
|
try:
|
||||||
urllib.request.urlopen('https://google.com')
|
urllib.request.urlopen('https://google.com')
|
||||||
binar = True
|
binar = True
|
||||||
except:
|
except urllib.error.URLError:
|
||||||
binar = False
|
binar = False
|
||||||
if binar:
|
if binar:
|
||||||
try:
|
try:
|
||||||
@ -167,20 +172,23 @@ def maj_verif(NAME):
|
|||||||
version_plugin = version_web[valeur_version_web:valeur_version_web + len_version]
|
version_plugin = version_web[valeur_version_web:valeur_version_web + len_version]
|
||||||
if version_plugin != version:
|
if version_plugin != version:
|
||||||
iface.messageBar().pushMessage("MAJ :", "Des mise à jour de plugin sont disponibles.", level=Qgis.Info, duration=30)
|
iface.messageBar().pushMessage("MAJ :", "Des mise à jour de plugin sont disponibles.", level=Qgis.Info, duration=30)
|
||||||
except:
|
except urllib.error.URLError:
|
||||||
print("error gitea version ssl")
|
print("error gitea version ssl")
|
||||||
else:
|
else:
|
||||||
iface.messageBar().pushMessage("WiFi :", "Pas de connection à internet.", level=Qgis.Warning, duration=30)
|
iface.messageBar().pushMessage("WiFi :", "Pas de connection à internet.", level=Qgis.Warning, duration=30)
|
||||||
|
|
||||||
|
|
||||||
def devlog(NAME):
|
def devlog(NAME):
|
||||||
import qgis
|
import qgis
|
||||||
devmaj = '<head><style>* {margin:0; padding:0; }</style></head>'
|
devmaj = '<head><style>* {margin:0; padding:0; }</style></head>'
|
||||||
devmaj = devmaj + qgis.utils.pluginMetadata(NAME, 'changelog')
|
devmaj = devmaj + qgis.utils.pluginMetadata(NAME, 'changelog')
|
||||||
return devmaj
|
return devmaj
|
||||||
|
|
||||||
|
|
||||||
def create_contour(self, schema, cur, con, host, port, dbname, user, mdp):
|
def create_contour(self, schema, cur, con, host, port, dbname, user, mdp):
|
||||||
### Creation de la table contour
|
# Creation de la table contour
|
||||||
if self.couche_contour.isChecked(): # Verifie si la checkbox est cochee
|
# Verifie si la checkbox est cochee
|
||||||
|
if self.couche_contour.isChecked():
|
||||||
if self.annee_1.text() == 'aaaa' or self.annee_1.text() == '':
|
if self.annee_1.text() == 'aaaa' or self.annee_1.text() == '':
|
||||||
tablename = schema + "_contour"
|
tablename = schema + "_contour"
|
||||||
else:
|
else:
|
||||||
@ -211,21 +219,24 @@ def create_contour(self,schema,cur,con,host ,port ,dbname ,user ,mdp):
|
|||||||
cur.execute(SQL_trigger_area_ha)
|
cur.execute(SQL_trigger_area_ha)
|
||||||
cur.execute(SQL_trigger_date_creation)
|
cur.execute(SQL_trigger_date_creation)
|
||||||
cur.execute(SQL_trigger_date_maj)
|
cur.execute(SQL_trigger_date_maj)
|
||||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
# Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||||
|
cur.execute(SQL_style)
|
||||||
cur.execute(SQL_GRANT_TABLE)
|
cur.execute(SQL_GRANT_TABLE)
|
||||||
|
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|
||||||
## Affichage de la table
|
# Affichage de la table
|
||||||
uri = QgsDataSourceUri()
|
uri = QgsDataSourceUri()
|
||||||
# set host name, port, database name, username and password
|
# set host name, port, database name, username and password
|
||||||
uri.setConnection(host, port, dbname, user, mdp)
|
uri.setConnection(host, port, dbname, user, mdp)
|
||||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||||
uri.setDataSource(schema, tablename, geom)
|
uri.setDataSource(schema, tablename, geom)
|
||||||
|
|
||||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||||
|
|
||||||
|
|
||||||
def create_travaux(self, schema, cur, con, host, port, dbname, user, mdp):
|
def create_travaux(self, schema, cur, con, host, port, dbname, user, mdp):
|
||||||
### Creation de la table travaux prevus
|
# Creation de la table travaux prevus
|
||||||
if self.couche_travaux_prevus.isChecked():
|
if self.couche_travaux_prevus.isChecked():
|
||||||
# **********Poly
|
# **********Poly
|
||||||
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
||||||
@ -241,7 +252,6 @@ def create_travaux(self,schema,cur,con,host,port,dbname,user,mdp):
|
|||||||
cur.execute(RETURNE)
|
cur.execute(RETURNE)
|
||||||
sequence_name = cur.fetchone()[0]
|
sequence_name = cur.fetchone()[0]
|
||||||
|
|
||||||
|
|
||||||
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename[len(schema):] + "_pkey" + " PRIMARY KEY (gid)"
|
SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename[len(schema):] + "_pkey" + " PRIMARY KEY (gid)"
|
||||||
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
|
||||||
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
|
||||||
@ -259,19 +269,20 @@ def create_travaux(self,schema,cur,con,host,port,dbname,user,mdp):
|
|||||||
cur.execute(SQL_trigger_date_maj)
|
cur.execute(SQL_trigger_date_maj)
|
||||||
cur.execute(SQL_trigger_area_m2)
|
cur.execute(SQL_trigger_area_m2)
|
||||||
cur.execute(SQL_trigger_area_ha)
|
cur.execute(SQL_trigger_area_ha)
|
||||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
# Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||||
|
cur.execute(SQL_style)
|
||||||
cur.execute(SQL_GRANT_TABLE)
|
cur.execute(SQL_GRANT_TABLE)
|
||||||
|
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|
||||||
## Affichage de la table
|
# Affichage de la table
|
||||||
uri = QgsDataSourceUri()
|
uri = QgsDataSourceUri()
|
||||||
# set host name, port, database name, username and password
|
# set host name, port, database name, username and password
|
||||||
uri.setConnection(host, port, dbname, user, mdp)
|
uri.setConnection(host, port, dbname, user, mdp)
|
||||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||||
uri.setDataSource(schema, tablename, geom)
|
uri.setDataSource(schema, tablename, geom)
|
||||||
|
|
||||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||||
|
|
||||||
# **********ligne
|
# **********ligne
|
||||||
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
||||||
@ -304,19 +315,20 @@ def create_travaux(self,schema,cur,con,host,port,dbname,user,mdp):
|
|||||||
cur.execute(SQL_trigger_date_maj)
|
cur.execute(SQL_trigger_date_maj)
|
||||||
cur.execute(SQL_trigger_length_m)
|
cur.execute(SQL_trigger_length_m)
|
||||||
cur.execute(SQL_trigger_length_km)
|
cur.execute(SQL_trigger_length_km)
|
||||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
# Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||||
|
cur.execute(SQL_style)
|
||||||
cur.execute(SQL_GRANT_TABLE)
|
cur.execute(SQL_GRANT_TABLE)
|
||||||
|
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|
||||||
## Affichage de la table
|
# Affichage de la table
|
||||||
uri = QgsDataSourceUri()
|
uri = QgsDataSourceUri()
|
||||||
# set host name, port, database name, username and password
|
# set host name, port, database name, username and password
|
||||||
uri.setConnection(host, port, dbname, user, mdp)
|
uri.setConnection(host, port, dbname, user, mdp)
|
||||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||||
uri.setDataSource(schema, tablename, geom)
|
uri.setDataSource(schema, tablename, geom)
|
||||||
|
|
||||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||||
|
|
||||||
# **********point
|
# **********point
|
||||||
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
if self.annee_5.text() == 'aaaa' or self.annee_5.text() == '':
|
||||||
@ -347,22 +359,24 @@ def create_travaux(self,schema,cur,con,host,port,dbname,user,mdp):
|
|||||||
cur.execute(SQL_trigger_date_creation)
|
cur.execute(SQL_trigger_date_creation)
|
||||||
cur.execute(SQL_trigger_date_maj)
|
cur.execute(SQL_trigger_date_maj)
|
||||||
cur.execute(SQL_trigger_coordonnees)
|
cur.execute(SQL_trigger_coordonnees)
|
||||||
cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
|
# Enregistrement du style (comme style par defaut) dans la table layer_styles
|
||||||
|
cur.execute(SQL_style)
|
||||||
cur.execute(SQL_GRANT_TABLE)
|
cur.execute(SQL_GRANT_TABLE)
|
||||||
|
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|
||||||
## Affichage de la table
|
# Affichage de la table
|
||||||
uri = QgsDataSourceUri()
|
uri = QgsDataSourceUri()
|
||||||
# set host name, port, database name, username and password
|
# set host name, port, database name, username and password
|
||||||
uri.setConnection(host, port, dbname, user, mdp)
|
uri.setConnection(host, port, dbname, user, mdp)
|
||||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||||
uri.setDataSource(schema, tablename, geom)
|
uri.setDataSource(schema, tablename, geom)
|
||||||
|
|
||||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||||
|
|
||||||
|
|
||||||
def create_habita(self, schema, cur, con, host, port, dbname, user, mdp):
|
def create_habita(self, schema, cur, con, host, port, dbname, user, mdp):
|
||||||
### Creation de la table habitat
|
# Creation de la table habitat
|
||||||
if self.couche_habitat.isChecked():
|
if self.couche_habitat.isChecked():
|
||||||
if self.annee_2.text() == 'aaaa' or self.annee_2.text() == '':
|
if self.annee_2.text() == 'aaaa' or self.annee_2.text() == '':
|
||||||
tablename = schema + "_habitat"
|
tablename = schema + "_habitat"
|
||||||
@ -395,14 +409,14 @@ def create_habita(self,schema,cur,con,host ,port ,dbname ,user ,mdp):
|
|||||||
cur.execute(SQL_GRANT_TABLE)
|
cur.execute(SQL_GRANT_TABLE)
|
||||||
|
|
||||||
con.commit()
|
con.commit()
|
||||||
### Affichage de la table
|
# Affichage de la table
|
||||||
uri = QgsDataSourceUri()
|
uri = QgsDataSourceUri()
|
||||||
# set host name, port, database name, username and password
|
# set host name, port, database name, username and password
|
||||||
uri.setConnection(host, port, dbname, user, mdp)
|
uri.setConnection(host, port, dbname, user, mdp)
|
||||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||||
uri.setDataSource(schema, tablename_1, geom)
|
uri.setDataSource(schema, tablename_1, geom)
|
||||||
|
|
||||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||||
|
|
||||||
tablename_2 = tablename + "_lignes"
|
tablename_2 = tablename + "_lignes"
|
||||||
RETURNE = "SELECT pg_get_serial_sequence('" + schema + "." + tablename_2 + "','gid')"
|
RETURNE = "SELECT pg_get_serial_sequence('" + schema + "." + tablename_2 + "','gid')"
|
||||||
@ -429,14 +443,14 @@ def create_habita(self,schema,cur,con,host ,port ,dbname ,user ,mdp):
|
|||||||
cur.execute(SQL_GRANT_TABLE)
|
cur.execute(SQL_GRANT_TABLE)
|
||||||
|
|
||||||
con.commit()
|
con.commit()
|
||||||
### Affichage de la table
|
# Affichage de la table
|
||||||
uri = QgsDataSourceUri()
|
uri = QgsDataSourceUri()
|
||||||
# set host name, port, database name, username and password
|
# set host name, port, database name, username and password
|
||||||
uri.setConnection(host, port, dbname, user, mdp)
|
uri.setConnection(host, port, dbname, user, mdp)
|
||||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||||
uri.setDataSource(schema, tablename_2, geom)
|
uri.setDataSource(schema, tablename_2, geom)
|
||||||
|
|
||||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||||
|
|
||||||
tablename_3 = tablename + "_polygones"
|
tablename_3 = tablename + "_polygones"
|
||||||
RETURNE = "SELECT pg_get_serial_sequence('" + schema + "." + tablename_3 + "','gid')"
|
RETURNE = "SELECT pg_get_serial_sequence('" + schema + "." + tablename_3 + "','gid')"
|
||||||
@ -463,16 +477,18 @@ def create_habita(self,schema,cur,con,host ,port ,dbname ,user ,mdp):
|
|||||||
cur.execute(SQL_GRANT_TABLE)
|
cur.execute(SQL_GRANT_TABLE)
|
||||||
|
|
||||||
con.commit()
|
con.commit()
|
||||||
### Affichage de la table
|
# Affichage de la table
|
||||||
uri = QgsDataSourceUri()
|
uri = QgsDataSourceUri()
|
||||||
# set host name, port, database name, username and password
|
# set host name, port, database name, username and password
|
||||||
uri.setConnection(host, port, dbname, user, mdp)
|
uri.setConnection(host, port, dbname, user, mdp)
|
||||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||||
uri.setDataSource(schema, tablename_3, geom)
|
uri.setDataSource(schema, tablename_3, geom)
|
||||||
|
|
||||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||||
|
|
||||||
|
|
||||||
def create_vierge(self, schema, cur, con, host, port, dbname, user, mdp):
|
def create_vierge(self, schema, cur, con, host, port, dbname, user, mdp):
|
||||||
### Creation de la table vierge
|
# Creation de la table vierge
|
||||||
if self.couche_vierge.isChecked():
|
if self.couche_vierge.isChecked():
|
||||||
if self.annee_4.text() == 'aaaa' or self.annee_4.text() == '':
|
if self.annee_4.text() == 'aaaa' or self.annee_4.text() == '':
|
||||||
tablename = schema + "_" + self.nom_couche_vierge.text().lower()
|
tablename = schema + "_" + self.nom_couche_vierge.text().lower()
|
||||||
@ -521,11 +537,11 @@ def create_vierge(self,schema,cur,con,host ,port ,dbname ,user ,mdp):
|
|||||||
|
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|
||||||
### Affichage de la table
|
# Affichage de la table
|
||||||
uri = QgsDataSourceUri()
|
uri = QgsDataSourceUri()
|
||||||
# set host name, port, database name, username and password
|
# set host name, port, database name, username and password
|
||||||
uri.setConnection(host, port, dbname, user, mdp)
|
uri.setConnection(host, port, dbname, user, mdp)
|
||||||
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
# set database schema, table name, geometry column and optionaly subset (WHERE clause)
|
||||||
uri.setDataSource(schema, tablename, geom)
|
uri.setDataSource(schema, tablename, geom)
|
||||||
|
|
||||||
layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user