1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 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 le plugin convertisseur de fichier
22 au format ini pour EFICAS.
23 Le convertisseur supporte le format de sortie eval
25 Le format eval est un texte Python qui peut etre
26 evalué avec la commande eval de Python. Il doit donc
27 etre une expression Python dont l'évaluation permet d'obtenir un objet
32 from ConfigParser import ConfigParser
33 from Noyau import N_CR
34 from Extensions.i18n import tr
35 from Extensions.eficas_exception import EficasException
40 Retourne les informations nécessaires pour le chargeur de plugins
41 Ces informations sont retournées dans un dictionnaire
46 # La factory pour créer une instance du plugin
47 'factory' : IniParser,
51 class IniParser(ConfigParser):
53 Ce convertisseur lit un fichier au format ini avec la
54 methode readfile : convertisseur.readfile(nom_fichier)
55 et retourne le texte au format outformat avec la
56 methode convertisseur.convert(outformat)
58 Ses caractéristiques principales sont exposées dans 2 attributs
60 - extensions : qui donne une liste d'extensions de fichier préconisées
61 - formats : qui donne une liste de formats de sortie supportés
63 # Les extensions de fichier préconisées
64 extensions=('.ini','.conf')
65 # Les formats de sortie supportés (eval ou exec)
66 formats=('eval','dict')
68 def __init__(self,cr=None):
69 ConfigParser.__init__(self)
70 # Si l'objet compte-rendu n'est pas fourni, on utilise le compte-rendu standard
74 self.cr=N_CR.CR(debut='CR convertisseur format ini',
75 fin='fin CR format ini')
77 def readfile(self,filename):
81 self.cr.fatal(tr("lecture du fichier impossible :")+str(e))
83 def convert(self,outformat,appli=None):
84 if outformat == 'eval':
85 return self.getdicttext()
86 elif outformat == 'dict':
89 raise ExceptionException("Format de sortie : %s, non supporte", outformat)
92 def getdicttext(self):
94 for section in self.sections():
95 s=s+ "'" + section + "' : {"
96 options=self.options(section)
97 for option in options:
98 value=self.get(section,option)
99 if value == '':value="None"
100 s=s+"'%s' : %s," % (option, value)
107 for section in self.sections():
109 options=self.options(section)
110 for option in options:
111 value=self.get(section,option)
115 d[option]=eval(value)