Template
forked from CEN-RA/Plugin_QGIS
premier commit/push
This commit is contained in:
+34
-1
@@ -1 +1,34 @@
|
||||
# CenRa_POSTGIS
|
||||
Plugin Builder Results
|
||||
|
||||
Your plugin CenRa was created in:
|
||||
C:\Users\gcostes\.qgis2\python\plugins\CenRa
|
||||
|
||||
Your QGIS plugin directory is located at:
|
||||
C:/Users/gcostes/.qgis2/python/plugins
|
||||
|
||||
What's Next:
|
||||
|
||||
* Copy the entire directory containing your new plugin to the QGIS plugin
|
||||
directory
|
||||
|
||||
* Compile the ui file using pyuic4
|
||||
|
||||
* Compile the resources file using pyrcc4
|
||||
|
||||
* Test the plugin by enabling it in the QGIS plugin manager
|
||||
|
||||
* Customize it by editing the implementation file:
|
||||
cenra.py
|
||||
|
||||
* Create your own custom icon, replacing the default icon.png
|
||||
|
||||
* Modify your user interface by opening cenra.ui
|
||||
in Qt Designer (don't forget to compile it with pyuic4 after changing it)
|
||||
|
||||
* You can use the Makefile to compile your Ui and resource files when
|
||||
you make changes. This requires GNU make (gmake)
|
||||
|
||||
For more information, see the PyQGIS Developer Cookbook at:
|
||||
http://www.qgis.org/pyqgis-cookbook/index.html
|
||||
|
||||
(C) 2011-2014 GeoApt LLC - geoapt.com
|
||||
|
||||
@@ -24,6 +24,7 @@ from __future__ import absolute_import
|
||||
from builtins import next
|
||||
from builtins import str
|
||||
from builtins import object
|
||||
import qgis
|
||||
from qgis.PyQt.QtCore import QSettings
|
||||
from qgis.PyQt.QtWidgets import QAction, QMenu, QDialog
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
@@ -31,6 +32,7 @@ from PyQt5.QtCore import *
|
||||
from PyQt5.QtGui import *
|
||||
from qgis.core import *
|
||||
from qgis.core import QgsDataSourceUri
|
||||
from .forms.about_form import PostgisAboutDialog
|
||||
# Initialize Qt resources from file resources.py
|
||||
from . import resources_rc
|
||||
# Import the code for the dialog
|
||||
@@ -67,6 +69,15 @@ class CenRa(object):
|
||||
self.dlg = CenRaDialog()
|
||||
self.dlgAjout = table_postgisDialog()
|
||||
maj_verif('CenRa_POSTGIS')
|
||||
|
||||
version = qgis.utils.pluginMetadata('CenRa_POSTGIS','version')
|
||||
# Display About window on first use
|
||||
s = QSettings()
|
||||
versionUse = s.value("postgis/version", 1, type=str)
|
||||
if str(versionUse) != str(version) :
|
||||
s.setValue("postgis/version", str(version))
|
||||
self.open_about_dialog()
|
||||
|
||||
def initGui(self):
|
||||
self.toolBar = self.iface.addToolBar("CEN-RA")
|
||||
self.toolBar.setObjectName("CEN-RA")
|
||||
@@ -122,6 +133,10 @@ class CenRa(object):
|
||||
self.cenra_ajout.triggered.connect(self.ajout)
|
||||
self.cenra_help.triggered.connect(self.doHelp)
|
||||
|
||||
def open_about_dialog(self):
|
||||
dialog = PostgisAboutDialog(self.iface)
|
||||
dialog.exec_()
|
||||
|
||||
def unload(self):
|
||||
# Remove the plugin menu item and icon
|
||||
self.iface.removePluginMenu(u"&CENRA", self.action)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
name=CenRa_POSTGIS
|
||||
qgisMinimumVersion=3.0
|
||||
description=Permet de crée un dossier dans la base PostGis
|
||||
version=1.6
|
||||
version=1.8
|
||||
author=Conservatoire d'Espaces Naturels de Rhône-Alpes
|
||||
email=si_besoin@cen-rhonealpes.fr
|
||||
|
||||
@@ -21,7 +21,7 @@ email=si_besoin@cen-rhonealpes.fr
|
||||
# Optional items:
|
||||
|
||||
# Uncomment the following line and add your changelog entries:
|
||||
changelog=Traduction en Qgis v3.x
|
||||
changelog=<h2>CenRa_POSTGIS:</h2></br><p><h3>13/09/2024 - Version 1.8:</h3>- Ajoute d'un changelog et vérification de mise à jour.</p>
|
||||
|
||||
# tags are comma separated with spaces allowed
|
||||
tags=cenra, postgis, database
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
"""Tools to work with resource files."""
|
||||
|
||||
import configparser
|
||||
import shutil
|
||||
import tempfile
|
||||
import base64
|
||||
import psycopg2
|
||||
import psycopg2.extras
|
||||
from os.path import abspath, join, pardir, dirname
|
||||
|
||||
from qgis.PyQt import uic
|
||||
|
||||
__copyright__ = "Copyright 2019, 3Liz"
|
||||
__license__ = "GPL version 3"
|
||||
__email__ = "info@3liz.org"
|
||||
__revision__ = "$Format:%H$"
|
||||
|
||||
|
||||
def plugin_path(*args):
|
||||
"""Get the path to plugin root folder.
|
||||
|
||||
:param args List of path elements e.g. ['img', 'logos', 'image.png']
|
||||
:type args: str
|
||||
|
||||
:return: Absolute path to the plugin path.
|
||||
:rtype: str
|
||||
"""
|
||||
path = dirname(dirname(__file__))
|
||||
path = abspath(abspath(join(path, pardir)))
|
||||
for item in args:
|
||||
path = abspath(join(path, item))
|
||||
|
||||
return path
|
||||
|
||||
|
||||
def plugin_name():
|
||||
"""Return the plugin name according to metadata.txt.
|
||||
|
||||
:return: The plugin name.
|
||||
:rtype: basestring
|
||||
"""
|
||||
metadata = metadata_config()
|
||||
name = metadata["general"]["name"]
|
||||
return name
|
||||
|
||||
|
||||
def metadata_config() -> configparser:
|
||||
"""Get the INI config parser for the metadata file.
|
||||
|
||||
:return: The config parser object.
|
||||
:rtype: ConfigParser
|
||||
"""
|
||||
path = plugin_path("metadata.txt")
|
||||
config = configparser.ConfigParser()
|
||||
config.read(path, encoding='utf8')
|
||||
return config
|
||||
|
||||
|
||||
def plugin_test_data_path(*args, copy=False):
|
||||
"""Get the path to the plugin test data path.
|
||||
|
||||
:param args List of path elements e.g. ['img', 'logos', 'image.png']
|
||||
:type args: str
|
||||
|
||||
:param copy: If the file must be copied into a temporary directory first.
|
||||
:type copy: bool
|
||||
|
||||
:return: Absolute path to the resources folder.
|
||||
:rtype: str
|
||||
"""
|
||||
path = abspath(abspath(join(plugin_path(), "test", "data")))
|
||||
for item in args:
|
||||
path = abspath(join(path, item))
|
||||
|
||||
if copy:
|
||||
temp = tempfile.mkdtemp()
|
||||
shutil.copy(path, temp)
|
||||
return join(temp, args[-1])
|
||||
else:
|
||||
return path
|
||||
|
||||
|
||||
def resources_path(*args):
|
||||
"""Get the path to our resources folder.
|
||||
|
||||
:param args List of path elements e.g. ['img', 'logos', 'image.png']
|
||||
:type args: str
|
||||
|
||||
:return: Absolute path to the resources folder.
|
||||
:rtype: str
|
||||
"""
|
||||
path = abspath(abspath(join(plugin_path(), "CenRa_Metabase\\resources")))
|
||||
for item in args:
|
||||
path = abspath(join(path, item))
|
||||
return path
|
||||
|
||||
|
||||
def load_ui(*args):
|
||||
"""Get compile UI file.
|
||||
|
||||
:param args List of path elements e.g. ['img', 'logos', 'image.png']
|
||||
:type args: str
|
||||
|
||||
:return: Compiled UI file.
|
||||
"""
|
||||
ui_class, _ = uic.loadUiType(resources_path("ui", *args))
|
||||
|
||||
return ui_class
|
||||
|
||||
def login_base(take=None):
|
||||
from CenRa_Metabase.resources.PythonSQL import host,port,dbname,password,os_user
|
||||
first_conn = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=first_cnx password=" + password)
|
||||
first_cur = first_conn.cursor(cursor_factory = psycopg2.extras.DictCursor)
|
||||
first_cur.execute("SELECT mdp_w, login_w FROM pg_catalog.pg_user t1, admin_sig.vm_users_sig t2 WHERE t2.oid = t1.usesysid AND (login_w = '" + os_user + "' OR login_w = '" + os_user + "')")
|
||||
res_ident = first_cur.fetchone()
|
||||
mdp = base64.b64decode(str(res_ident[0])).decode('utf-8')
|
||||
user = res_ident[1]
|
||||
|
||||
con = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=" + user + " password=" + mdp)
|
||||
cur = con.cursor(cursor_factory = psycopg2.extras.DictCursor)
|
||||
first_conn.close()
|
||||
|
||||
if take:
|
||||
return cur,con
|
||||
else:
|
||||
return cur
|
||||
def send_issues(url,titre,body,labels):
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
import qgis
|
||||
|
||||
usr = os.environ['USERNAME']
|
||||
token = '9d0a4e0bea561710e0728f161f7edf4e5201e112'
|
||||
url=url+'?token='+token
|
||||
|
||||
headers = {'Authorization': 'token ' + token,'accept': 'application/json','Content-Type': 'application/json'}
|
||||
|
||||
|
||||
payload = {'title': titre, 'body': body, 'labels': labels}
|
||||
|
||||
r = requests.post(url, data=json.dumps(payload), headers=headers)
|
||||
print(r.text)
|
||||
return r
|
||||
|
||||
def maj_verif(NAME):
|
||||
import qgis
|
||||
import urllib
|
||||
|
||||
url = qgis.utils.pluginMetadata(NAME,'repository')
|
||||
URL = url+'/raw/branch/main/plugins.xml'
|
||||
# print(URL)
|
||||
version = qgis.utils.pluginMetadata(NAME,'version')
|
||||
len_version = len(version)
|
||||
version_web = str(urllib.request.urlopen(URL).read())
|
||||
plugin_num = version_web.find(NAME)
|
||||
valeur_version_web = version_web.find('<version>',plugin_num)+9
|
||||
version_plugin = version_web[valeur_version_web:valeur_version_web+len_version]
|
||||
|
||||
if version_plugin == version:
|
||||
iface.messageBar().pushMessage("MAJ :", "Des mise à jour de plugin sont disponibles.", level=Qgis.Info, duration=30)
|
||||
@@ -116,8 +116,8 @@ def login_base(take=None):
|
||||
mdp = base64.b64decode(str(res_ident[0])).decode('utf-8')
|
||||
user = res_ident[1]
|
||||
|
||||
#con = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=" + user + " password=" + mdp)
|
||||
con = psycopg2.connect("host=" + '100.100.100.81' + " port=" + port + " dbname="+'postgres'+" user=" + 'tlaveille' + " password=" + 'tlaveille')
|
||||
con = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=" + user + " password=" + mdp)
|
||||
|
||||
cur = con.cursor(cursor_factory = psycopg2.extras.DictCursor)
|
||||
first_conn.close()
|
||||
|
||||
@@ -139,26 +139,45 @@ def send_issues(url,titre,body,labels):
|
||||
|
||||
|
||||
payload = {'title': titre, 'body': body, 'labels': labels}
|
||||
|
||||
r = requests.post(url, data=json.dumps(payload), headers=headers)
|
||||
print(r.text)
|
||||
try:
|
||||
urllib.request.urlopen('https://google.com')
|
||||
binar = True
|
||||
except:
|
||||
binar = False
|
||||
r = ''
|
||||
if binar:
|
||||
r = requests.post(url, data=json.dumps(payload), headers=headers)
|
||||
return r
|
||||
|
||||
def maj_verif(NAME):
|
||||
import qgis
|
||||
import urllib
|
||||
from qgis.utils import iface
|
||||
import urllib.request
|
||||
iface = qgis.utils.iface
|
||||
from qgis.core import Qgis
|
||||
|
||||
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/releases/plugins.xml'
|
||||
# print(URL)
|
||||
version = qgis.utils.pluginMetadata(NAME,'version')
|
||||
len_version = len(version)
|
||||
version_web = str(urllib.request.urlopen(URL).read())
|
||||
plugin_num = version_web.find(NAME)
|
||||
valeur_version_web = version_web.find('<version>',plugin_num)+9
|
||||
version_plugin = version_web[valeur_version_web:valeur_version_web+len_version]
|
||||
try:
|
||||
urllib.request.urlopen('https://google.com')
|
||||
binar = True
|
||||
except:
|
||||
binar = False
|
||||
if binar:
|
||||
version_web = str(urllib.request.urlopen(URL).read())
|
||||
plugin_num = version_web.find(NAME)
|
||||
valeur_version_web = version_web.find('<version>',plugin_num)+9
|
||||
version_plugin = version_web[valeur_version_web:valeur_version_web+len_version]
|
||||
if version_plugin != version:
|
||||
iface.messageBar().pushMessage("MAJ :", "Des mise à jour de plugin sont disponibles.", level=Qgis.Info, duration=30)
|
||||
else:
|
||||
iface.messageBar().pushMessage("WiFi :", "Pas de connection à internet.", level=Qgis.Warning, duration=30)
|
||||
|
||||
if version_plugin == version:
|
||||
qgis.utils.iface.messageBar().pushMessage("MAJ :", "Des mise à jour de plugin sont disponibles.", level=Qgis.Info, duration=30)
|
||||
def devlog(NAME):
|
||||
import qgis
|
||||
devmaj = '<head><style>* {margin:0; padding:0; }</style></head>'
|
||||
devmaj = devmaj+qgis.utils.pluginMetadata(NAME,'changelog')
|
||||
return devmaj
|
||||
|
||||
Reference in New Issue
Block a user