From 251f9d6cf40edda6ca1c6f954d045ecebc42f074 Mon Sep 17 00:00:00 2001 From: einarr Date: Tue, 25 Apr 2006 12:19:25 +0000 Subject: [PATCH] Added command line options to create a new project based on a given workflow. --- fluents | 68 +++++++++++++++++++++++++++++++++++++ fluent => system/fluents.py | 23 ++----------- system/workflow.py | 1 + workflows/go_workflow.py | 1 + workflows/pca_workflow.py | 1 + 5 files changed, 74 insertions(+), 20 deletions(-) create mode 100755 fluents rename fluent => system/fluents.py (84%) diff --git a/fluents b/fluents new file mode 100755 index 0000000..ac42eef --- /dev/null +++ b/fluents @@ -0,0 +1,68 @@ +#!/usr/bin/python + +from getopt import getopt +import sys +from system import fluents, project, workflow +import workflows + +PROGRAM_NAME = 'fluents' +VERSION = '0.1.0' + +parameters = {'workflow': workflow.EmptyWorkflow} + +def show_help(): + print 'fluent %s' % VERSION + print 'This software is released under the GNU General Public Licence' + print + print 'Usage: fluent [options]' + print + print 'Description:' + print ' Fluent is a lightweight data analysis application for bilinear models.' + print + print 'Options:' + print ' -h --help Show this help text' + print ' -l --list-workflows Lists available workflows' + print ' -w --workflow= Generates a new project based on workflow wf.' + print + +def list_workflows(): + print 'fluent %s' % VERSION + print + print 'Workflows:' + + wfs = workflow.workflow_list() + names = [wf.name for wf in wfs] + names.sort() + + for n in names: + print ' %s (%s)' % (n.id, n.name) + +def parse_options(): + short_opts = 'hlw:' + long_opts = ['help', 'list-workflows', 'workflow='] + + options, params = getopt(sys.argv[1:], short_opts, long_opts) + + for opt, val in options: + if opt in ['-h', '--help']: + show_help() + elif opt in ['-l', '--list-workflows']: + list_workflows() + elif opt in ['-w', '--workflow']: + wfs = workflow.workflow_list() + for wf in wfs: + if wf.ident == val: + parameters['workflow'] = wf + parameters['workflow'] + +if __name__ == '__main__': + parse_options() + + import gtk + import gnome + + gnome.program_init(PROGRAM_NAME, VERSION) + app = fluents.FluentApp(parameters['workflow']) + app.set_project(project.Project()) + app.show() + gtk.main() diff --git a/fluent b/system/fluents.py similarity index 84% rename from fluent rename to system/fluents.py index 1e47090..d96b361 100755 --- a/fluent +++ b/system/fluents.py @@ -20,14 +20,14 @@ GLADEFILENAME = 'system/fluent.glade' class FluentApp: - def __init__(self): + def __init__(self, wf): # Application variables self.project = None self.current_data = None gtk.glade.set_custom_handler(self.custom_object_factory) self.widget_tree = gtk.glade.XML(GLADEFILENAME, 'appwindow') - self.workflow = workflow.EmptyWorkflow(self) + self.workflow = wf(self) def set_project(self, project): logger.log('notice', 'Creating a new project') @@ -93,8 +93,7 @@ class FluentApp: 'on_zoom_out_button_clicked' : (self.on_multiple_view), 'on_new1_activate' : (self.on_create_project), 'on_button_new_clicked' : (self.on_create_project), - 'on_about1_activate' : (self.on_help_about), - 'on_workflow_refresh_clicked' : (self.on_workflow_refresh_clicked)} + 'on_about1_activate' : (self.on_help_about)} self.widget_tree.signal_autoconnect(signals) # Log that we've set up the app now @@ -124,19 +123,3 @@ class FluentApp: about = widget_tree.get_widget('aboutdialog') about.run() - def on_workflow_refresh_clicked(self, *ignored): - try: - reload(sys.modules[self.workflow.__class__.__module__]) - except Exception, e: - logger.log('error', 'Relading workflow failed.') - logger.log('error', e) - else: - logger.log('notice', 'Successfully reloaded workflow.') - -if __name__ == '__main__': - gnome.program_init(PROGRAM_NAME, VERSION) - app = FluentApp() - app.show() - gtk.main() - - diff --git a/system/workflow.py b/system/workflow.py index 970be89..d38198d 100644 --- a/system/workflow.py +++ b/system/workflow.py @@ -53,6 +53,7 @@ class Workflow: """ name = "Workflow" + ident = None description = "Workflow Description" def __init__(self, app): diff --git a/workflows/go_workflow.py b/workflows/go_workflow.py index 411ca6e..5e38c94 100644 --- a/workflows/go_workflow.py +++ b/workflows/go_workflow.py @@ -9,6 +9,7 @@ import cPickle class EinarsWorkflow (workflow.Workflow): name = 'Test Workflow' + ident = 'go' description = 'Gene Ontology Workflow. This workflow currently serves as a general testing workflow.' def __init__(self, app): workflow.Workflow.__init__(self, app) diff --git a/workflows/pca_workflow.py b/workflows/pca_workflow.py index 91e562f..11558a6 100644 --- a/workflows/pca_workflow.py +++ b/workflows/pca_workflow.py @@ -8,6 +8,7 @@ from system import dataset, logger, plots class PCAWorkflow(wf.Workflow): name = 'PCA Workflow' + ident = 'pca' description = 'PCA workflow. Uses real microarray data from a study of diabetes (Mootha et al.).' def __init__(self, app):