1 # -*- coding: utf-8 -*-
2 # CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
20 # ======================================================================
22 Ce module contient le plugin convertisseur de fichier
23 au format ini pour EFICAS.
24 Le convertisseur supporte le format de sortie eval
26 Le format eval est un texte Python qui peut etre
27 evalué avec la commande eval de Python. Il doit donc
28 etre une expression Python dont l'évaluation permet d'obtenir un objet
33 from ConfigParser import ConfigParser
34 from Noyau import N_CR
38 Retourne les informations nécessaires pour le chargeur de plugins
39 Ces informations sont retournées dans un dictionnaire
44 # La factory pour créer une instance du plugin
45 'factory' : IniParser,
49 class IniParser(ConfigParser):
51 Ce convertisseur lit un fichier au format ini avec la
52 methode readfile : convertisseur.readfile(nom_fichier)
53 et retourne le texte au format outformat avec la
54 methode convertisseur.convert(outformat)
56 Ses caractéristiques principales sont exposées dans 2 attributs
58 - extensions : qui donne une liste d'extensions de fichier préconisées
59 - formats : qui donne une liste de formats de sortie supportés
61 # Les extensions de fichier préconisées
62 extensions=('.ini','.conf')
63 # Les formats de sortie supportés (eval ou exec)
64 formats=('eval','dict')
66 def __init__(self,cr=None):
67 ConfigParser.__init__(self)
68 # Si l'objet compte-rendu n'est pas fourni, on utilise le compte-rendu standard
72 self.cr=N_CR.CR(debut='CR convertisseur format ini',
73 fin='fin CR format ini')
75 def readfile(self,filename):
81 def convert(self,outformat,appli=None):
82 if outformat == 'eval':
83 return self.getdicttext()
84 elif outformat == 'dict':
87 raise "Format de sortie : %s, non supporté"
89 def getdicttext(self):
91 for section in self.sections():
92 s=s+ "'" + section + "' : {"
93 options=self.options(section)
94 for option in options:
95 value=self.get(section,option)
96 if value == '':value="None"
97 s=s+"'%s' : %s," % (option, value)
104 for section in self.sections():
106 options=self.options(section)
107 for option in options:
108 value=self.get(section,option)
112 d[option]=eval(value)