Salome HOME
premiere version
[tools/eficas.git] / Noyau / N_CR.py
index 5be765e76691f01aa8eeb3f71bb08284923c780f..1b6d0466c7c2d17e1b2c36e6d5e93abff43d1b0b 100644 (file)
@@ -1,31 +1,31 @@
-#@ MODIF N_CR Noyau  DATE 20/01/2003   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='   '):
       """
@@ -53,9 +53,9 @@ class CR :
       """ 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"""
@@ -66,10 +66,9 @@ class CR :
       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
@@ -78,7 +77,7 @@ class CR :
       return 1
 
    def purge(self):
-      """ 
+      """
            Purge complètement le CR sauf les exceptions
       """
       self.debut=''
@@ -117,7 +116,7 @@ class CR :
       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
       """
@@ -129,16 +128,22 @@ class CR :
       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
@@ -165,7 +170,7 @@ class CR :
 
    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()
@@ -177,7 +182,7 @@ class CR :
 
    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()
@@ -188,57 +193,6 @@ class CR :
       return s
 
 
-
-
-def justify_text_old(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]
-
-def encadre_message_old(texte,motif):
-  """ 
-     Retourne la chaine de caractères texte entourée d'un cadre formés
-     d'éléments 'motif'
-  """
-  texte = justify_text(texte,cesure=80)
-  lignes = string.split(texte,'\n')
-  longueur = 0
-  for ligne in lignes :
-    if len(ligne)> longueur : longueur = len(ligne)
-  longueur = longueur + 4
-  txt = motif*longueur+'\n'
-  for ligne in lignes :
-    txt = txt + motif + ' '+ligne+' '*(longueur-len(motif+ligne)-2)+motif+'\n'
-  txt = txt + motif*longueur+'\n'
-  return txt
-
-
-
-
 separateurs=(' ',',','/')
 def split(ligne,cesure):
        ligne= string.rstrip(ligne)