Salome HOME
Merge branch 'V9_2_2_BR'
[modules/shaper.git] / utils.py
1 # coding: utf-8
2
3 # Copyright (C) 2014-2019  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 email : webmaster.salome@opencascade.com
20 #
21
22 import os, os.path
23
24 #SHAPER_SRC = os.environ['SHAPER_SRC']
25 SHAPER_SRC = os.environ['PWD']
26 # VERBOSE_FLAG = os.environ['VERBOSE_FLAG']
27 VERBOSE_FLAG = ""
28 ENCODING = "utf-8"
29 OPERATORS=[">", "<", "+", "=", "-", "*", "/"]
30
31 def create_warning_generator(fichier):
32         """
33         fichier est le fichier de log cpplint ouvert à la position courante.
34         Un trou dans le fichier résulte en l'arrêt de la génération
35         """
36         ligne = "-"
37         ligne = fichier.readline()
38         i = 1
39         while ligne.strip("\n") :
40                 ligne = ligne.decode(ENCODING)
41                 liste = ligne.split(":")
42                 print("Size of liste = ", len(liste))
43                 print("ligne = ", ligne)
44                 print("n° ligne = ", i)
45                 print("XXX : ", ligne.find('Done processing '))
46
47                 if len(liste) < 3:
48                         if ligne.find('Done processing ') == -1 and ligne.find('Category ') == -1 and ligne.find('Total errors found: ') == -1:
49                                 raise Exception("Fichier de log mal formé")
50                         else:
51                                 ligne = fichier.readline()
52                                 i += 1
53                                 continue
54                 elif len(liste) != 3:
55                         item1=liste[0]
56                         item2=liste[1]
57                         merge = ""
58                         sep = ""
59                         for item in liste[2:]:
60                                 merge += sep
61                                 merge += item
62                                 sep = ":"
63                         liste = [item1, item2, merge]
64                 ligne = fichier.readline()
65                 i += 1
66                 yield liste[0], int(liste[1]), liste[2]
67
68 def get_src_path(path):
69         return os.path.normpath(os.path.join(SHAPER_SRC, path))
70
71 def get_line_no(path, nol):
72         """retourne la ligne No nol du fichier path (relatif à DST_SRC_PARENT) sous forme d'un unicode"""
73         ligne = ""
74         fic = open(get_src_path(path), "r")
75         for i in range(nol):
76                 ligne = fic .readline()
77         fic.close()
78         ligne_u = ligne.decode(ENCODING)
79         return ligne_u
80
81 def fic_readlines(fic):
82         tmp=fic.readlines()
83         liste=[]
84         for ligne in tmp:
85                 liste.append(ligne.decode(ENCODING))
86         return liste
87
88 def fic_writelines(liste):
89         liste2=[]
90         for ligne in liste:
91                 liste2.append(ligne.encode(ENCODING))
92         return liste2