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