Example #1
0
    def start(self):
        command = self.compileCommand()
        ctx.field('debugCommandline').value = ' '.join(map(escapeShellArg, command))
        
        self.saveInputImages()

        self.errorDescription = None
        self.stdout, self.stdoutFilename = arg.mkstemp('.stdout')
        self.stderr, self.stderrFilename = arg.mkstemp('.stderr')
        self.process = popenCLIExecutable(command, stdout = self.stdout, stderr = self.stderr,
                                          env = mlabFreeEnvironment())
        return self.process
Example #2
0
def doImport(field = None, window = None):
    importPaths = [ctx.expandFilename(os.path.expanduser(path))
                   for path in _importPathsAsList()]
    
    targetDirectory = ctx.expandFilename(os.path.expanduser(
            ctx.field('targetDirectory').value))
    if not os.path.exists(targetDirectory):
        os.mkdir(targetDirectory)
    if not os.path.exists(os.path.join(targetDirectory, "mhelp")):
        os.mkdir(os.path.join(targetDirectory, "mhelp"))

    generateScreenshots = ctx.field('generatePanelScreenshots').value
        
    pd = QtGui.QProgressDialog(window.widget() if window else None)
    pd.setWindowModality(Qt.Qt.WindowModal)
     
    for index, successful, total, path in cli_to_macro.importAllCLIs(
            importPaths, targetDirectory,
            includePanelScreenshots = generateScreenshots,
            env = mlabFreeEnvironment(),
            unexpandFilename = ctx.unexpandFilename):
        if path:
            print("%d/%d importing %s..." % (index+1, total, path))
        pd.setValue(index)
        pd.setMaximum(total)
        if path:
            pd.setLabelText(os.path.basename(path))
        if pd.wasCanceled:
            break

    if not pd.wasCanceled:
        if successful:
            if generateScreenshots:
                pd.setLabelText("Generating screenshots...")
                ctx.field('MLABModuleHelp2Html.directory').value = targetDirectory
                ctx.field('MLABModuleHelp2Html.createScreenshots').touch()

            # TODO: use MLAB.priv().reloadModules() instead?
            QtGui.QMessageBox.information(
                pd, "Done" if (successful == total) else "Done (with errors)",
                "%s modules successfully imported. "
                "You probably need to reload the module database (via the 'Extras' menu) now."
                % ("All %d" % total if (successful == total)
                   else "%d out of %d modules" % (successful, total), ))
            if window and (successful == total):
                window.close()
        else:
            if not total:
                QtGui.QMessageBox.critical(
                    pd, "Import Failed",
                    "%d CLI modules found, but none could be imported.  Check the log for details." % total
                    if total else
                    "No CLI modules found in the given directories.")