1 #@ MODIF lire_table_ops Macro DATE 16/10/2007 AUTEUR REZETTE C.REZETTE
2 # -*- coding: iso-8859-1 -*-
3 # CONFIGURATION MANAGEMENT OF EDF VERSION
4 # ======================================================================
5 # COPYRIGHT (C) 1991 - 2004 EDF R&D WWW.CODE-ASTER.ORG
6 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
7 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
8 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
9 # (AT YOUR OPTION) ANY LATER VERSION.
11 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
12 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
13 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
14 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
16 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
17 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
18 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
19 # ======================================================================
24 # ------------------------------------------------------------------------------
25 def msplit(chaine, separ):
26 """Equivalent de chaine.split(separ) en acceptant une ou plusieurs
27 occurrences du séparateur.
29 return re.split('%s+' % re.escape(separ), chaine.strip(separ))
31 # ------------------------------------------------------------------------------
32 def lecture_table(texte, nume, separ):
33 """Méthode de construction de l'objet Table à partir d'un texte d'une table
36 from Utilitai.transpose import transpose
37 from Utilitai.Table import Table
38 from Utilitai.Utmess import UTMESS
42 idt_deb = '#DEBUT_TABLE\n'
43 idt_fin = '#FIN_TABLE\n'
47 # expression régulière pour découper les N tables du fichier
48 exp = re.compile(re.escape(idt_deb) + '(.*?)' + re.escape(idt_fin),
49 re.MULTILINE | re.DOTALL)
50 l_txt = exp.findall(texte)
53 UTMESS('F', 'TABLE0_10', vali=(nume, nbbloc))
54 txttab = l_txt[nume - 1]
56 # expression régulière pour extraire le titre
57 exp = re.compile(re.escape(idt_tit) + '(.*)$', re.MULTILINE)
58 titre_tab = os.linesep.join([s.strip(separ) for s in exp.findall(txttab)])
60 # restent dans la table les lignes non vides qui ne sont pas des titres
61 txttab = [line for line in txttab.splitlines() \
62 if line.strip(separ) != '' and not line.startswith(idt_tit)]
64 # ligne des paramètres et des types
65 list_para = msplit(txttab.pop(0), separ)
66 list_type = msplit(txttab.pop(0), separ)
67 nb_para = len(list_type)
72 'R' : '([0-9\.,\-\+eEdD]+)',
75 lfmt = ('%s+' % re.escape(separ)).join(
76 [fmt[typ[0]] % { 'len' : typ[1:] } for typ in list_type]
79 # construction des lignes de la Table
81 for i, line in enumerate(txttab):
82 mat = re.search(lfmt, line)
83 if mat is None or nb_para != len(mat.groups()):
84 UTMESS('F+', 'TABLE0_11', vali=i + 1)
86 UTMESS('F+', 'TABLE0_12', vali=len(mat.groups()))
87 UTMESS('F', 'TABLE0_13', vali=nb_para)
89 for para, typ, ch in zip(list_para, list_type, mat.groups()):
101 tab = Table(l_rows, list_para, list_type, titre_tab)
105 # ------------------------------------------------------------------------------
106 def lire_table_ops(self, **args):
107 """Méthode corps de la macro LIRE_TABLE
109 from Utilitai.Utmess import UTMESS
110 from Utilitai.UniteAster import UniteAster
113 nompro = 'LIRE_TABLE'
114 ### On importe les definitions des commandes a utiliser dans la macro
115 CREA_TABLE = self.get_cmd('CREA_TABLE')
116 UNITE = self['UNITE']
117 FORMAT = self['FORMAT']
118 NUME_TABLE = self['NUME_TABLE']
119 SEPARATEUR = self['SEPARATEUR']
121 TITRE = self['TITRE']
123 ### La macro compte pour 1 dans la numerotation des commandes
126 ### Lecture de la table dans un fichier d unité logique UNITE
128 nomfich=UL.Nom(UNITE)
129 if not os.path.isfile(nomfich):
130 UTMESS('F', nompro, "le fichier '%s' est introuvable" % nomfich)
132 texte = open(nomfich,'r').read()
133 # remet UNITE dans son état initial
136 ### mise en forme de la liste de valeurs suivant le format choisi :
137 # pour le moment uniquement ASTER
139 tab_lue = lecture_table(texte, NUME_TABLE, SEPARATEUR)
143 ### création de la table ASTER :
144 self.DeclareOut('ut_tab', self.sd)
145 motscles = tab_lue.dict_CREA_TABLE()
146 ut_tab=CREA_TABLE(**motscles)