diff --git a/system/dialogs.py b/system/dialogs.py index e9e07c6..2b87cca 100644 --- a/system/dialogs.py +++ b/system/dialogs.py @@ -32,50 +32,15 @@ class CreateProjectDruid(gtk.Window): self.wf_info = gtk.TextBuffer() self['workflow_info'].set_buffer(self.wf_info) - def workflow_classes(self, modname): - """Returns a list of all subclasses of Workflow in a given module""" - workflow_classes = [] - - __import__('workflows.%s' % modname) - module = sys.modules['workflows.%s' % modname] - - d = module.__dict__ - for wf in d.values(): - try: - if issubclass(wf, workflow.Workflow): - workflow_classes.append(wf) - except TypeError, e: - pass - return workflow_classes - - def make_workflow_list(self): - """Returns a ListStore containing all new workflows""" - store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT) - - # List all .py files that can contain workflow classes - wf_path = sys.modules['workflows'].__path__ - wf_files = [] - - for dir in wf_path: - for fn in os.listdir(dir): - if fn.endswith('.py') and ('#' not in fn) : - wf_files.append(fn[:-3]) - - # Try to load each file and look for Workflow derived classes - for fn in wf_files: - try: - wf_info = self.workflow_classes(fn) - for wf in wf_info: - store.insert_after(None, (getattr(wf, 'name'), wf)) - except Exception, e: - wf_info = self.workflow_classes(fn) - logger.log('warning', 'Cannot load workflow: %s' % fn) - - return store - def __getitem__(self, key): return self.widget_tree.get_widget(key) - + + def make_workflow_list(self): + store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT) + for wf in workflow.workflow_list(): + store.insert_after(None, (wf.name, wf)) + return store + def run(self): self['workflow_list'].set_model(self.workflows) diff --git a/system/workflow.py b/system/workflow.py index 62dc41d..5c1eca8 100644 --- a/system/workflow.py +++ b/system/workflow.py @@ -1,6 +1,48 @@ import gtk import logger +import sys +import os + +def _workflow_classes(modname): + """Returns a list of all subclasses of Workflow in a given module""" + workflow_classes = [] + + __import__('workflows.%s' % modname) + module = sys.modules['workflows.%s' % modname] + + d = module.__dict__ + for wf in d.values(): + try: + if issubclass(wf, Workflow): + workflow_classes.append(wf) + except TypeError, e: + pass + return workflow_classes + +def workflow_list(): + """Returns a ListStore containing all new workflows""" + retval = [] + + # List all .py files that can contain workflow classes + wf_path = sys.modules['workflows'].__path__ + wf_files = [] + + for dir in wf_path: + for fn in os.listdir(dir): + if fn.endswith('.py') and ('#' not in fn): + wf_files.append(fn[:-3]) + + # Try to load each file and look for Workflow derived classes + for fn in wf_files: + try: + for wf in _workflow_classes(fn): + retval.append(wf) + except Exception, e: + logger.log('warning', 'Cannot load workflow: %s' % fn) + logger.log('warning', e) + + return retval class Workflow: """Defines a workflow that contains a set of analysis stages.