Salome HOME
Copyright update 2022
[modules/smesh.git] / src / Tools / ZCracksPlug / output.py
1 # Copyright (C) 2016-2022  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 from subprocess import Popen
21 from os import remove, getpid, path
22
23 def init(tmpdir):
24   global log
25   log=output(tmpdir)
26   log.initialise()
27
28 def message(typ, message, goOn=False):
29   global log
30   log.message(typ,message,goOn)
31
32 class output():
33   def __init__(self, tmpDir, tmpFile='Messages.txt'):
34     self.tmpFile=path.join(tmpDir,tmpFile)
35
36   def initialise(self):
37     try:
38       remove(self.tmpFile)
39     except:
40       pass
41     f = open(self.tmpFile,'w')
42     f.write('\n      ------------------------------\n')
43     f.write('     |  BIENVENUE DANS L\'INTERFACE  |\n')
44     f.write('     |      ZCRACKS DE SALOME       |\n')
45     f.write('     |        VERSION BETA          |\n')
46     f.write('       ------------------------------\n\n')
47     f.close()
48
49     pid=getpid()
50     fenName='Zcracks message log'
51     proc = Popen(['xterm -T "%s" -e "tail -s 0.05 -f %s --pid=%d"' %(fenName,self.tmpFile,pid)], shell=True)
52     return()
53
54   def message(self, typ, message='', goOn=False):
55     fileName=self.tmpFile
56     f = open(fileName,'a')
57     if typ=='E':
58       f.write('ERROR: '+message+'\n')
59       #print 'ERROR: '+message
60       if not goOn:
61         exit()
62
63     elif typ in ['A','W']:
64       #print ARNING: '+message
65       f.write('WARNING: '+message+'\n')
66
67     elif typ in ['M','I']:
68       #print 'INFO: '+message
69       f.write(message+'\n')
70
71     f.close()