Example #1
0
    def run(self):
        if not self.settings.value("openfoam/path"):
            self.window.console.write_error("Path to OpenFOAM is not set")
            return

        if not self.case.path:
            self.window.console.write_error("Shampoo project is not saved")
            return

        self.case.save()

        path = os.path.join(self.settings.value("openfoam/path"), "etc/bashrc")
        commands = "source {0}\n{1}\n".format(
                path,
                "blockMesh")

        program_name = "/bin/bash"
        logging.info("Running %s", "blockMesh")
        process = QProcess()
        self.window.console.set_process(process)
        process.setWorkingDirectory(self.case.path)
        process.start(program_name)
        process.write(commands)
        process.closeWriteChannel()
Example #2
0
class PluginProcessBase(QObject):
    proc_list = []

    def __init__(self, wdir):
        QObject.__init__(self)

        PluginProcess.proc_list.append(self)
        self.is_rebuild = False
        self.is_query_fl = False

        self.sig = QuerySignal()

        self.proc = QProcess()
        self.proc.finished.connect(self._finished_cb)
        self.proc.error.connect(self._error_cb)

        self.proc.setWorkingDirectory(wdir)
        self.wdir = wdir

    def _cleanup(self):
        PluginProcess.proc_list.remove(self)
        if self.err_str != '':
            s = '<b>' + self.p_cmd + '</b><p>' + '<p>'.join(
                self.err_str.splitlines())
            QMessageBox.warning(None, "Seascope", s, QMessageBox.Ok)
        if self.res != '':
            s = '<b>' + self.p_cmd + '</b><p>Summary<p>' + self.res
            QMessageBox.information(None, "Seascope", s, QMessageBox.Ok)

    def _error_cb(self, err):
        err_dict = {
            QProcess.FailedToStart: 'FailedToStart',
            QProcess.Crashed: 'Crashed',
            QProcess.Timedout: 'The last waitFor...() function timed out',
            QProcess.WriteError:
            'An error occurred when attempting to write to the process',
            QProcess.ReadError:
            'An error occurred when attempting to read from the process',
            QProcess.UnknownError: 'An unknown error occurred',
        }
        self.err_str = '<b>' + self.p_cmd + '</b><p>' + err_dict[err]
        self._cleanup()

    def _finished_cb(self, ret):
        res = str(self.proc.readAllStandardOutput())
        self.err_str = str(self.proc.readAllStandardError())

        #print 'output', res
        #print 'cmd:', self.p_cmd
        if self.is_rebuild:
            self.res = res
            self.sig.sig_rebuild.emit()
        elif self.is_query_fl:
            self.res = ''
            res = self.parse_query_fl(res)
            self.sig.sig_query_fl.emit(res)
        else:
            self.res = ''
            self.sig.sig_result_dbg.emit(self.p_cmd, res, self.err_str)
            try:
                res = self.parse_result(res, self.sig)
            except Exception as e:
                print e
                res = [[
                    '', '', '', 'error while parsing output of: ' + self.p_cmd
                ]]
            if res != None:
                self.sig.emit_result(res)

        self._cleanup()

    def run_query_process(self, pargs, sym, rquery=None):
        self.sig.sym = sym
        self.sig.rquery = rquery
        self.p_cmd = ' '.join(pargs)
        if os.getenv('SEASCOPE_DEBUG'):
            print self.p_cmd
        self.proc.start(pargs[0], pargs[1:])
        if self.proc.waitForStarted() == False:
            return None
        self.proc.closeWriteChannel()
        return [self.sig.sig_result, self.sig.sig_result_dbg]

    def run_rebuild_process(self, pargs):
        self.is_rebuild = True
        self.p_cmd = ' '.join(pargs)
        self.proc.start(pargs[0], pargs[1:])
        if self.proc.waitForStarted() == False:
            return None
        #print 'cmd:', pargs
        self.sig.sig_rebuild.connect(CtagsCache.flush)
        return self.sig.sig_rebuild

    def run_query_fl(self, pargs):
        self.is_query_fl = True
        self.p_cmd = ' '.join(pargs)
        self.proc.start(pargs[0], pargs[1:])
        if self.proc.waitForStarted() == False:
            return None
        return self.sig.sig_query_fl

    def parse_query_fl(self, text):
        fl = []
        for f in re.split('\r?\n', text.strip()):
            if f == '':
                continue
            fl.append(os.path.join(self.wdir, f))
        return fl
