Пример #1
0
    def threadFinished(self, status):
        if self.thread.task == DEPENDENCY_CHECK:
            QApplication.restoreOverrideCursor()

        elif self.thread.task == DOWNLOAD_GNUPLOTPY:
            self.consoleMessage("Attempting to install Gnuplot-py package:")

            if platform.system() == 'Windows':
                python_exe = os.path.join(FreeCAD.getHomePath(), 'bin',
                                          'python.exe')
            else:
                python_exe = 'python'
            cmd = [python_exe, '-u', 'setup.py', 'install']

            working_dir = os.path.join(tempfile.gettempdir(),
                                       GNUPLOTPY_FILE_BASE)
            self.install_process = CfdConsoleProcess.CfdConsoleProcess(
                finishedHook=self.installFinished)
            print("Running {} in {}".format(' '.join(cmd), working_dir))

            self.install_process.start(cmd, working_dir=working_dir)
            if not self.install_process.waitForStarted():
                self.consoleMessage("Unable to run command " + ' '.join(cmd),
                                    '#FF0000')

        elif self.thread.task == DOWNLOAD_CFMESH:
            if status:
                self.consoleMessage("Download completed")
                user_dir = self.thread.user_dir
                self.consoleMessage(
                    "Building cfMesh. Lengthy process - please wait...")
                if CfdFoamTools.getFoamRuntime() == "BlueCFD":
                    script_name = "buildCfMeshOnBlueCFD.sh"
                    self.consoleMessage("Log file: {}\\log.{}".format(
                        user_dir, script_name))
                    shutil.copy(
                        os.path.join(CfdTools.getModulePath(), 'data',
                                     script_name),
                        os.path.join(user_dir, script_name))
                    self.install_process = CfdFoamTools.startFoamApplication(
                        "./" + script_name, "$WM_PROJECT_USER_DIR",
                        self.installFinished)
                else:
                    self.consoleMessage("Log file: {}/{}/log.Allwmake".format(
                        user_dir, CFMESH_FILE_BASE))
                    self.install_process = CfdFoamTools.startFoamApplication(
                        "./Allwmake",
                        "$WM_PROJECT_USER_DIR/" + CFMESH_FILE_BASE,
                        self.installFinished)
            else:
                self.consoleMessage("Download unsuccessful")
Пример #2
0
 def __init__(self):
     self.process = CfdConsoleProcess.CfdConsoleProcess(
         stdoutHook=self.readOutput, stderrHook=self.readOutput)
     self.output = ""
Пример #3
0
    if log_name == '':
        app = cmds[0].rsplit('/', 1)[-1]
        logFile = "log.{}".format(app)
    else:
        logFile = log_name

    cmdline = ' '.join(cmds)  # Space to separate options
    # Pipe to log file and terminal
    if logFile:
        cmdline += " 1> >(tee -a " + logFile + ") 2> >(tee -a " + logFile + " >&2)"
        # Tee appends to the log file, so we must remove first. Can't do directly since
        # paths may be specified using variables only available in foam runtime environment.
        cmdline = "{{ rm {}; {}; }}".format(logFile, cmdline)

    proc = CfdConsoleProcess.CfdConsoleProcess(finishedHook=finishedHook,
                                               stdoutHook=stdoutHook,
                                               stderrHook=stderrHook)
    if logFile:
        print("Running ", ' '.join(cmds), " -> ", logFile)
    else:
        print("Running ", ' '.join(cmds))
    proc.start(makeRunCommand(cmdline, case), env_vars=getRunEnvironment())
    if not proc.waitForStarted():
        raise Exception("Unable to start command " + ' '.join(cmds))
    return proc


def runFoamApplication(cmd, case, log_name=''):
    """ Same as startFoamApplication, but waits until complete. Returns exit code. """
    proc = startFoamApplication(cmd, case, log_name)
    proc.waitForFinished()