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.")
import logging, sys, glob #logging.basicConfig(format=' %(asctime)s %(message)s') #logging.basicConfig(filename = 'warnings.txt', level = 0) logging.basicConfig(stream = sys.stdout, level = 0) # easy grep'ping import cli_to_macro args = sys.argv[1:] or ['/Applications/Slicer.app/Contents/lib/Slicer-4.2/cli-modules'] for index, total, path in cli_to_macro.importAllCLIs(args, 'mdl'): print "%d/%d importing %s..." % (index, total, path)