From: Jean-Philippe ARGAUD Date: Mon, 6 Aug 2012 19:33:35 +0000 (+0200) Subject: Improving path management in the whole module X-Git-Tag: V6_6_0~42 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=96c43574f86adc54ecc4898204041991a5529956;p=modules%2Fadao.git Improving path management in the whole module --- diff --git a/bin/qtEficas_adao_study.py.in b/bin/qtEficas_adao_study.py.in index 6cf0205..c9018cc 100644 --- a/bin/qtEficas_adao_study.py.in +++ b/bin/qtEficas_adao_study.py.in @@ -28,9 +28,9 @@ import sys # Configuration de l'installation INSTALLDIR = "@EFICAS_DIR@" -sys.path[:0]=[INSTALLDIR] +sys.path.insert(0,INSTALLDIR) ADAO_INSTALL_DIR = "@PYTHON_SITE@/salome/daEficas" -sys.path[:0]=[ADAO_INSTALL_DIR] +sys.path.insert(0,ADAO_INSTALL_DIR) # Configuration import prefs diff --git a/resources/ADAOSchemaCatalog.xml b/resources/ADAOSchemaCatalog.xml index 4d42970..aa8c2d7 100644 --- a/resources/ADAOSchemaCatalog.xml +++ b/resources/ADAOSchemaCatalog.xml @@ -278,7 +278,8 @@ import os filepath = os.path.dirname(script) filename = os.path.basename(script) module_name = os.path.splitext(filename)[0] -sys.path.insert(0,filepath) +if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath,0,1)>0): + sys.path.insert(0,filepath) # Import script __import__(module_name) @@ -337,7 +338,8 @@ import os filepath = os.path.dirname(script) filename = os.path.basename(script) module_name = os.path.splitext(filename)[0] -sys.path.insert(0,filepath) +if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath,0,1)>0): + sys.path.insert(0,filepath) # Import script __import__(module_name) diff --git a/src/daComposant/daCore/AssimilationStudy.py b/src/daComposant/daCore/AssimilationStudy.py index fbbb3b7..fbb7156 100644 --- a/src/daComposant/daCore/AssimilationStudy.py +++ b/src/daComposant/daCore/AssimilationStudy.py @@ -33,6 +33,7 @@ import numpy import Logging ; Logging.Logging() # A importer en premier import Persistence from BasicObjects import Operator +from PlatformInfo import uniq # ============================================================================== class AssimilationStudy: @@ -95,7 +96,7 @@ class AssimilationStudy: # qui est activée dans Persistence) self.__parent = os.path.abspath(os.path.join(os.path.dirname(__file__),"..")) sys.path.insert(0, self.__parent) - sys.path = list(set(sys.path)) # Conserve en unique exemplaire chaque chemin + sys.path = uniq( sys.path ) # Conserve en unique exemplaire chaque chemin # --------------------------------------------------------- def setBackground(self, @@ -758,7 +759,7 @@ class AssimilationStudy: if not os.path.isfile(os.path.join(asPath,"daAlgorithms","__init__.py")): raise ValueError("The given \""+asPath+"/daAlgorithms\" path must contain a file named \"__init__.py\"") sys.path.insert(0, os.path.abspath(asPath)) - sys.path = list(set(sys.path)) # Conserve en unique exemplaire chaque chemin + sys.path = uniq( sys.path ) # Conserve en unique exemplaire chaque chemin return 1 def get_diagnostics_main_path(self): @@ -783,7 +784,7 @@ class AssimilationStudy: if not os.path.isfile(os.path.join(asPath,"daDiagnostics","__init__.py")): raise ValueError("The given \""+asPath+"/daDiagnostics\" path must contain a file named \"__init__.py\"") sys.path.insert(0, os.path.abspath(asPath)) - sys.path = list(set(sys.path)) # Conserve en unique exemplaire chaque chemin + sys.path = uniq( sys.path ) # Conserve en unique exemplaire chaque chemin return 1 # ----------------------------------------------------------- diff --git a/src/daComposant/daCore/PlatformInfo.py b/src/daComposant/daCore/PlatformInfo.py index b70bb45..7e51265 100644 --- a/src/daComposant/daCore/PlatformInfo.py +++ b/src/daComposant/daCore/PlatformInfo.py @@ -83,6 +83,14 @@ class PlatformInfo: import version return "%s %s (%s)"%(version.name,version.version,version.date) +# ============================================================================== +def uniq(sequence): + """ + Fonction pour rendre unique chaque élément d'une liste, en préservant l'ordre + """ + __seen = set() + return [x for x in sequence if x not in __seen and not __seen.add(x)] + # ============================================================================== class PathManagement: """ @@ -100,9 +108,9 @@ class PathManagement: sys.path.insert(0, v ) # # Conserve en unique exemplaire chaque chemin - sys.path = list(set(sys.path)) + sys.path = uniq( sys.path ) del parent - + def getpaths(self): """ Renvoie le dictionnaire des chemins ajoutés diff --git a/src/daEficas/prefs_ADAO.py.in b/src/daEficas/prefs_ADAO.py.in index b2f68c0..a825744 100644 --- a/src/daEficas/prefs_ADAO.py.in +++ b/src/daEficas/prefs_ADAO.py.in @@ -26,7 +26,7 @@ import os, sys # Configuration de Eficas # INSTALLDIR, REPINI est obligatoire INSTALLDIR = "@EFICAS_DIR@" -sys.path[:0]=[INSTALLDIR] +sys.path.insert(0,INSTALLDIR) # positionnee a repin au debut mise a jour dans configuration repIni=os.path.dirname(os.path.abspath(__file__)) diff --git a/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py b/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py index 8dacee4..457e82b 100644 --- a/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py +++ b/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py @@ -42,7 +42,7 @@ class AdaoEficasWrapper(eficasSalome.MyEficas): # Permet à EFICAS de faire ses import correctement my_path = os.path.dirname(os.path.abspath(__file__)) ADAO_INSTALL_DIR = my_path + "/../daEficas" - sys.path[:0]=[ADAO_INSTALL_DIR] + sys.path.insert(0,ADAO_INSTALL_DIR) self.__parent = parent diff --git a/src/daSalome/daYacsSchemaCreator/methods.py b/src/daSalome/daYacsSchemaCreator/methods.py index 27d1910..9f148f8 100644 --- a/src/daSalome/daYacsSchemaCreator/methods.py +++ b/src/daSalome/daYacsSchemaCreator/methods.py @@ -324,7 +324,8 @@ def create_yacs_proc(study_config): node_script += "filepath = \"" + base_repertory + "\"\n" else: node_script += "filepath = \"" + os.path.dirname(script_filename) + "\"\n" - node_script += "sys.path.insert(0,os.path.dirname(filepath))\n" + node_script += "if sys.path.count(os.path.dirname(filepath))==0 or (sys.path.count(os.path.dirname(filepath))>0 and sys.path.index(os.path.dirname(filepath),0,1)>0):\n" + node_script += " sys.path.insert(0,os.path.dirname(filepath))\n" node_script += script_str.read() opt_script_node.setScript(node_script) opt_script_node.edAddInputPort("computation", t_param_input) @@ -455,7 +456,8 @@ def create_yacs_proc(study_config): node_script += "filepath = \"" + base_repertory + "\"\n" else: node_script += "filepath = \"" + os.path.dirname(script_filename) + "\"\n" - node_script += "sys.path.insert(0,os.path.dirname(filepath))\n" + node_script += "if sys.path.count(os.path.dirname(filepath))==0 or (sys.path.count(os.path.dirname(filepath))>0 and sys.path.index(os.path.dirname(filepath),0,1)>0):\n" + node_script += " sys.path.insert(0,os.path.dirname(filepath))\n" node_script += default_script node_script += analysis_file.read() analysis_node.setScript(node_script)