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 la classe Formatage qui permet le formatage d'une
22 liste de chaines de caractères dans une syntaxe représentative d'un
23 jeu de commandes en un texte présentable
29 Cette classe contient toutes les méthodes nécessaires au formatage
30 de la chaine de caracteres issue d'un generator en un fichier
31 'lisible' ie avec indentations
33 def __init__(self,l_jdc,code=None,mode=None,sep='=',l_max=72):
34 # l_jdc représente le jeu de commandes brut sous forme de liste
47 def formate_jdc(self):
48 for etape in self.l_jdc:
49 self.count = self.count+1
51 if type(etape)==types.ListType:
53 self.indent.append(len(etape[0]))
54 self.indent_courant = self.indent[0]
55 self.texte_etape = '\n' + etape[0]
57 self.formate_etape(etape[1:])
60 self.texte_etape = etape
61 self.jdc_fini = self.jdc_fini + '\n' + self.texte_etape
64 def formate_etape(self,liste):
66 for element in liste :
67 if type(element) == types.ListType:
68 # il s'agit d'un mot-clé facteur
70 longueur = self.longueur(self.texte_etape)
72 increment = len(('\n'+self.indent_courant*' ')*ind + element[0])
77 self.texte_etape = self.texte_etape + ('\n'+self.indent_courant*' ')*ind + element[0]
78 length = len(self.indent)
79 self.indent.insert(length,self.indent[length-1]+len(element[0]))
80 self.indent_courant = self.indent[length]
82 self.formate_etape(element[1:])
83 elif type(element) == types.StringType:
84 # il s'agit d'un mot-clé simple ou de ')' ou ');' ou '),'
85 if element == ')' or element == '),':
86 self.texte_etape = self.texte_etape + string.strip(element)
87 length = len(self.indent)
89 last = self.indent[length-1]
90 self.indent.remove(last)
91 self.indent_courant=self.indent[length-2]
93 self.indent_courant=self.indent[0]
95 length = len(self.indent)
97 last = self.indent[length-1]
98 self.indent.remove(last)
99 self.indent_courant=self.indent[length-2]
101 self.indent_courant=self.indent[0]
102 self.texte_etape = self.texte_etape + string.strip(element)
104 longueur = self.longueur(self.texte_etape)
105 increment = len(('\n'+self.indent_courant*' ')*ind + string.strip(element))
106 #self.jdc_fini = self.jdc_fini + ('\n'+self.indent_courant*' ')*ind + string.strip(element)
107 if ((1-ind)*longueur+increment) <= self.l_max :
108 self.texte_etape = self.texte_etape + ('\n'+self.indent_courant*' ')*ind + string.strip(element)
111 nom,valeur = string.split(element,self.sep,1)
112 chaine = self.creer_chaine(nom,valeur,'\n'+self.indent_courant*' ',ind)+','
113 #self.jdc_fini = self.jdc_fini + ('\n'+self.indent_courant*' ')*ind + string.strip(element)
114 self.texte_etape = self.texte_etape + chaine
117 def longueur(self,texte):
119 texte est une string qui peut contenir des retours chariots
120 Cette méthode retourne la longueur de la dernière ligne de texte
122 liste = string.split(texte,'\n')
123 return len(liste[-1])
125 def creer_chaine(self,nom,valeur,increment,ind):
127 if len(increment + nom + self.sep) <= self.l_max:
128 texte = increment*ind
129 label = nom + self.sep
131 longueur = len(increment + label)
132 if len(string.split(valeur,'(')) == 1:
133 # il s'agit d'une vraie chaîne de caractères
135 texte = (self.l_max-2-val)*' '+valeur
138 # il s'agit d'une liste
139 liste = string.split(valeur,',')
142 ajout = string.strip(arg)
143 if len(ajout) == 0 : continue
144 longueur = self.longueur(texte = (texte + label)) + len(ajout +',') + (1-i)*len(increment)
145 if longueur <= self.l_max:
147 texte = texte + ajout +','
149 texte = texte + ajout
153 texte = texte + increment + (len(label)+2)*' ' + ajout +','
155 texte = texte + increment + (len(label)+2)*' ' + ajout