Salome HOME
bug
[tools/eficas.git] / Editeur / listePatrons.py
1 # Copyright (C) 2007-2017   EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 from __future__ import absolute_import
20 try :
21    from builtins import range
22    from builtins import object
23 except : pass
24 import os
25 import re
26 from six.moves import range
27
28 sous_menus={
29 #           "OPENTURNS_STUDY" : {0:{"Essai":"Std.comm"}},
30 #            "OPENTURNS_WRAPPER" : {0:{"Essai":"wrapper_exemple.comm"}},
31            }
32
33 class listePatrons(object) :
34
35     def __init__(self,code = "ASTER"):
36        repIni=os.path.dirname(os.path.abspath(__file__))
37        self.rep_patrons=repIni+"/Patrons/"+code
38        self.sous_menu={}
39        if code in sous_menus  :
40           self.sous_menu=sous_menus[code]
41        self.code=code
42        self.liste={}
43        self.traiteListe()
44
45     def traiteListe(self):
46         if not (self.code in sous_menus) : return
47         if not (os.path.exists(self.rep_patrons)) : return
48         for file in os.listdir(self.rep_patrons):
49             for i in range(len(self.sous_menu)):
50                 clef=list(self.sous_menu[i].keys())[0]
51                 chaine=self.sous_menu[i][clef]
52                 if re.search(chaine,file) :
53                    if clef in self.liste:
54                       self.liste[clef].append(file)
55                    else :
56                       self.liste[clef]=[file]
57                    break