Example #3
0
class PluginProcessBase(QObject):
	proc_list = []

	def __init__(self, wdir):
		QObject.__init__(self)
		
		PluginProcess.proc_list.append(self)
		self.is_rebuild = False
		self.is_query_fl = False

		self.sig = QuerySignal()

		self.proc = QProcess()
		self.proc.finished.connect(self._finished_cb)
		self.proc.error.connect(self._error_cb)

		self.proc.setWorkingDirectory(wdir)
		self.wdir = wdir

	def _cleanup(self):
		PluginProcess.proc_list.remove(self)
		if self.err_str != '':
			s = '<b>' + self.p_cmd + '</b><p>' + '<p>'.join(self.err_str.splitlines())
			QMessageBox.warning(None, "Seascope", s, QMessageBox.Ok)
		if self.res != '':
			s = '<b>' + self.p_cmd + '</b><p>Summary<p>' + self.res
			QMessageBox.information(None, "Seascope", s, QMessageBox.Ok)

	def _error_cb(self, err):
		err_dict = { 
			QProcess.FailedToStart:	'FailedToStart',
			QProcess.Crashed:	'Crashed',
			QProcess.Timedout:	'The last waitFor...() function timed out',
			QProcess.WriteError:	'An error occurred when attempting to write to the process',
			QProcess.ReadError:	'An error occurred when attempting to read from the process',
			QProcess.UnknownError:	'An unknown error occurred',
		}
		self.err_str = '<b>' + self.p_cmd + '</b><p>' + err_dict[err]
		self._cleanup()

	def _finished_cb(self, ret):
		res = str(self.proc.readAllStandardOutput())
		self.err_str = str(self.proc.readAllStandardError())
		
		#print 'output', res
		#print 'cmd:', self.p_cmd
		if self.is_rebuild:
			self.res = res
			self.sig.sig_rebuild.emit()
		elif self.is_query_fl:
			self.res = ''
			res = self.parse_query_fl(res)
			self.sig.sig_query_fl.emit(res)
		else:
			self.res = ''
			self.sig.sig_result_dbg.emit(self.p_cmd, res, self.err_str)
			try:
				res = self.parse_result(res, self.sig)
			except Exception as e:
				print e
				res = [['', '', '', 'error while parsing output of: ' + self.p_cmd]]
			if res != None:
				self.sig.emit_result(res)

		self._cleanup()

	def run_query_process(self, pargs, sym, rquery=None):
		self.sig.sym = sym
		self.sig.rquery = rquery
		self.p_cmd = ' '.join(pargs)
		if os.getenv('SEASCOPE_DEBUG'):
			print self.p_cmd
		self.proc.start(pargs[0], pargs[1:])
		if self.proc.waitForStarted() == False:
			return None
		self.proc.closeWriteChannel()
		return [self.sig.sig_result, self.sig.sig_result_dbg]

	def run_rebuild_process(self, pargs):
		self.is_rebuild = True
		self.p_cmd = ' '.join(pargs)
		self.proc.start(pargs[0], pargs[1:])
		if self.proc.waitForStarted() == False:
			return None
		#print 'cmd:', pargs
		self.sig.sig_rebuild.connect(CtagsCache.flush)
		return self.sig.sig_rebuild

	def run_query_fl(self, pargs):
		self.is_query_fl = True
		self.p_cmd = ' '.join(pargs)
		self.proc.start(pargs[0], pargs[1:])
		if self.proc.waitForStarted() == False:
			return None
		return self.sig.sig_query_fl

	def parse_query_fl(self, text):
		fl = []
		for f in re.split('\r?\n', text.strip()):
			if f == '':
				continue
			fl.append(os.path.join(self.wdir, f))
		return fl