1 # CONFIGURATION MANAGEMENT OF EDF VERSION
2 # ======================================================================
3 # COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG
4 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
5 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
6 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
7 # (AT YOUR OPTION) ANY LATER VERSION.
9 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
10 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
11 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
12 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
14 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
15 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
16 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
19 # ======================================================================
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
37 Retourne les informations nécessaires pour le chargeur de plugins
38 Ces informations sont retournées dans un dictionnaire
43 # La factory pour créer une instance du plugin
44 'factory' : IniParser,
48 class IniParser(ConfigParser):
50 Ce convertisseur lit un fichier au format ini avec la
51 methode readfile : convertisseur.readfile(nom_fichier)
52 et retourne le texte au format outformat avec la
53 methode convertisseur.convert(outformat)
55 Ses caractéristiques principales sont exposées dans 2 attributs
58 - extensions : qui donne une liste d'extensions de fichier préconisées
60 - formats : qui donne une liste de formats de sortie supportés
62 # Les extensions de fichier préconisées
63 extensions=('.ini','.conf')
64 # Les formats de sortie supportés (eval ou exec)
65 formats=('eval','dict')
67 def __init__(self,cr=None):
68 ConfigParser.__init__(self)
69 # Si l'objet compte-rendu n'est pas fourni, on utilise le compte-rendu standard
73 self.cr=N_CR.CR(debut='CR convertisseur format ini',
74 fin='fin CR format ini')
76 def readfile(self,filename):
82 def convert(self,outformat):
83 if outformat == 'eval':
84 return self.getdicttext()
85 elif outformat == 'dict':
88 raise "Format de sortie : %s, non supporté"
90 def getdicttext(self):
92 for section in self.sections():
93 s=s+ "'" + section + "' : {"
94 options=self.options(section)
95 for option in options:
96 value=self.get(section,option)
97 if value == '':value="None"
98 s=s+"'%s' : %s," % (option, value)
105 for section in self.sections():
107 options=self.options(section)
108 for option in options:
109 value=self.get(section,option)
113 d[option]=eval(value)