|
|
@@ -17,10 +17,9 @@ import sys
|
|
|
from path import Path
|
|
|
import shapefile
|
|
|
|
|
|
-from core import logconf, select_list_dialog
|
|
|
+from core import logconf
|
|
|
from core.pde import ControlesDb, CSigDb, COMPACTAGE_DIR, QGisChantier, \
|
|
|
QGisPoint, SRID
|
|
|
-from core.sqlformatter import SqlFormatter
|
|
|
|
|
|
|
|
|
logger = logging.getLogger("qgis_sync_compactage")
|
|
|
@@ -29,18 +28,17 @@ logconf.start("qgis_sync_compactage", logging.DEBUG)
|
|
|
# # POUR TESTER, décommenter les lignes suivantes
|
|
|
##-----------------------------------------------
|
|
|
|
|
|
-# ControlesDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\cg67Parc_data.mdb")
|
|
|
-# CSigDb.server = "TR-POSTGIS-02"
|
|
|
-# CSigDb.pwd = "Am5VOMkdFHU7WwrfVOs9"
|
|
|
-# COMPACTAGE_DIR = Path(__file__).parent / "resources" / "test_qgis_sync_compactage"
|
|
|
-# logger.handlers = [h for h in logger.handlers if (type(h) == logging.StreamHandler)]
|
|
|
-# logger.warning("<<<<<<<<<<<<<< Mode TEST >>>>>>>>>>>>>>>>>")
|
|
|
+ControlesDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\cg67Parc_data.mdb")
|
|
|
+CSigDb.server = "TR-POSTGIS-02"
|
|
|
+CSigDb.pwd = "Am5VOMkdFHU7WwrfVOs9"
|
|
|
+COMPACTAGE_DIR = Path(__file__).parent / "resources" / "test_qgis_sync_compactage"
|
|
|
+logger.handlers = [h for h in logger.handlers if (type(h) == logging.StreamHandler)]
|
|
|
+logger.warning("<<<<<<<<<<<<<< Mode TEST >>>>>>>>>>>>>>>>>")
|
|
|
|
|
|
##-----------------------------------------------
|
|
|
|
|
|
-def main():
|
|
|
|
|
|
- Sql = SqlFormatter()
|
|
|
+def main():
|
|
|
|
|
|
# Connexion à ControlesSig (postgres)
|
|
|
csig_db = CSigDb(autocommit=False)
|
|
|
@@ -54,7 +52,16 @@ def main():
|
|
|
a_importer = [subdir for subdir in COMPACTAGE_DIR.dirs() if rxi.search(subdir.name)]
|
|
|
|
|
|
if a_importer:
|
|
|
- a_importer = select_list_dialog.exec_(a_importer, lambda x: x.name, "Sélectionnez les chantiers à importer")
|
|
|
+ reponse = input("""Les chantiers suivants peuvent être importés.
|
|
|
+Tapez les numéros correpsondant aux chantiers à importer, séparés par une virgule (ou * pour tout importer)
|
|
|
+Ex: "1", "1,2,5", "*"
|
|
|
+{}""".format("\n".join(["{} - {}".format(i, item.name) for i, item in enumerate(a_importer)])))
|
|
|
+ if reponse != "*":
|
|
|
+ a_importer = [item for i, item in enumerate(a_importer) if str(i) in reponse.split(",")]
|
|
|
+
|
|
|
+# if a_importer:
|
|
|
+# from core import select_list_dialog
|
|
|
+# a_importer = select_list_dialog.exec_(a_importer, lambda x: x.name, "Sélectionnez les chantiers à importer")
|
|
|
|
|
|
if not a_importer:
|
|
|
logger.info("Aucun nouveau dossier à importer")
|
|
|
@@ -64,7 +71,7 @@ def main():
|
|
|
|
|
|
# ** Read the data in the shapefiles and store it in memory **
|
|
|
for chantier_dir_path in a_importer:
|
|
|
- logger.info("** %s", chantier_dir_path)
|
|
|
+ logger.info("Lecture de : %s", chantier_dir_path)
|
|
|
|
|
|
# instanciate a new Chantier
|
|
|
chantier = QGisChantier()
|
|
|
@@ -133,6 +140,8 @@ def main():
|
|
|
|
|
|
# Contrôle si un chantier de compactage portant ce nom n'existe pas déjà dans la base
|
|
|
qry = csig_db.read(u"SELECT id FROM t_chantiers WHERE nom = '{}' AND id_type_chantier=2;".format(chantier.name))
|
|
|
+ cancelled = False
|
|
|
+
|
|
|
for row in qry:
|
|
|
logger.warning("Un chantier de compactage portant ce nom existe déjà '{}' (id {})".format(chantier.name, row.id))
|
|
|
if input("Voulez-vous le remplacer? (o/n)") == "o":
|
|
|
@@ -143,8 +152,12 @@ def main():
|
|
|
WHERE id = {};""".format(row.id))
|
|
|
logger.info("> L'ancien chantier a été supprimé".format(chantier.name, row.id))
|
|
|
else:
|
|
|
- logger.warning("Import du chantier annulé")
|
|
|
- continue
|
|
|
+ cancelled = True
|
|
|
+ break
|
|
|
+
|
|
|
+ if cancelled:
|
|
|
+ logger.warning("Import du chantier annulé")
|
|
|
+ continue
|
|
|
|
|
|
# Créé le chantier
|
|
|
q = csig_db.first("""INSERT INTO t_chantiers(id_type_chantier, numero, nom, geom, archive)
|