diff --git a/externalProgramPathGui.pyw b/externalProgramPathGui.pyw index 8c5f8054473540efa2c8e834304f21aaa4aaa8d8..989470f3c5ba9d84bc3b92416144802109ed4177 100755 --- a/externalProgramPathGui.pyw +++ b/externalProgramPathGui.pyw @@ -5,23 +5,17 @@ ## Qt ## from __future__ import print_function -foundQt=0 try: - from PyQt4.QtCore import * - from PyQt4.QtGui import * - foundQt=4 -except: - pass - -try: - from PyQt5.QtCore import * - from PyQt5.QtGui import * - from PyQt5.QtWidgets import * - foundQt=5 -except: - pass -if not foundQt: - raise Exception("PyQt4/5 not found!") + from PySide2.QtCore import * + from PySide2.QtGui import * + from PySide2.QtWidgets import * +except: + try: + from PyQt5.QtCore import * + from PyQt5.QtGui import * + from PyQt5.QtWidgets import * + except: + raise Exception("PyQt5/PySide2 not found!") #print "PyQt%d (Qt %s) loaded!" % (foundQt, QT_VERSION_STR) diff --git a/launch.py b/launch.py index 9d75e0463b386c61b8797326f93292476103b47b..9a042f41048a7bfebe3aa20ed6526d25398fa9d2 100755 --- a/launch.py +++ b/launch.py @@ -234,16 +234,18 @@ class LaunchJob(ParametricJob): if not os.path.isdir(self.pars['TEST_DIR'].val): print("Error: 'TEST_DIR' %s non existant directory" % self.pars['TEST_DIR'].val) return - asciiname = self.pars['TEST_DIR'].val.encode('ascii','ignore') # convert unicode (from PyQt) - outRun = self.startMultipleTests(asciiname) + #asciiname = self.pars['TEST_DIR'].val.encode('ascii','ignore') # convert unicode (from PyQt) + #outRun = self.startMultipleTests(asciiname) + outRun = self.startMultipleTests(self.pars['TEST_DIR'].val) else: #check if not os.path.isfile(self.pars['TEST_NAME'].val): print("Error: 'TEST_NAME' %s non existant file" % self.pars['TEST_NAME'].val) return #run - asciiname = self.pars['TEST_NAME'].val.encode('ascii','ignore') # convert unicode (from PyQt) - outRun = self.startMultipleTests(asciiname) + #asciiname = self.pars['TEST_NAME'].val #.encode('ascii','ignore') # convert unicode (from PyQt) + #outRun = self.startMultipleTests(asciiname) + outRun = self.startMultipleTests(self.pars['TEST_NAME'].val) ''' if (self.pars['ALGORITHM'].val == "restart" && self.pars['RESTART_STEP'].val > 0): outRun = self.startSingleTest() @@ -304,8 +306,9 @@ class LaunchJob(ParametricJob): print("starting Multiple test at %s (come back later)" % now.ctime()) # opening outfile - self.outFile = open(self.getOutFileName(),"w") - mtfdir, mtfexe = os.path.split(self.pars['EXEC_NAME'].val.encode('ascii','ignore')) + self.outFile = open(self.getOutFileName(),"w") + mtfdir, mtfexe = os.path.split(self.pars['EXEC_NAME'].val) + #mtfdir, mtfexe = os.path.split(self.pars['EXEC_NAME'].val.encode('ascii','ignore')) mtfdir = os.path.abspath(mtfdir) # necessaire pour sge sinon, en local disk, soucis pour trouver libGen4.so # starting python battery if self.launchGui: @@ -337,67 +340,71 @@ class LaunchJob(ParametricJob): pin = p.stdin # filling command to battery - pin.write('import sys, os, os.path\n') + pin.write(b'import sys, os, os.path\n') if self.debug: - pin.write('print ("sys.path = ", sys.path)\n') - pin.write('print ("os.getcwd() = ", os.getcwd())\n') + pin.write(b'print ("sys.path = ", sys.path)\n') + pin.write(b'print ("os.getcwd() = ", os.getcwd())\n') #pin.write("raw_input()\n") - pin.write('if os.path.isdir(r"%s"):\n'%mtfdir) - pin.write('\tsys.path.append(r"%s")\n'%mtfdir) # mtfdir est dorenavant un abspath + print ("mtfdir = ", mtfdir) + print ("type mtfdir = ", type(mtfdir)) + pin.write(('if os.path.isdir(r"%s"):\n'%mtfdir).encode('utf-8')) + #pin.write(('if os.path.isdir(r"%s"):\n'%mtfdir)) + pin.write(('\tsys.path.append(r"%s")\n'%mtfdir).encode('utf-8')) # mtfdir est dorenavant un abspath + #pin.write(('\tsys.path.append(r"%s")\n'%mtfdir)) # mtfdir est dorenavant un abspath #pin.write('\tsys.path.append(os.path.abspath(r"%s"))\n'%mtfdir) - pin.write('else:\n') - pin.write('\tprint ("metafor dir %s not found!")\n'%mtfdir) - pin.write('\tsys.exit()\n\n') - pin.write('exec(open(r"%s").read())\n'%os.path.join(mtfdir,'.pythonrc.py')) - #pin.write('execfile(r"%s")\n'%os.path.join(mtfdir,'.pythonrc.py')) - pin.write('import toolbox.battery as b\n') - pin.write('battery = b.Battery() \n') - pin.write('battery.keepFacs = True\n') - pin.write('battery.dirs = [r"%s"]\n'%tests) + pin.write(b'else:\n') + pin.write(('\tprint ("metafor dir %s not found!")\n'%mtfdir).encode('utf-8')) + pin.write(b'\tsys.exit()\n\n') + pin.write(('exec(open(r"%s").read())\n'%os.path.join(mtfdir,'.pythonrc.py')).encode('utf-8')) + #pin.write(('execfile(r"%s")\n'%os.path.join(mtfdir,'.pythonrc.py')).encode()) + pin.write(b'import toolbox.battery as b\n') + pin.write(b'battery = b.Battery() \n') + pin.write(b'battery.keepFacs = True\n') + pin.write(('battery.dirs = [r"%s"]\n'%tests).encode('utf-8')) if (self.pars['ALGORITHM'].val == "execfile"): reg1=r"(.+)_0*([1-9][0-9]*)\.py" exp1= re.compile(reg1) m = exp1.match(os.path.basename(tests)) if m: # chaining tests - pin.write('battery.addCplxExecPath(r"%s_*")\n'%os.path.join(os.path.dirname(tests), m.group(1))) + pin.write(('battery.addCplxExecPath(r"%s_*")\n'%os.path.join(os.path.dirname(tests), m.group(1))).encode('utf-8')) print('battery.cplx_exec = [r"%s_*"]\n'%os.path.join(os.path.dirname(tests), m.group(1))) else: - pin.write('battery.addCplxExecPath(r"%s")\n'%tests) + pin.write(('battery.addCplxExecPath(r"%s")\n'%tests).encode('utf-8')) print('battery.cplx_exec = [r"%s"]\n'%tests) elif (self.pars['ALGORITHM'].val == "import" ): - pin.write('battery.addCplxImportPath(r"%s")\n'%tests) + pin.write(('battery.addCplxImportPath(r"%s")\n'%tests).encode('utf-8')) print('battery.cplx_import = [r"%s"]\n'%tests) elif (self.pars['ALGORITHM'].val == "restart" ): - pin.write('battery.addRestartPath(r"%s")\n'%tests) + pin.write(('battery.addRestartPath(r"%s")\n'%tests).encode('utf-8')) print('battery.restart = [r"%s"]\n'%tests) - pin.write('battery.verifsrc = "verif"\n') - pin.write('battery.codes = [ "FAILED", "STP", "ITE", "INW", "EXT", "EXW", "LKS", "CPU", "MEM" ]\n') + pin.write(b'battery.verifsrc = "verif"\n') + pin.write(b'battery.codes = [ "FAILED", "STP", "ITE", "INW", "EXT", "EXW", "LKS", "CPU", "MEM" ]\n') if ((self.pars['RUNMETHOD'].val == 'sge' or self.pars['RUNMETHOD'].val == 'slurm') and self.pars['LOCALDISK'].val == True): - pin.write('battery.setWDRoot("%s")\n'%self.getLocalDiskDir(self.jobId)) + pin.write(('battery.setWDRoot("%s")\n'%self.getLocalDiskDir(self.jobId)).encode('utf-8')) if self.pars['RUNMETHOD'].val != 'sge' and self.pars['RUNMETHOD'].val != 'slurm': if self.pars['AFFINITY'].val != '': - pin.write('battery.setAffinity("%s")\n'%self.pars['AFFINITY'].val) + pin.write(('battery.setAffinity("%s")\n'%self.pars['AFFINITY'].val).encode('utf-8')) if self.pars['NICE_VALUE'].val != '0': #print ('battery.setNice(%s)\n'%self.pars['NICE_VALUE'].val) - pin.write('battery.setNice(%s)\n'%self.pars['NICE_VALUE'].val) + pin.write(('battery.setNice(%s)\n'%self.pars['NICE_VALUE'].val).encode('utf-8')) - pin.write('battery.setNumTasks(%s)\n'%self.pars['NB_TASKS'].val) - pin.write('battery.setNumThreads(%s)\n'%self.pars['NB_THREADS'].val) - pin.write('battery.mtfdir = r"%s"\n'%mtfdir) + pin.write(('battery.setNumTasks(%s)\n'%self.pars['NB_TASKS'].val).encode('utf-8')) + pin.write(('battery.setNumThreads(%s)\n'%self.pars['NB_THREADS'].val).encode('utf-8')) + pin.write(('battery.mtfdir = r"%s"\n'%mtfdir).encode('utf-8')) if self.pars['ALGORITHM'].val == 'clean': - pin.write('battery.start("clean")\n') + pin.write(b'battery.start("clean")\n') elif self.pars['ALGORITHM'].val == 'verif': - pin.write('battery.verif()\n') + pin.write(b'battery.verif()\n') else: - pin.write('battery.start("run")\n') + pin.write(b'battery.start("run")\n') #pin.write('battery.verif()\n') # pas très utile dans le cadre de launch ou faudrait faire un verif + malin) # write to exit python at the end of job - pin.write('quit()\n') + pin.write(b'quit()\n') # wait for process to finish if self.launchGui: diff --git a/launchGui.pyw b/launchGui.pyw index 936fa7c2f29dbe7c6e8dc2d83311cb215aec57b7..ba06f61baf1622b33affefedc34bcaa979eae666 100755 --- a/launchGui.pyw +++ b/launchGui.pyw @@ -327,27 +327,16 @@ class LaunchGui(QWidget): for var in self.sf: self.sf[var].setEnabled(self.launch.pars[var].enabled) - @pyqtSlot() + #@pyqtSlot() def readStdOutput(self): - out = self.process.readAllStandardOutput() - ''' - if self.launch.outFile: - self.launch.outFile.write(repr(out)) - self.launch.outFile.write("\n") - ''' - if foundQt==4: - out = QString(out) - else: - out = str(out).encode('utf8') - ''' - if self.launch.outFile: - self.launch.outFile.write(repr(out)) - self.launch.outFile.write("\n") - ''' + out = self.process.readAllStandardOutput() + print ("out = ", out) + print ("type out = ", type(out)) + out = str(out)#.encode('utf8') out = out.replace('>>> >>> ... ... ... ... ... >>>','') out = out.replace('>>> ','') out = out.replace('\r\n','\n') - self.write(out) + self.write(out.encode('utf-8')) #self.console.append(QString(out)) ''' self.console.moveCursor (QTextCursor.End) diff --git a/postProLoopGui.pyw b/postProLoopGui.pyw index 9dd2609deab122cc94e88975c930f2f9a0e3180e..ef1b5d097eaae753581b4026ae20de24d11c7011 100755 --- a/postProLoopGui.pyw +++ b/postProLoopGui.pyw @@ -8,27 +8,19 @@ ## Qt ## from __future__ import print_function -foundQt=0 try: - from PyQt4.QtCore import * - from PyQt4.QtGui import * - foundQt=4 -except: - pass - -try: - from PyQt5.QtCore import * - from PyQt5.QtGui import * - from PyQt5.QtWidgets import * - foundQt=5 -except: - pass -if not foundQt: - raise Exception("PyQt4/5 not found!") + from PySide2.QtCore import * + from PySide2.QtGui import * + from PySide2.QtWidgets import * +except: + try: + from PyQt5.QtCore import * + from PyQt5.QtGui import * + from PyQt5.QtWidgets import * + except: + raise Exception("PyQt5/PySide2 not found!") #print "PyQt%d (Qt %s) loaded!" % (foundQt, QT_VERSION_STR) - - from prmClassesGui import * from postProLoop import * diff --git a/prmClasses.py b/prmClasses.py index 1578916a16416947c4274027af2d8cff03569aa6..a20a80138c6f504d7e58e32d34e6cdec4733f617 100644 --- a/prmClasses.py +++ b/prmClasses.py @@ -268,7 +268,7 @@ class _GetchWindows(object): import msvcrt def __call__(self): import msvcrt - return msvcrt.getch() + return msvcrt.getch().decode() # -- variable globale -- getch = _Getch() diff --git a/prmClassesGui.py b/prmClassesGui.py index ad2743caa468c16788c0d7a143d733da9226d068..847ed65973992ae3a822fd0cd860daa6bac54cd6 100644 --- a/prmClassesGui.py +++ b/prmClassesGui.py @@ -9,24 +9,20 @@ from builtins import object import os,sys ## Qt ## -foundQt=0 -coding='latin-1' +#coding='latin-1' +coding='utf-8' try: - from PyQt4.QtCore import * - from PyQt4.QtGui import * - foundQt=4 -except: - pass + from PySide2.QtCore import * + from PySide2.QtGui import * + from PySide2.QtWidgets import * +except: + try: + from PyQt5.QtCore import * + from PyQt5.QtGui import * + from PyQt5.QtWidgets import * + except: + raise Exception("PyQt5/PySide2 not found!") -try: - from PyQt5.QtCore import * - from PyQt5.QtGui import * - from PyQt5.QtWidgets import * - foundQt=5 -except: - pass -if not foundQt: - raise Exception("PyQt4/5 not found!") #print "PyQt%d (Qt %s) loaded!" % (foundQt, QT_VERSION_STR) import distutils.spawn @@ -84,10 +80,8 @@ class TextLine(PRMLine): self.setEnabled(self.param.enabled) def action(self): - if foundQt==4: - self.param.val = self.lineEdt.text().toLatin1().data() - else: - self.param.val = self.lineEdt.text().encode(coding) + #self.param.val = self.lineEdt.text().encode(coding) + self.param.val = self.lineEdt.text() #print opt.key,'=',opt.val # update widgets visibility according to enable/disable self.win.updateWidgetsVisibility() @@ -132,13 +126,11 @@ class PathLine(PRMLine): def action(self, dir): if dir: - if foundQt==4: - self.param.val = dir.toLatin1().data().replace('/',os.sep) - self.lineEdt.setText(dir) - else: - #print "PathLine.action:dir=", dir - self.param.val = dir.encode(coding).replace('/',os.sep) - self.lineEdt.setText(self.param.val.decode(coding)) + #print "PathLine.action:dir=", dir + #self.param.val = dir.encode(coding).replace('/',os.sep) + self.param.val = dir.replace('/',os.sep) + #self.lineEdt.setText(self.param.val.decode(coding)) + self.lineEdt.setText(self.param.val) #print self.param.key,'=',self.param.val # update widgets visibility according to enable/disable self.checkValidity() @@ -195,17 +187,14 @@ class FileLine(PRMLine): def btAction(self): file = QFileDialog.getOpenFileName(self.win, "Choose %s file" % self.param.key, self.param.val, self.fileType) - if foundQt>4: file=file[0] # en PyQt5 retourne (filename, filter) - self.action(file) + self.action(file[0]) # en PyQt5 retourne (filename, filter) def action(self, file): if file: - if foundQt==4: - self.param.val = file.toLatin1().data().replace('/', os.sep) - self.lineEdt.setText(file) - else: - self.param.val = file.encode(coding).replace('/', os.sep) - self.lineEdt.setText(self.param.val.decode(coding)) + #self.param.val = file.encode(coding).replace('/', os.sep) + self.param.val = file.replace('/', os.sep) + #self.lineEdt.setText(self.param.val.decode(coding)) + self.lineEdt.setText(self.param.val) #print "FileLine.action:", self.param.key,'=',self.param.val self.checkValidity() # update widgets visibility according to enable/disable @@ -269,10 +258,8 @@ class MultiPMRLine(PRMLine): self.setEnabled(self.param.enabled) def action(self): - if foundQt==4: - self.param.val = self.comboBox.currentText().toLatin1().data() - else: - self.param.val = self.comboBox.currentText().encode(coding) + #self.param.val = self.comboBox.currentText().encode(coding) + self.param.val = self.comboBox.currentText() #print self.param.val self.win.updateWidgetsVisibility() self.win.updateWidgetsValues() @@ -316,11 +303,9 @@ class MultiPathLine(PRMLine): def cbIndexChangeAction(self): dir = self.comboBox.currentText() - if foundQt==4: - val = dir.toLatin1().data().replace('/',os.sep) - else: - #print "cbIndexChangeAction:dir=",dir - val = dir.encode(coding).replace('/',os.sep) + #print "cbIndexChangeAction:dir=",dir + #val = dir.encode(coding).replace('/',os.sep) + val = dir.replace('/',os.sep) self.param.val = val if val in self.param.vals: # bidouille pour que la nouvelle valeur soit unique et toujours en premiere position self.param.vals.remove(val) @@ -364,7 +349,8 @@ class MultiPathLine(PRMLine): self.win.updateWidgetsValues() def setParamValue(self): - idx = self.comboBox.findText(self.param.val.decode(coding)) + #idx = self.comboBox.findText(self.param.val.decode(coding)) + idx = self.comboBox.findText(self.param.val) self.comboBox.setCurrentIndex(idx) def setEnabled(self, enable):