1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2013-2016 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
28 import pprint as PP #pretty print
30 from qtsalome import *
34 from MGCleanerViewText_ui import Ui_ViewExe
38 force = os.getenv("FORCE_DISTENE_LICENSE_FILE")
40 os.environ["DISTENE_LICENSE_FILE"] = force
41 os.environ["DLIM8VAR"] = "NOTHING"
43 class MGCleanerMonViewText(Ui_ViewExe, QDialog):
45 Classe permettant la visualisation de texte
47 def __init__(self, parent, txt, ):
48 QDialog.__init__(self,parent)
50 self.resize( QSize(1000,600).expandedTo(self.minimumSizeHint()) )
51 #self.connect( self.PB_Ok,SIGNAL("clicked()"), self, SLOT("close()") )
52 self.PB_Ok.clicked.connect( self.theClose )
53 self.PB_Save.clicked.connect( self.saveFile )
54 self.PB_Save.setToolTip("Save trace in log file")
55 self.PB_Ok.setToolTip("Close view")
56 self.monExe=QProcess(self)
58 self.monExe.readyReadStandardOutput.connect( self.readFromStdOut )
59 self.monExe.readyReadStandardError.connect( self.readFromStdErr )
60 self.monExe.finished.connect( self.finished )
62 """ for test set environment
63 env = QProcessEnvironment().systemEnvironment()
64 env.insert("HELLO", "bonjour") #Add an environment variable for debug
65 self.monExe.setProcessEnvironment(env)
67 PP.pprint([str(i) for i in sorted(self.monExe.processEnvironment().toStringList()) if 'DISTENE' in i])
72 if sys.platform == "win32":
73 if os.path.exists(self.parent().fichierOut):
74 cmds += 'del %s\n' % self.parent().fichierOut
77 cmds += '#!/bin/bash\n'
79 #cmds += 'which mg-cleaner.exe\n'
80 cmds += 'echo "DISTENE_LICENSE_FILE="$DISTENE_LICENSE_FILE\n'
81 cmds += 'echo "DLIM8VAR="$DLIM8VAR\n'
82 cmds += 'rm -f %s\n' % self.parent().fichierOut
85 cmds += 'echo %s\n' % txt #to see what is compute command
87 cmds += 'echo "END_OF_MGCleaner"\n'
89 nomFichier = os.path.splitext(self.parent().fichierOut)[0] + ext
90 with open(nomFichier, 'w') as f:
92 self.make_executable(nomFichier)
94 if verbose: print(("INFO: MGCleaner launch script file: %s" % nomFichier))
96 self.monExe.start(nomFichier)
97 self.monExe.closeWriteChannel()
98 self.enregistreResultatsDone=False
101 def make_executable(self, path):
102 mode = os.stat(path).st_mode
103 mode |= (mode & 0o444) >> 2 # copy R bits to X
107 #recuperation du nom du fichier
108 savedir=os.environ['HOME']
109 fn = QFileDialog.getSaveFileName(None, self.trUtf8("Save File"),savedir)
110 if fn.isNull() : return
111 ulfile = os.path.abspath(str(fn))
114 f.write(str(self.TB_Exe.toPlainText()))
116 except IOError as why:
117 QMessageBox.critical(self, self.trUtf8('Save File'),
118 self.trUtf8('The file <b>%1</b> could not be saved.<br>Reason: %2')
119 .arg(str(fn)).arg(str(why)))
121 def readFromStdErr(self):
122 a=self.monExe.readAllStandardError()
123 self.TB_Exe.append(str(a.data()))
125 def readFromStdOut(self) :
126 a=self.monExe.readAllStandardOutput()
128 self.TB_Exe.append(aa)
131 self.parent().enregistreResultat()
132 self.enregistreResultatsDone=True
135 if not self.enregistreResultatsDone:
136 self.parent().enregistreResultat()
137 self.enregistreResultatsDone=True