Skip to content

Commit

Permalink
Merge pull request #414 from Gustry/python-3-6
Browse files Browse the repository at this point in the history
Raise QGIS min to 3.18 and Python 3.6
  • Loading branch information
Gustry authored Aug 22, 2023
2 parents b99e1a9 + c9e2b78 commit 992586d
Show file tree
Hide file tree
Showing 33 changed files with 263 additions and 277 deletions.
1 change: 0 additions & 1 deletion cadastre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
***************************************************************************/
This script initializes the plugin, making it known to QGIS.
"""
from __future__ import absolute_import


def classFactory(iface):
Expand Down
20 changes: 8 additions & 12 deletions cadastre/cadastre_common_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def fetchDataFromSqlQuery(connector: 'DBConnector',
except BaseError as e:
ok = False
QgsMessageLog.logMessage(
"Error while fetching data from database : {}".format(str(e.msg)),
f"Error while fetching data from database : {str(e.msg)}",
"cadastre",
Qgis.Critical
)
Expand Down Expand Up @@ -213,16 +213,12 @@ def getConnectorFromUri(connectionParams: Dict[str, str]) -> 'DBConnector':
connectionParams['password']
)

if Qgis.QGIS_VERSION_INT >= 31200:
# we need a fake DBPlugin object
# with connectionName and providerName methods
obj = QObject()
obj.connectionName = lambda: 'fake'
obj.providerName = lambda: 'postgres'

connector = PostGisDBConnector(uri, obj)
else:
connector = PostGisDBConnector(uri)
# we need a fake DBPlugin object
# with connectionName and providerName methods
obj = QObject()
obj.connectionName = lambda: 'fake'
obj.providerName = lambda: 'postgres'
connector = PostGisDBConnector(uri, obj)

if connectionParams['dbType'] == 'spatialite':
uri.setConnection('', '', connectionParams['dbname'], '', '')
Expand All @@ -236,7 +232,7 @@ def getConnectorFromUri(connectionParams: Dict[str, str]) -> 'DBConnector':
connector = SpatiaLiteDBConnector(uri)
except ConnectionError as e:
QgsMessageLog.logMessage(
"Erreur lors de la récupération du fichier SQLite : {}".format(str(e)),
f"Erreur lors de la récupération du fichier SQLite : {str(e)}",
'cadastre',
Qgis.Critical)

Expand Down
52 changes: 26 additions & 26 deletions cadastre/cadastre_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ def __init__(self, project: QgsProject, layer: QgsMapLayer, etype: str, compteco

# label for header2
if self.etype == 'proprietaire':
self.typeLabel = u'DE PROPRIÉTÉ'
self.typeLabel = 'DE PROPRIÉTÉ'
else:
self.typeLabel = u'PARCELLAIRE'
self.typeLabel = 'PARCELLAIRE'

self.layer = layer
self.connectionParams = cadastre_common.getConnectionParameterFromDbLayer(self.layer)
Expand Down Expand Up @@ -157,8 +157,8 @@ def set_composer_templates(self, compte_communal):
'type': 'sql',
'filter': 'comptecommunal',
'and': {
'proprietaire': " AND comptecommunal = '{}'".format(compte_communal),
'parcelle': " AND comptecommunal = '{}'".format(compte_communal),
'proprietaire': f" AND comptecommunal = '{compte_communal}'",
'parcelle': f" AND comptecommunal = '{compte_communal}'",
},
'sticky': True
},
Expand Down Expand Up @@ -200,8 +200,8 @@ def set_composer_templates(self, compte_communal):
'keepContent': True,
'filter': 'comptecommunal',
'and': {
'proprietaire': " AND l10.comptecommunal = '{}'".format(compte_communal),
'parcelle': " AND p.parcelle = '{}'".format(self.geo_parcelle)
'proprietaire': f" AND l10.comptecommunal = '{compte_communal}'",
'parcelle': f" AND p.parcelle = '{self.geo_parcelle}'"
}
},
'proprietes_non_baties': {
Expand All @@ -218,8 +218,8 @@ def set_composer_templates(self, compte_communal):
'keepContent': True,
'filter': 'comptecommunal',
'and': {
'proprietaire': " AND p.comptecommunal = '{}'".format(compte_communal),
'parcelle': " AND p.parcelle = '{}'".format(self.geo_parcelle)
'proprietaire': f" AND p.comptecommunal = '{compte_communal}'",
'parcelle': f" AND p.parcelle = '{self.geo_parcelle}'"
},
'bgcolor': Qt.transparent
},
Expand All @@ -242,8 +242,8 @@ def set_composer_templates(self, compte_communal):
'keepContent': True,
'filter': 'comptecommunal',
'and': {
'proprietaire': " AND comptecommunal = '{}'".format(compte_communal),
'parcelle': " AND comptecommunal = '{}'".format(compte_communal)
'proprietaire': f" AND comptecommunal = '{compte_communal}'",
'parcelle': f" AND comptecommunal = '{compte_communal}'"
}
},
'proprietes_baties_line': {
Expand All @@ -253,8 +253,8 @@ def set_composer_templates(self, compte_communal):
'type': 'sql',
'filter': 'comptecommunal',
'and': {
'proprietaire': " AND l10.comptecommunal = '{}'".format(compte_communal),
'parcelle': " AND p.parcelle = '{}'".format(self.geo_parcelle)
'proprietaire': f" AND l10.comptecommunal = '{compte_communal}'",
'parcelle': f" AND p.parcelle = '{self.geo_parcelle}'"
}
},
'proprietes_non_baties_line': {
Expand All @@ -263,8 +263,8 @@ def set_composer_templates(self, compte_communal):
'revenucadastral', 'coll', 'natexo', 'anret', 'fractionrcexo', 'pourcentageexo', 'tc', 'lff'],
'type': 'sql',
'and': {
'proprietaire': " AND p.comptecommunal = '{}'".format(compte_communal),
'parcelle': " AND p.parcelle = '{}'".format(self.geo_parcelle)
'proprietaire': f" AND p.comptecommunal = '{compte_communal}'",
'parcelle': f" AND p.parcelle = '{self.geo_parcelle}'"
}
}

Expand Down Expand Up @@ -314,7 +314,7 @@ def getContentForGivenItem(self, key, item, page=None):
# Load SQL query and get data
# Get sql file
sqlFile = tplPath + '.sql'
fin = open(sqlFile, 'rt', encoding='utf8')
fin = open(sqlFile, encoding='utf8')
sql = fin.read()
fin.close()

Expand Down Expand Up @@ -362,7 +362,7 @@ def getContentForGivenItem(self, key, item, page=None):
for line in data:
replaceDict = {}
for i in range(len(item['names'])):
replaceDict['$%s' % item['names'][i]] = u'%s' % line[i]
replaceDict['$%s' % item['names'][i]] = '%s' % line[i]
content += self.getHtmlFromTemplate(tplPath, replaceDict)

# fill empty data to have full size table
Expand All @@ -371,7 +371,7 @@ def getContentForGivenItem(self, key, item, page=None):
for _ in range(self.maxLineNumber - len(data)):
replaceDict = {}
for i in range(len(item['names'])):
replaceDict['$%s' % item['names'][i]] = u' '
replaceDict['$%s' % item['names'][i]] = ' '
content += self.getHtmlFromTemplate(tplPath, replaceDict)

elif item['type'] == 'properties':
Expand Down Expand Up @@ -407,13 +407,13 @@ def replfunc(match):
regex = re.compile('|'.join(re.escape(x) for x in replaceDict))

try:
with open(tplPath, 'rt', encoding='utf8') as fin:
with open(tplPath, encoding='utf8') as fin:
data = fin.read()
data = regex.sub(replfunc, data)
return data

except IOError as e:
msg = u"Erreur lors de l'export: %s" % e
except OSError as e:
msg = "Erreur lors de l'export: %s" % e
self.go = False
# fix_print_with_import
print("%s" % msg)
Expand Down Expand Up @@ -559,10 +559,10 @@ def addParcelleMap(self):
vl.commitChanges()
vl.updateExtents()
props = vl.renderer().symbol().symbolLayer(0).properties()
props['outline_width'] = u'1'
props['outline_color'] = u'0,85,255,255'
props['outline_style'] = u'solid'
props['style'] = u'no'
props['outline_width'] = '1'
props['outline_color'] = '0,85,255,255'
props['outline_style'] = 'solid'
props['style'] = 'no'
vl.renderer().setSymbol(QgsFillSymbol.createSimple(props))
self.mProject.addMapLayer(vl)
self.redlineLayer = vl
Expand Down Expand Up @@ -610,7 +610,7 @@ def exportItemAsPdf(self, comptecommunal, suffix=None) -> str:

# Create the pdf output path
from time import time
temp = "releve_%s_%s_%s.pdf" % (
temp = "releve_{}_{}_{}.pdf".format(
self.etype,
comptecommunal.replace('+', 'plus').replace('*', 'fois'), # .replace('¤', 'plus'),
int(time() * 100)
Expand All @@ -622,7 +622,7 @@ def exportItemAsPdf(self, comptecommunal, suffix=None) -> str:
# print temp
temppath = os.path.join(self.targetDir, temp)
temppath = os.path.normpath(temppath)
QgsMessageLog.logMessage('Export PDF vers {}'.format(temppath), 'cadastre', Qgis.Info)
QgsMessageLog.logMessage(f'Export PDF vers {temppath}', 'cadastre', Qgis.Info)
# print("export temppath %s" % temppath)

# Export as pdf
Expand Down
1 change: 0 additions & 1 deletion cadastre/cadastre_identify_parcelle.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* *
***************************************************************************/
"""
from __future__ import absolute_import

from qgis.core import (
QgsFeature,
Expand Down
Loading

0 comments on commit 992586d

Please sign in to comment.