def runProcess(self, args): self.logDb( u"BEFEHL: '%s'" % ( u"' '".join(args) ) ) currout = "" currerr = "" p = QProcess() p.start( args[0], args[1:] ) i=0 while not p.waitForFinished(500): i += 1 self.alive.setText( self.alive.text()[:-1] + ("-\|/")[i%4] ) app.processEvents() currout = self.processOutput( currout, p.readAllStandardOutput() ) currerr = self.processOutput( currerr, p.readAllStandardError() ) if p.state()<>QProcess.Running: if self.canceled: self.log( u"Prozeß abgebrochen." ) break if self.canceled: self.log( u"Prozeß wird abgebrochen." ) p.kill() currout = self.processOutput( currout, p.readAllStandardOutput() ) if currout and currout!="": self.log( "E %s" % currout ) currerr = self.processOutput( currerr, p.readAllStandardError() ) if currerr and currerr!="": self.log( "E %s" % currerr ) ok = False if p.exitStatus()==QProcess.NormalExit: if p.exitCode()==0: ok = True else: self.log( u"Fehler bei Prozeß: %d" % p.exitCode() ) else: self.log( u"Prozeß abgebrochen: %d" % p.exitCode() ) self.logDb( "EXITCODE: %d" % p.exitCode() ) p.close() return ok
def runProcess(self, args): self.logDb(u"BEFEHL: '%s'" % (u"' '".join(args))) currout = "" currerr = "" p = QProcess() p.start(args[0], args[1:]) i = 0 while not p.waitForFinished(500): i += 1 self.alive.setText(self.alive.text()[:-1] + ("-\|/")[i % 4]) app.processEvents() currout = self.processOutput(currout, p.readAllStandardOutput()) currerr = self.processOutput(currerr, p.readAllStandardError()) if p.state() <> QProcess.Running: if self.canceled: self.log(u"Prozeß abgebrochen.") break if self.canceled: self.log(u"Prozeß wird abgebrochen.") p.kill() currout = self.processOutput(currout, p.readAllStandardOutput()) if currout and currout != "": self.log("E %s" % currout) currerr = self.processOutput(currerr, p.readAllStandardError()) if currerr and currerr != "": self.log("E %s" % currerr) ok = False if p.exitStatus() == QProcess.NormalExit: if p.exitCode() == 0: ok = True else: self.log(u"Fehler bei Prozeß: %d" % p.exitCode()) else: self.log(u"Prozeß abgebrochen: %d" % p.exitCode()) self.logDb("EXITCODE: %d" % p.exitCode()) p.close() return ok
def __runPackagingCommand(self, command_line): self.ui.pbCreatePackage.setEnabled(False) try: logger.info("going to run command: {0}".format(command_line)) proc = QProcess() proc.startDetached(command_line) proc.waitForFinished(-1) # note: you are looking here, probably because the PKG command failed, but it wasn't caught - I've noticed that # the waitForFinished() will always return False (the command runs too quick on analysis for example?), and exitStatus() # isn't reliable when a failure occurs anyway. Useless.... if proc.exitStatus() != QProcess.NormalExit: QMessageBox.critical(self, "Packaging Error", "The packaging process failed to finish properly") return False return True finally: self.ui.pbCreatePackage.setEnabled(True)
def __runPackagingCommand(self, command_line): self.ui.pbCreatePackage.setEnabled(False) try: logger.info("going to run command: {0}".format(command_line)) proc = QProcess() proc.startDetached(command_line) proc.waitForFinished(-1) # note: you are looking here, probably because the PKG command failed, but it wasn't caught - I've noticed that # the waitForFinished() will always return False (the command runs too quick on analysis for example?), and exitStatus() # isn't reliable when a failure occurs anyway. Useless.... if proc.exitStatus() != QProcess.NormalExit: QMessageBox.critical( self, "Packaging Error", "The packaging process failed to finish properly") return False return True finally: self.ui.pbCreatePackage.setEnabled(True)
class CFDSTUDYGUI_QProcessDialog(QDialog, Ui_CFDSTUDYGUI_QProcessDialog): """ Advanced dialog. """ def __init__(self, parent, title, cmd_list, obj_directory="", start_directory=""): """ Constructor """ QDialog.__init__(self, parent) Ui_CFDSTUDYGUI_QProcessDialog.__init__(self) self.setupUi(self) self.setWindowTitle(title) self.pushButton.setEnabled(False) if start_directory != None and start_directory != "": os.chdir(start_directory) self.objBr = None if obj_directory != None and obj_directory != "": self.objBr = obj_directory self.proc = QProcess() #env = QProcessEnvironment().systemEnvironment() #self.proc.setProcessEnvironment(env) self.connect(self.proc, SIGNAL('readyReadStandardOutput()'), self.__readFromStdout) self.connect(self.proc, SIGNAL('readyReadStandardError()'), self.__readFromStderr) self.procErrorFlag = False self.cmd_list = cmd_list self.cmd = self.cmd_list.pop(0) cursor = QCursor(Qt.BusyCursor) QApplication.setOverrideCursor(cursor) self.__process() def __process(self): if self.proc.exitStatus() == QProcess.NormalExit and not self.procErrorFlag: self.proc.start(self.cmd) if self.cmd_list: self.cmd = self.cmd_list.pop(0) self.connect(self.proc, SIGNAL('finished(int, QProcess::ExitStatus)'), self.__process) else: self.connect(self.proc, SIGNAL('finished(int, QProcess::ExitStatus)'), self.__finished) def __readFromStdout(self): """ Private slot to handle the readyReadStandardOutput signal of the process. """ if self.proc is None: return self.proc.setReadChannel(QProcess.StandardOutput) while self.proc and self.proc.canReadLine(): ba = self.proc.readLine() if ba.isNull(): return str = QString() s = QString(str.fromUtf8(ba.data()))[:-1] self.logText.append(s) def __readFromStderr(self): """ Private slot to handle the readyReadStandardError signal of the process. """ if self.proc is None: return self.proc.setReadChannel(QProcess.StandardError) while self.proc and self.proc.canReadLine(): ba = self.proc.readLine() if ba.isNull(): return str = QString() s = QString(str.fromUtf8(ba.data()))[:-1] self.logText.append(s.prepend('<font color="red">').append('</font>')) self.procErrorFlag = True def __finished(self): if self.objBr: CFDSTUDYGUI_DataModel.UpdateSubTree(self.objBr) QApplication.restoreOverrideCursor() self.pushButton.setEnabled(True) def event(self, e): if e.type() == 9999: return QDialog.event(self, QCloseEvent()) if e.type() == 9998: return QDialog.event(self, QCloseEvent()) if e.type() == QEvent.Close: e.ignore() return True return QDialog.event(self, e)