Salome HOME
Fix XAO Part uppercase
[modules/shaper.git] / utils.py
1 # coding: utf-8
2
3 ## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
4 ##
5 ## This library is free software; you can redistribute it and/or
6 ## modify it under the terms of the GNU Lesser General Public
7 ## License as published by the Free Software Foundation; either
8 ## version 2.1 of the License, or (at your option) any later version.
9 ##
10 ## This library is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## Lesser General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU Lesser General Public
16 ## License along with this library; if not, write to the Free Software
17 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ##
19 ## See http:##www.salome-platform.org/ or
20 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 ##
22
23 import os, os.path
24
25 #SHAPER_SRC = os.environ['SHAPER_SRC']
26 SHAPER_SRC = os.environ['PWD']
27 # VERBOSE_FLAG = os.environ['VERBOSE_FLAG']
28 VERBOSE_FLAG = ""
29 ENCODING = u"utf-8"
30 OPERATORS=[u">", u"<", u"+", u"=", u"-", u"*", u"/"]
31
32 def create_warning_generator(fichier):
33         """
34         fichier est le fichier de log cpplint ouvert à la position courante.
35         Un trou dans le fichier résulte en l'arrêt de la génération
36         """
37         ligne = "-"
38         ligne = fichier.readline()
39         i = 1
40         while ligne.strip("\n") :
41                 ligne = ligne.decode(ENCODING)
42                 liste = ligne.split(":")
43                 print "Size of liste = ", len(liste)
44                 print "ligne = ", ligne
45                 print "n° ligne = ", i
46                 print "XXX : ", ligne.find(u'Done processing ')
47
48                 if len(liste) < 3:
49                         if ligne.find(u'Done processing ') == -1 and ligne.find(u'Category ') == -1 and ligne.find(u'Total errors found: ') == -1:
50                                 raise Exception(u"Fichier de log mal formé")
51                         else:
52                                 ligne = fichier.readline()
53                                 i += 1
54                                 continue
55                 elif len(liste) != 3:
56                         item1=liste[0]
57                         item2=liste[1]
58                         merge = u""
59                         sep = u""
60                         for item in liste[2:]:
61                                 merge += sep
62                                 merge += item
63                                 sep = u":"
64                         liste = [item1, item2, merge]
65                 ligne = fichier.readline()
66                 i += 1
67                 yield liste[0], int(liste[1]), liste[2]
68
69 def get_src_path(path):
70         return os.path.normpath(os.path.join(SHAPER_SRC, path))
71
72 def get_line_no(path, nol):
73         """retourne la ligne No nol du fichier path (relatif à DST_SRC_PARENT) sous forme d'un unicode"""
74         ligne = ""
75         fic = open(get_src_path(path), "r")
76         for i in xrange(nol):
77                 ligne = fic .readline()
78         fic.close()
79         ligne_u = ligne.decode(ENCODING)
80         return ligne_u
81
82 def fic_readlines(fic):
83         tmp=fic.readlines()
84         liste=[]
85         for ligne in tmp:
86                 liste.append(ligne.decode(ENCODING))
87         return liste
88
89 def fic_writelines(liste):
90         liste2=[]
91         for ligne in liste:
92                 liste2.append(ligne.encode(ENCODING))
93         return liste2