X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FTools%2FYamsPlug%2FmonViewText.py;h=3109bfe8aad4c8ac3de005f910636ea4d3712bfb;hp=478e1833d0b0f4d46f3125283b552a6b65d163a2;hb=442fd64c19a6e27a339ca36264c15ec91732cf32;hpb=eb75a450cceabb83064e079ca4f907bde33b38de diff --git a/src/Tools/YamsPlug/monViewText.py b/src/Tools/YamsPlug/monViewText.py index 478e1833d..3109bfe8a 100644 --- a/src/Tools/YamsPlug/monViewText.py +++ b/src/Tools/YamsPlug/monViewText.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2007-2015 EDF R&D +# Copyright (C) 2007-2016 EDF R&D # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -18,16 +18,26 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -# Modules Python -import string,types,os +import os +import sys +import string +import types +import tempfile import traceback +import pprint as PP #pretty print from qtsalome import * # Import des panels - from ViewText_ui import Ui_ViewExe +verbose = True + +force = os.getenv("FORCE_DISTENE_LICENSE_FILE") +if force != None: + os.environ["DISTENE_LICENSE_FILE"] = force + os.environ["DLIM8VAR"] = "NOTHING" + class MonViewText(Ui_ViewExe, QDialog): """ Classe permettant la visualisation de texte @@ -43,54 +53,73 @@ class MonViewText(Ui_ViewExe, QDialog): self.monExe.readyReadStandardOutput.connect( self.readFromStdOut ) self.monExe.readyReadStandardError.connect( self.readFromStdErr ) - - # Je n arrive pas a utiliser le setEnvironment du QProcess - # fonctionne hors Salome mais pas dans Salome ??? - cmds='' - cmds+='rm -f '+self.parent().fichierOut+'\n' - cmds+=txt+'\n' - cmds+='echo END_OF_Yams\n' - pid=self.monExe.pid() - nomFichier='/tmp/Yams_'+str(pid)+'.sh' - f=open(nomFichier,'w') - f.write(cmds) - f.close() - - maBidouille='sh ' + nomFichier - self.monExe.start(maBidouille) + self.monExe.finished.connect( self.finished ) + + cmds = '' + ext = '' + if sys.platform == "win32": + if os.path.exists(self.parent().fichierOut): + cmds += 'del %s\n' % self.parent().fichierOut + ext = '.bat' + else: + cmds += '#!/bin/bash\n' + cmds += 'pwd\n' + #cmds += 'which mg-surfopt.exe\n' + cmds += 'echo "DISTENE_LICENSE_FILE="$DISTENE_LICENSE_FILE\n' + cmds += 'echo "DLIM8VAR="$DLIM8VAR\n' + cmds += 'rm -f %s\n' % self.parent().fichierOut + ext = '.bash' + + cmds += 'echo %s\n' % txt #to see what is compute command + cmds += txt+'\n' + cmds += 'echo "END_OF_MGSurfOpt"\n' + + nomFichier = os.path.splitext(self.parent().fichierOut)[0] + ext + with open(nomFichier, 'w') as f: + f.write(cmds) + self.make_executable(nomFichier) + + if verbose: print(("INFO: MGSurfOpt launch script file: %s" % nomFichier)) + + self.monExe.start(nomFichier) self.monExe.closeWriteChannel() self.enregistreResultatsDone=False self.show() + def make_executable(self, path): + mode = os.stat(path).st_mode + mode |= (mode & 0o444) >> 2 # copy R bits to X + os.chmod(path, mode) + def saveFile(self): #recuperation du nom du fichier savedir=os.environ['HOME'] fn = QFileDialog.getSaveFileName(None,"Save File",savedir) if fn.isNull() : return - ulfile = os.path.abspath(unicode(fn)) + ulfile = os.path.abspath(str(fn)) try: - f = open(fn, 'wb') - f.write(str(self.TB_Exe.toPlainText())) - f.close() - except IOError, why: - QMessageBox.critical(self, 'Save File', - 'The file %1 could not be saved.
Reason: %2'%(unicode(fn), str(why))) + f = open(fn, 'wb') + f.write(str(self.TB_Exe.toPlainText())) + f.close() + except IOError as why: + QMessageBox.critical(self, 'Save File', + 'The file %1 could not be saved.
Reason: %2'%(str(fn), str(why))) def readFromStdErr(self): a=self.monExe.readAllStandardError() - self.TB_Exe.append(unicode(a.data().encode())) + self.TB_Exe.append(str(a.data().encode())) def readFromStdOut(self) : a=self.monExe.readAllStandardOutput() - aa=unicode(a.data(),len(a)) + aa=str(a.data()) self.TB_Exe.append(aa) - if "END_OF_Yams" in aa: - self.parent().enregistreResultat() - self.enregistreResultatsDone=True - #self.theClose() - - def theClose(self): - if not self.enregistreResultatsDone: + + def finished(self): self.parent().enregistreResultat() self.enregistreResultatsDone=True - self.close() + + def theClose(self): + if not self.enregistreResultatsDone: + self.parent().enregistreResultat() + self.enregistreResultatsDone=True + self.close()