def testExportSteps(self): manager = Manager() stepsStats = dict() for project in manager.listProjects(): projectFolder = manager.getProjectPath(project.projName) project = Project(pyworkflow.Config.getDomain(), projectFolder) project.load() for prot in project.getRuns(): protName = prot.getClassName() for step in prot.loadSteps(): stepName = "-".join([ prot.getClassPackageName(), protName, step.funcName.get() ]) stepSeconds = step.getElapsedTime().total_seconds() if stepName not in stepsStats: stepsStats[stepName] = [] stepsStats[stepName].append(stepSeconds) # average steps for name in stepsStats: plugin, protClass, step = name.split("-") stepStats = stepsStats[name] mean = sum(stepStats) / len(stepStats) # DO not send mean values if higher than a threshold to keep chart in a decent visualization range # We are loosing long duration steps, probably due to large if mean < 30: bm = Benchmark(time=mean, name="-".join([protClass, step])) codespeed.sendData(bm)
# Create a new project manager = Manager() if not manager.hasProject(projName): usage("There is no project with this name: %s" % pwutils.red(projName)) # the project may be a soft link which may be unavailable to the cluster so get the real path try: projectPath = os.readlink(manager.getProjectPath(projName)) except: projectPath = manager.getProjectPath(projName) project = Project(pw.Config.getDomain(), projectPath) project.load() runs = project.getRuns() # Now assuming that there is no dependencies between runs # and the graph is lineal for prot in runs: protClassName = prot.getClassName() protLabelName = prot.getObjLabel() if (protClassName not in sys.argv[3:] and protLabelName not in sys.argv[3:]): project.scheduleProtocol(prot) # Wait 1 seconds to avoid concurrent activity time.sleep(0.7) else: print(pwutils.blueStr("\nNot scheduling '%s' protocol named '%s'.\n"
class ProjectWindow(ProjectBaseWindow): """ Main window for working in a Project. """ _OBJECT_COMMANDS = {} def __init__(self, path, master=None): # Load global configuration self.projName = os.path.basename(path) try: projTitle = '%s (%s on %s)' % (self.projName, pwutils.getLocalUserName(), pwutils.getLocalHostName()) except Exception: projTitle = self.projName self.projPath = path self.loadProject() # TODO: put the menu part more nicely. From here: menu = MenuConfig() projMenu = menu.addSubMenu('Project') projMenu.addSubMenu('Browse files', 'browse', icon='fa-folder-open.png') projMenu.addSubMenu('Remove temporary files', 'delete', icon='fa-trash-o.png') projMenu.addSubMenu('Manage project labels', 'labels', icon=Icon.TAGS) projMenu.addSubMenu('Toogle color mode', 'color_mode', shortCut="Ctrl+t", icon=Icon.ACTION_VISUALIZE) projMenu.addSubMenu('Select all protocols', 'select all', shortCut="Ctrl+a") projMenu.addSubMenu('Find protocol to add', 'find protocol', shortCut="Ctrl+f") projMenu.addSubMenu('', '') # add separator projMenu.addSubMenu('Import workflow', 'load_workflow', icon='fa-download.png') projMenu.addSubMenu('Export tree graph', 'export_tree') projMenu.addSubMenu('', '') # add separator projMenu.addSubMenu('Notes', 'notes', icon='fa-pencil.png') projMenu.addSubMenu('', '') # add separator projMenu.addSubMenu('Exit', 'exit', icon='fa-sign-out.png') helpMenu = menu.addSubMenu('Help') helpMenu.addSubMenu('Online help', 'online_help', icon='fa-external-link.png') helpMenu.addSubMenu('About', 'about', icon='fa-question-circle.png') helpMenu.addSubMenu('Contact support', 'contact_us', icon='fa-question-circle.png') self.menuCfg = menu # TODO: up to here if self.project.openedAsReadOnly(): self.projName += "<READ ONLY>" # Notify about the workflow in this project self.icon = self.generalCfg.icon.get() self.selectedProtocol = None self.showGraph = False Plotter.setBackend('TkAgg') ProjectBaseWindow.__init__(self, projTitle, master, icon=self.icon, minsize=(90, 50)) self.root.attributes("-zoomed", True) self.switchView(VIEW_PROTOCOLS) self.initProjectTCPServer( ) # Socket thread to communicate with clients from notifier import ProjectNotifier ProjectNotifier(self.project).notifyWorkflow() def createHeaderFrame(self, parent): """Create the header and add the view selection frame at the right.""" header = ProjectBaseWindow.createHeaderFrame(self, parent) self.addViewList(header) return header def getSettings(self): return self.settings def saveSettings(self): self.settings.write() def _onClosing(self): try: if not self.project.openedAsReadOnly(): self.saveSettings() except Exception as ex: print("%s %s" % (Message.NO_SAVE_SETTINGS, str(ex))) ProjectBaseWindow._onClosing(self) def loadProject(self): self.project = Project(self.projPath) self.project.load() # Check if we have settings.sqlite, generate if not settingsPath = os.path.join(self.project.path, self.project.settingsPath) if os.path.exists(settingsPath): self.settings = self.project.getSettings() else: print( 'Warning: settings.sqlite not found! Creating default settings..' ) self.settings = self.project.createSettings() self.generalCfg = self.settings.getConfig() self.protCfg = self.project.getCurrentProtocolView() # The next functions are callbacks from the menu options. # See how it is done in pyworkflow/gui/gui.py:Window._addMenuChilds() # def onBrowseFiles(self): # Project -> Browse files FileBrowserWindow( "Browse Project files", self, self.project.getPath(''), selectButton=None # we will select nothing ).show() def onNotes(self): if not all(var in os.environ for var in [ 'SCIPION_NOTES_PROGRAM', 'SCIPION_NOTES_FILE', 'SCIPION_NOTES_ARGS' ]): return self.showError( "Missing variables SCIPION_NOTES_* under\n" "[VARIABLES] section in the configuration file\n" "~/.config/scipion/scipion.conf") args = [] # Program name program = os.environ.get('SCIPION_NOTES_PROGRAM', None) notesFile = self.project.getPath('Logs', os.environ['SCIPION_NOTES_FILE']) if program: args.append(program) # Custom arguments if os.environ.get('SCIPION_NOTES_ARGS', None): args.append(os.environ['SCIPION_NOTES_ARGS']) args.append(notesFile) subprocess.Popen(args) #nonblocking else: openTextFileEditor(notesFile) def onRemoveTemporaryFiles(self): # Project -> Remove temporary files tmpPath = os.path.join(self.project.path, self.project.tmpPath) n = 0 try: for fname in os.listdir(tmpPath): fpath = "%s/%s" % (tmpPath, fname) if os.path.isfile(fpath): os.remove(fpath) n += 1 # TODO: think what to do with directories. Delete? Report? self.showInfo("Deleted content of %s -- %d file(s)." % (tmpPath, n)) except Exception as e: self.showError(str(e)) def _loadWorkflow(self, obj): try: self.project.loadProtocols(obj.getPath()) self.getViewWidget().updateRunsGraph(True, reorganize=True) except Exception, ex: self.showError(str(ex))
def loadProjectFromPath(projectPath): project = Project(projectPath) project.load() return project
class ProjectWindow(ProjectBaseWindow): """ Main window for working in a Project. """ _OBJECT_COMMANDS = {} def __init__(self, path, master=None): # Load global configuration self.projName = os.path.basename(path) try: projTitle = '%s (%s on %s)' % (self.projName, pwutils.getLocalUserName(), pwutils.getLocalHostName()) except Exception: projTitle = self.projName self.projPath = path self.loadProject() # TODO: put the menu part more nicely. From here: menu = MenuConfig() projMenu = menu.addSubMenu('Project') projMenu.addSubMenu('Browse files', 'browse', icon='fa-folder-open.png') projMenu.addSubMenu('Remove temporary files', 'delete', icon='fa-trash-o.png') projMenu.addSubMenu('Manage project labels', 'labels', icon=Icon.TAGS) projMenu.addSubMenu('Toogle color mode', 'color_mode', shortCut="Ctrl+t", icon=Icon.ACTION_VISUALIZE) projMenu.addSubMenu('Select all protocols', 'select all', shortCut="Ctrl+a") projMenu.addSubMenu('Find protocol to add', 'find protocol', shortCut="Ctrl+f") projMenu.addSubMenu('', '') # add separator projMenu.addSubMenu('Import workflow', 'load_workflow', icon='fa-download.png') projMenu.addSubMenu('Search workflow', 'search_workflow', icon = 'fa-search.png') projMenu.addSubMenu('Export tree graph', 'export_tree') projMenu.addSubMenu('', '') # add separator projMenu.addSubMenu('Notes', 'notes', icon='fa-pencil.png') projMenu.addSubMenu('', '') # add separator projMenu.addSubMenu('Exit', 'exit', icon='fa-sign-out.png') helpMenu = menu.addSubMenu('Help') helpMenu.addSubMenu('Online help', 'online_help', icon='fa-external-link.png') helpMenu.addSubMenu('About', 'about', icon='fa-question-circle.png') helpMenu.addSubMenu('Contact support', 'contact_us', icon='fa-question-circle.png') self.menuCfg = menu # TODO: up to here if self.project.openedAsReadOnly(): self.projName += "<READ ONLY>" # Notify about the workflow in this project self.icon = self.generalCfg.icon.get() self.selectedProtocol = None self.showGraph = False Plotter.setBackend('TkAgg') ProjectBaseWindow.__init__(self, projTitle, master, icon=self.icon, minsize=(90,50)) self.root.attributes("-zoomed", True) self.switchView(VIEW_PROTOCOLS) self.initProjectTCPServer() # Socket thread to communicate with clients ProjectWorkflowNotifier(self.project).notifyWorkflow() def createHeaderFrame(self, parent): """Create the header and add the view selection frame at the right.""" header = ProjectBaseWindow.createHeaderFrame(self, parent) self.addViewList(header) return header def getSettings(self): return self.settings def saveSettings(self): self.settings.write() def _onClosing(self): try: if not self.project.openedAsReadOnly(): self.saveSettings() except Exception as ex: print("%s %s" %(Message.NO_SAVE_SETTINGS, str(ex)) ) ProjectBaseWindow._onClosing(self) def loadProject(self): self.project = Project(self.projPath) self.project.load() # Check if we have settings.sqlite, generate if not settingsPath = os.path.join(self.project.path, self.project.settingsPath) if os.path.exists(settingsPath): self.settings = self.project.getSettings() else: print('Warning: settings.sqlite not found! Creating default settings..') self.settings = self.project.createSettings() self.generalCfg = self.settings.getConfig() self.protCfg = self.project.getCurrentProtocolView() # The next functions are callbacks from the menu options. # See how it is done in pyworkflow/gui/gui.py:Window._addMenuChilds() # def onBrowseFiles(self): # Project -> Browse files FileBrowserWindow("Browse Project files", self, self.project.getPath(''), selectButton=None # we will select nothing ).show() def onNotes(self): if not all(var in os.environ for var in ['SCIPION_NOTES_PROGRAM', 'SCIPION_NOTES_FILE', 'SCIPION_NOTES_ARGS']): return self.showError("Missing variables SCIPION_NOTES_* under\n" "[VARIABLES] section in the configuration file\n" "~/.config/scipion/scipion.conf") args = [] # Program name program = os.environ.get('SCIPION_NOTES_PROGRAM', None) notesFile = self.project.getPath('Logs', os.environ['SCIPION_NOTES_FILE']) if program: args.append(program) # Custom arguments if os.environ.get('SCIPION_NOTES_ARGS', None): args.append(os.environ['SCIPION_NOTES_ARGS']) args.append(notesFile) subprocess.Popen(args) #nonblocking else: openTextFileEditor(notesFile) def onRemoveTemporaryFiles(self): # Project -> Remove temporary files tmpPath = os.path.join(self.project.path, self.project.tmpPath) n = 0 try: for fname in os.listdir(tmpPath): fpath = "%s/%s" % (tmpPath, fname) if os.path.isfile(fpath): os.remove(fpath) n += 1 # TODO: think what to do with directories. Delete? Report? self.showInfo("Deleted content of %s -- %d file(s)." % (tmpPath, n)) except Exception as e: self.showError(str(e)) def _loadWorkflow(self, obj): try: self.project.loadProtocols(obj.getPath()) self.getViewWidget().updateRunsGraph(True, reorganize=True) except Exception, ex: self.showError(str(ex))
if n <>2: usage("This script accepts 1 parameter: the project name.") projName = sys.argv[1] path = os.path.join(os.environ['SCIPION_HOME'], 'pyworkflow', 'gui', 'no-tkinter') sys.path.insert(1, path) # Create a new project manager = Manager() if not manager.hasProject(projName): usage("There is no project with this name: %s" % pwutils.red(projName)) # the project may be a soft link which may be unavailable to the cluster so get the real path try: projectPath = os.readlink(manager.getProjectPath(projName)) except: projectPath = manager.getProjectPath(projName) project = Project(projectPath) project.load() runs = project.getRuns() # Now assuming that there is no dependencies between runs # and the graph is lineal for prot in runs: project.scheduleProtocol(prot)
def loadProjectFromPath(projectPath): project = Project(projectPath) project.load(chdir=False) return project