1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 Ce module contient des utilitaires divers
28 from Extensions.i18n import tr
30 def substract_list(liste1,liste2):
32 Enleve tous les elements de liste2 presents dans liste1 et retourne liste1
41 def get_rep_user(dir):
43 Determine sur quelle plate-forme s'execute Eficas et recherche
44 le repertoire de l'utilisateur /$home/Eficas_install
47 rep_user_eficas= os.path.join(os.environ['HOME'],dir)
48 if os.path.exists(rep_user_eficas):
49 if os.path.isfile(rep_user_eficas) :
50 print (tr("Un fichier de nom %s existe deja : impossible de creer un repertoire de meme nom", rep_user_eficas))
54 os.mkdir(rep_user_eficas)
56 print (tr("Creation du repertoire %s impossible\n Verifiez vos droits d'acces", rep_user_eficas))
57 return rep_user_eficas
61 ouvre le fichier file et retourne son contenu
72 def save_in_file(file,text,dir=None):
74 cree le fichier file (ou l'ecrase s'il existe) et ecrit text dedans
75 retourne 1 si OK 0 sinon
87 def extension_fichier(pathAndFile):
88 """ Return ext if path/filename.ext is given """
89 return os.path.splitext(pathAndFile)[1][1:]
91 def stripPath(pathAndFile):
92 """ Return filename.ext if path/filename.ext is given """
93 return os.path.split(pathAndFile)[1]
95 def init_rep_cata_dev(fic_cata,rep_goal):
97 Initialise le repertoire des catalogues developpeurs (chemin d'acces donne
98 dans le fichier eficas.ini cad :
99 - le cree s'il n'existe pas encore
100 - copie dedans les 3 fichiers necessaires :
101 * __init__.py (pour que ce repertoire puisse etre interprete comme un package)
102 * entete.py (pour realiser les import necessaires a l'interpretation des catalogues)
103 * declaration_concepts.py (idem)
104 - cree le fichier cata_developpeur.py qui sera par la suite importe
107 if not os.path.isdir(rep_goal) :
109 #texte_entete = get_entete_cata(fic_cata)
111 # rep_goal doit contenir les catalogues du developpeur sous la forme *.capy
112 # il faut creer le catalogue developpeur par concatenation de entete,declaration_concepts
113 # et de tous ces fichiers
114 cur_dir = os.getcwd()
116 l_cata_dev = glob.glob('*.capy')
117 if os.path.isfile('cata_developpeur.py') : os.remove('cata_developpeur.py')
119 # des catalogues developpeurs sont effectivement presents : on cree cata_dev.py dans rep_goal
121 str = str + texte_entete+'\n'
122 for file in l_cata_dev :
123 str = str + open(file,'r').read() +'\n'
124 open('cata_developpeur.py','w+').write(str)
127 traceback.print_exc()
128 print ( tr("Impossible de transferer les fichiers requis dans : %s", str(rep_goal)))
130 def get_entete_cata(fic_cata):
131 """ Retrouve l'entete du catalogue """
132 l_lignes = open(fic_cata,'r').readlines()
135 for ligne in l_lignes :
136 if re.match(u"# debut entete",ligne) : flag = 1
137 if re.match(u"# fin entete",ligne) : break
138 if not flag : continue