-#@ MODIF N_CR Noyau DATE 29/05/2002 AUTEUR DURAND C.DURAND
-# CONFIGURATION MANAGEMENT OF EDF VERSION
-# ======================================================================
-# COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG
-# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
-# IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
-# THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
-# (AT YOUR OPTION) ANY LATER VERSION.
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2013 EDF R&D
#
-# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
-# WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
-# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
-# GENERAL PUBLIC LICENSE FOR MORE DETAILS.
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
-# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
-# 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
-#
-#
-# ======================================================================
""" Ce module contient la classe compte-rendu de validation
"""
import string
+from strfunc import convert, ufmt
class CR :
- """
- Classe servant à la construction et à l'affichage des objets Comptes-rendus
+ """
+ Classe servant à la construction et à l'affichage des objets Comptes-rendus
"""
def __init__(self,verbeux = 'non',debut='',fin='',dec=' '):
"""
""" Ajoute un commentaire Warning à la liste crwarn"""
self.crwarn.append(comment)
- def fatal(self,comment):
- """ Ajoute un commentaire Erreur Fatale à la liste crfatal"""
- self.crfatal.append(comment)
+ def fatal(self, comment, *args):
+ """Ajoute un commentaire Erreur Fatale à la liste crfatal à formater"""
+ self.crfatal.append(ufmt(comment, *args))
def exception(self,comment):
""" Ajoute un commentaire Exception à la liste crexception"""
self.subcr.append(cr)
def estvide(self):
- """
- Retourne 1 si self ne contient aucun message grave (fatal ou exception) et
- aucun CR qui en contienne,
- 0 sinon
+ """
+ Retourne 1 si self ne contient aucun message grave (fatal ou exception)
+ et aucun CR qui en contienne, 0 sinon
"""
if self.crexception : return 0
if self.crfatal : return 0
return 1
def purge(self):
- """
+ """
Purge complètement le CR sauf les exceptions
"""
self.debut=''
l = string.split(s,'\n')
return self.dec+string.join(l,'\n'+self.dec)[:-3]
- def __str__(self):
+ def __unicode__(self):
"""
Retourne une chaine de caractères décorée et représentative de self
"""
s=s+string.join(self.crexception_belle,'')
for subcr in self.subcr:
if self.verbeux == 'oui':
- s=s+str(subcr)+'\n'
+ s=s+unicode(subcr)+'\n'
else:
if not subcr.estvide():
- s=s+str(subcr)
+ s=s+unicode(subcr)
if s != '':
s=self.debut+'\n'+self.indent(s)+self.fin+'\n'
else :
s=self.debut+'\n'+self.fin+'\n'
return s
+ def __str__(self):
+ """Return the report representation"""
+ # convert into the output encoding
+ txt = convert(self.__unicode__())
+ return txt
+
def report(self,decalage = 2):
"""
Retourne une chaine de caractères non encadrée mais représentative de self
def get_mess_fatal(self):
"""
- Retourne une chaine de caractères contenant les messages de
+ Retourne une chaine de caractères contenant les messages de
la liste crfatal (du dernier au premier)
"""
self.crfatal.reverse()
def get_mess_exception(self):
"""
- Retourne une chaine de caractères contenant les messages
+ Retourne une chaine de caractères contenant les messages
de la liste crexception (du dernier au premier)
"""
self.crexception.reverse()
return s
-
+separateurs=(' ',',','/')
+def split(ligne,cesure):
+ ligne= string.rstrip(ligne)
+ if len(ligne) <= cesure :
+ return ligne
+ else:
+ coupure=cesure
+ while ligne[coupure] not in separateurs and coupure > 0:
+ coupure = coupure - 1
+ if coupure == 0:
+ # Il faut augmenter la cesure
+ coupure =cesure
+ while ligne[coupure] not in separateurs and coupure < len(ligne)-1 :
+ coupure = coupure + 1
+ if coupure == len(ligne)-1:
+ return ligne
+ else:
+ return ligne[:coupure+1]+ '\n' + split(ligne[coupure+1:],cesure)
def justify_text(texte='',cesure=50):
- """
- Prend la chaine de caractères 'texte' et la retourne avec un retour chariot
- tous les 'cesure' caractères s'il y a lieu (le retour chariot est placé dans un blanc
- et non au milieu d'un mot
- """
- texte = string.strip(texte)
- if len(texte) < cesure : return texte
- liste_lignes = string.split(texte,'\n')
- texte_justifie = ''
- for ligne in liste_lignes :
- ligne = string.strip(ligne)
- if len(ligne) <= cesure :
- texte_justifie = texte_justifie + ligne + '\n'
- continue
- longueur = 0
- new_text = ''
- liste_mots = string.split(ligne,' ')
- for mot in liste_mots :
- new_longueur = longueur + len(mot)+1
- if new_longueur < cesure :
- new_text = new_text+' '+mot
- longueur = longueur + len(mot) + 1
- else :
- longueur = 0
- new_text = new_text + '\n'+mot
- texte_justifie = texte_justifie + string.strip(new_text) + '\n'
- return texte_justifie[0:-1]
+ texte = string.strip(texte)
+ liste_lignes = string.split(texte,'\n')
+ l=[split(l,cesure) for l in liste_lignes]
+ texte_justifie=string.join(l,'\n')
+ return texte_justifie
def encadre_message(texte,motif):
- """
+ """
Retourne la chaine de caractères texte entourée d'un cadre formés
d'éléments 'motif'
"""
lignes = string.split(texte,'\n')
longueur = 0
for ligne in lignes :
+ ligne=string.rstrip(ligne)
if len(ligne)> longueur : longueur = len(ligne)
longueur = longueur + 4
txt = motif*longueur+'\n'