From c809c12c9fc37b3ae8509e8a77c80e01959e4d54 Mon Sep 17 00:00:00 2001 From: Tom LAVEILLE Date: Wed, 9 Apr 2025 11:44:05 +0200 Subject: [PATCH] Optimisation pour TT --- CenRa_AUTOMAP/tools/resources.py | 13 ++++--------- CenRa_COPIE/CenRa_Copie.py | 6 +----- CenRa_COPIE/tools/resources.py | 13 ++++--------- CenRa_FLUX/CenRa_Flux.py | 7 +------ CenRa_FLUX/tools/resources.py | 13 ++++--------- CenRa_METABASE/tools/resources.py | 13 ++++--------- CenRa_POSTGIS/CenRa_Postgis.py | 18 +++--------------- CenRa_POSTGIS/tools/resources.py | 13 ++++--------- CenRa_SICEN/sicen.py | 7 +------ CenRa_SICEN/tools/resources.py | 13 ++++--------- 10 files changed, 30 insertions(+), 86 deletions(-) diff --git a/CenRa_AUTOMAP/tools/resources.py b/CenRa_AUTOMAP/tools/resources.py index 208cc6d..c7c1885 100644 --- a/CenRa_AUTOMAP/tools/resources.py +++ b/CenRa_AUTOMAP/tools/resources.py @@ -4,7 +4,7 @@ import configparser import shutil import tempfile import base64 -import socket +import os import psycopg2 import psycopg2.extras from os.path import abspath, join, pardir, dirname @@ -109,14 +109,9 @@ def load_ui(*args): return ui_class def pyperclip(): - IPAddr=socket.gethostbyname(socket.gethostname()) - dst = abspath(abspath(join(plugin_path(), "CenRa_AUTOMAP\\tools\\"))) - if IPAddr[0:11] == "100.100.100": #4269 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\StyleLayer.py' - if IPAddr[0:9] == "192.168.0": #01 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\StyleLayer.py' - if IPAddr[0:9] == "192.168.1": #0726 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\StyleLayer.py' + dst = dirname(dirname(__file__))+"\\tools\\" + if os.access('N:/',os.R_OK): + src = 'N:/SI_Systeme d information/Z_QGIS/PLUGIN/StyleLayer.py' try: shutil.copy(src, dst) except: diff --git a/CenRa_COPIE/CenRa_Copie.py b/CenRa_COPIE/CenRa_Copie.py index 8fc8549..7589e16 100644 --- a/CenRa_COPIE/CenRa_Copie.py +++ b/CenRa_COPIE/CenRa_Copie.py @@ -70,11 +70,7 @@ class PgCopie: self.copie_editor.triggered.connect(self.open_editor) self.copie_editor.setEnabled(False) IPAddr=socket.gethostbyname(socket.gethostname()) - if IPAddr[0:11] == "100.100.100": - self.copie_editor.setEnabled(True) - elif IPAddr[0:9] == "192.168.0": - self.copie_editor.setEnabled(True) - elif IPAddr[0:9] == "192.168.1": + if os.access('N:/',os.R_OK): self.copie_editor.setEnabled(True) def open_about_dialog(self): diff --git a/CenRa_COPIE/tools/resources.py b/CenRa_COPIE/tools/resources.py index ded5a0a..019ab96 100644 --- a/CenRa_COPIE/tools/resources.py +++ b/CenRa_COPIE/tools/resources.py @@ -6,7 +6,7 @@ import tempfile import base64 import psycopg2 import psycopg2.extras -import socket +import os from os.path import abspath, join, pardir, dirname from qgis.PyQt import uic @@ -109,14 +109,9 @@ def load_ui(*args): return ui_class def pyperclip(): - IPAddr=socket.gethostbyname(socket.gethostname()) - dst = abspath(abspath(join(plugin_path(), "CenRa_COPIE\\tools\\"))) - if IPAddr[0:11] == "100.100.100": #4269 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' - if IPAddr[0:9] == "192.168.0": #01 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' - if IPAddr[0:9] == "192.168.1": #0726 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' + dst = dirname(dirname(__file__))+"\\tools\\" + if os.access('N:/',os.R_OK): + src = 'N:/SI_Systeme d information/Z_QGIS/PLUGIN/PythonSQL.py' try: shutil.copy(src, dst) except: diff --git a/CenRa_FLUX/CenRa_Flux.py b/CenRa_FLUX/CenRa_Flux.py index cc21d09..673b053 100644 --- a/CenRa_FLUX/CenRa_Flux.py +++ b/CenRa_FLUX/CenRa_Flux.py @@ -70,12 +70,7 @@ class PgFlux: self.toolBar.addAction(self.flux_editor) self.flux_editor.triggered.connect(self.open_editor) self.flux_editor.setEnabled(False) - IPAddr=socket.gethostbyname(socket.gethostname()) - if IPAddr[0:11] == "100.100.100": - self.flux_editor.setEnabled(True) - elif IPAddr[0:9] == "192.168.0": - self.flux_editor.setEnabled(True) - elif IPAddr[0:9] == "192.168.1": + if os.access('N:/',os.R_OK): self.flux_editor.setEnabled(True) def open_about_dialog(self): diff --git a/CenRa_FLUX/tools/resources.py b/CenRa_FLUX/tools/resources.py index bf3342f..b7d3549 100644 --- a/CenRa_FLUX/tools/resources.py +++ b/CenRa_FLUX/tools/resources.py @@ -2,7 +2,7 @@ import configparser import shutil -import socket +import os import tempfile from os.path import abspath, join, pardir, dirname @@ -78,14 +78,9 @@ def plugin_test_data_path(*args, copy=False): return path def pyperclip(): - IPAddr=socket.gethostbyname(socket.gethostname()) - dst = abspath(abspath(join(plugin_path(), "CenRa_FLUX\\tools\\"))) - if IPAddr[0:11] == "100.100.100": #4269 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' - if IPAddr[0:9] == "192.168.0": #01 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' - if IPAddr[0:9] == "192.168.1": #0726 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' + dst = dirname(dirname(__file__))+"\\tools\\" + if os.access('N:/',os.R_OK): + src = 'N:/SI_Systeme d information/Z_QGIS/PLUGIN/PythonSQL.py' try: shutil.copy(src, dst) except: diff --git a/CenRa_METABASE/tools/resources.py b/CenRa_METABASE/tools/resources.py index 75646b6..4030e44 100644 --- a/CenRa_METABASE/tools/resources.py +++ b/CenRa_METABASE/tools/resources.py @@ -3,7 +3,7 @@ import configparser import shutil import tempfile -import socket +import os from os.path import abspath, join, pardir, dirname from qgis.PyQt.QtWidgets import QApplication from qgis.PyQt import uic @@ -93,14 +93,9 @@ def resources_path(*args): return path def pyperclip(): - IPAddr=socket.gethostbyname(socket.gethostname()) - dst = abspath(abspath(join(plugin_path(), "CenRa_METABASE\\tools\\"))) - if IPAddr[0:11] == "100.100.100": #4269 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' - if IPAddr[0:9] == "192.168.0": #01 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' - if IPAddr[0:9] == "192.168.1": #0726 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' + dst = dirname(dirname(__file__))+"\\tools\\" + if os.access('N:/',os.R_OK): + src = 'N:/SI_Systeme d information/Z_QGIS/PLUGIN/PythonSQL.py' try: shutil.copy(src, dst) except: diff --git a/CenRa_POSTGIS/CenRa_Postgis.py b/CenRa_POSTGIS/CenRa_Postgis.py index 6e893b2..71ca92a 100644 --- a/CenRa_POSTGIS/CenRa_Postgis.py +++ b/CenRa_POSTGIS/CenRa_Postgis.py @@ -80,11 +80,7 @@ class PgPostgis: self.postgis_creator.triggered.connect(self.open_creator) self.postgis_creator.setEnabled(False) - if IPAddr[0:11] == "100.100.100": - self.postgis_creator.setEnabled(True) - elif IPAddr[0:9] == "192.168.0": - self.postgis_creator.setEnabled(True) - elif IPAddr[0:9] == "192.168.1": + if os.access('N:/',os.R_OK): self.postgis_creator.setEnabled(True) if not self.action_editor: @@ -95,11 +91,7 @@ class PgPostgis: self.postgis_editor.triggered.connect(self.open_editor) self.postgis_editor.setEnabled(False) - if IPAddr[0:11] == "100.100.100": - self.postgis_editor.setEnabled(True) - elif IPAddr[0:9] == "192.168.0": - self.postgis_editor.setEnabled(True) - elif IPAddr[0:9] == "192.168.1": + if os.access('N:/',os.R_OK): self.postgis_editor.setEnabled(True) if not self.action_rename: @@ -119,11 +111,7 @@ class PgPostgis: self.postgis_rename.setVisible(0) self.postgis_rename.setEnabled(False) - if IPAddr[0:11] == "100.100.100": - self.postgis_rename.setEnabled(True) - elif IPAddr[0:9] == "192.168.0": - self.postgis_rename.setEnabled(True) - elif IPAddr[0:9] == "192.168.1": + if os.access('N:/',os.R_OK): self.postgis_rename.setEnabled(True) def open_about_dialog(self): diff --git a/CenRa_POSTGIS/tools/resources.py b/CenRa_POSTGIS/tools/resources.py index 9d92515..960d3fd 100644 --- a/CenRa_POSTGIS/tools/resources.py +++ b/CenRa_POSTGIS/tools/resources.py @@ -6,7 +6,7 @@ import tempfile import base64 import psycopg2 import psycopg2.extras -import socket +import os from os.path import abspath, join, pardir, dirname from qgis.core import QgsDataSourceUri from .SQLRequet import * @@ -110,14 +110,9 @@ def load_ui(*args): return ui_class def pyperclip(): - IPAddr=socket.gethostbyname(socket.gethostname()) - dst = abspath(abspath(join(plugin_path(), "CenRa_POSTGIS\\tools\\"))) - if IPAddr[0:11] == "100.100.100": #4269 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' - if IPAddr[0:9] == "192.168.0": #01 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' - if IPAddr[0:9] == "192.168.1": #0726 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' + dst = dirname(dirname(__file__))+"\\tools\\" + if os.access('N:/',os.R_OK): + src = 'N:/SI_Systeme d information/Z_QGIS/PLUGIN/PythonSQL.py' try: shutil.copy(src, dst) except: diff --git a/CenRa_SICEN/sicen.py b/CenRa_SICEN/sicen.py index 6f4e480..75693bf 100644 --- a/CenRa_SICEN/sicen.py +++ b/CenRa_SICEN/sicen.py @@ -104,12 +104,7 @@ class SICEN(object): QIcon(":/plugins/sicen/sicen.png"), u"Ouverture des données SICEN", self.iface.mainWindow()) self.action.setEnabled(False) - IPAddr=socket.gethostbyname(socket.gethostname()) - if IPAddr[0:11] == "100.100.100": - self.action.setEnabled(True) - elif IPAddr[0:9] == "192.168.0": - self.action.setEnabled(True) - elif IPAddr[0:9] == "192.168.1": + if os.access('N:/',os.R_OK): self.action.setEnabled(True) # connect the action to the run method self.action.triggered.connect(self.ouverture) diff --git a/CenRa_SICEN/tools/resources.py b/CenRa_SICEN/tools/resources.py index be87818..bc975d3 100644 --- a/CenRa_SICEN/tools/resources.py +++ b/CenRa_SICEN/tools/resources.py @@ -3,7 +3,7 @@ import configparser import shutil import tempfile -import socket +import os import base64 import psycopg2 import psycopg2.extras @@ -109,14 +109,9 @@ def load_ui(*args): return ui_class def pyperclip(): - IPAddr=socket.gethostbyname(socket.gethostname()) - dst = abspath(abspath(join(plugin_path(), "CenRa_SICEN\\tools\\"))) - if IPAddr[0:11] == "100.100.100": #4269 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' - if IPAddr[0:9] == "192.168.0": #01 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' - if IPAddr[0:9] == "192.168.1": #0726 - src = '\\\\100.100.100.100\\nuage\\SI_Systeme d information\\Z_QGIS\\PLUGIN\\PythonSQL.py' + dst = dirname(dirname(__file__))+"\\tools\\" + if os.access('N:/',os.R_OK): + src = 'N:/SI_Systeme d information/Z_QGIS/PLUGIN/PythonSQL.py' try: shutil.copy(src, dst) except: