2007-06-28 23:42:18 +02:00
|
|
|
#!/usr/bin/python
|
2006-04-25 14:19:25 +02:00
|
|
|
|
|
|
|
from getopt import getopt
|
2007-02-28 15:07:33 +01:00
|
|
|
import os
|
2006-04-25 14:19:25 +02:00
|
|
|
import sys
|
2008-12-05 23:07:56 +01:00
|
|
|
from laydi import laydi, project, workflow, main
|
2007-12-14 12:48:21 +01:00
|
|
|
#import workflows
|
2008-12-05 23:07:56 +01:00
|
|
|
from laydi import cfgparse
|
2008-12-05 01:12:49 +01:00
|
|
|
import optparse
|
2006-04-25 14:19:25 +02:00
|
|
|
|
2008-12-05 21:01:02 +01:00
|
|
|
PROGRAM_NAME = 'laydi'
|
2006-04-25 14:19:25 +02:00
|
|
|
VERSION = '0.1.0'
|
|
|
|
|
|
|
|
def list_workflows():
|
2008-12-05 23:07:56 +01:00
|
|
|
print 'laydi %s' % VERSION
|
2006-04-25 14:19:25 +02:00
|
|
|
print
|
2007-02-27 17:25:48 +01:00
|
|
|
print 'Available workflows:'
|
2006-04-25 14:19:25 +02:00
|
|
|
|
|
|
|
wfs = workflow.workflow_list()
|
2006-04-25 14:36:38 +02:00
|
|
|
for wf in wfs:
|
|
|
|
print ' %s (%s)' % (wf.ident, wf.name)
|
|
|
|
print
|
2006-04-25 14:19:25 +02:00
|
|
|
|
2010-01-19 17:45:51 +01:00
|
|
|
|
|
|
|
def generate_config():
|
|
|
|
fn = os.path.join(os.environ['HOME'], '.laydi')
|
|
|
|
if not os.path.exists(fn):
|
|
|
|
fd = open(fn, 'w')
|
|
|
|
print >> fd, "home = %s" % os.environ['HOME']
|
|
|
|
print >> fd, "datadir = %%(home)s/laydi/datasets"
|
|
|
|
print >> fd, "workflowdir = %%(home)s/laydi/workflows"
|
|
|
|
fd.close()
|
|
|
|
|
|
|
|
laydidir = os.path.join(os.environ['HOME'], 'laydi')
|
|
|
|
if not os.path.exists(laydidir):
|
|
|
|
os.mkdir(laydidir, 0755)
|
|
|
|
|
|
|
|
datadir = os.path.join(os.environ['HOME'], 'laydi/datasets')
|
|
|
|
if not os.path.exists(datadir):
|
|
|
|
os.mkdir(datadir, 0755)
|
|
|
|
|
|
|
|
workflowdir = os.path.join(os.environ['HOME'], 'laydi/workflows')
|
|
|
|
if not os.path.exists(workflowdir):
|
|
|
|
os.mkdir(workflowdir, 0755)
|
|
|
|
|
|
|
|
|
2006-04-25 14:19:25 +02:00
|
|
|
def parse_options():
|
2008-12-05 23:07:56 +01:00
|
|
|
conf_files = ['/etc/laydirc',
|
|
|
|
os.path.join(os.environ['HOME'], '.laydi')]
|
2007-02-28 15:07:33 +01:00
|
|
|
|
2007-02-27 17:08:22 +01:00
|
|
|
cp = cfgparse.ConfigParser()
|
2007-02-28 15:07:33 +01:00
|
|
|
|
|
|
|
cp.add_option('home', type='string',
|
|
|
|
default=os.environ['HOME'])
|
|
|
|
|
|
|
|
cp.add_option('datadir', type='string',
|
|
|
|
default=os.environ['HOME'])
|
2008-02-07 15:20:52 +01:00
|
|
|
cp.add_option('workflowdir', type='string',
|
|
|
|
default='workflows')
|
2007-02-28 15:07:33 +01:00
|
|
|
cp.parse()
|
2007-02-27 17:08:22 +01:00
|
|
|
op = optparse.OptionParser()
|
2006-04-25 14:19:25 +02:00
|
|
|
|
2007-02-27 17:08:22 +01:00
|
|
|
op.add_option('-l', '--list-workflows',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='List available workflows.')
|
2006-04-25 14:19:25 +02:00
|
|
|
|
2007-02-27 17:08:22 +01:00
|
|
|
op.add_option('-w', '--workflow',
|
2010-01-19 17:45:51 +01:00
|
|
|
default='chemometric',
|
2007-02-27 17:08:22 +01:00
|
|
|
help='Start with selected workflow')
|
2006-04-25 14:19:25 +02:00
|
|
|
|
2010-01-19 17:45:51 +01:00
|
|
|
op.add_option('-c', '--generate-config',
|
|
|
|
action='store_true',
|
|
|
|
help='Generate configuration file ~/.laydi if it does not exist.')
|
|
|
|
|
2007-02-28 15:07:33 +01:00
|
|
|
for cf in conf_files:
|
|
|
|
if os.path.isfile(cf):
|
|
|
|
cp.add_file(cf)
|
|
|
|
|
2007-02-27 17:08:22 +01:00
|
|
|
return cp.parse(op)
|
|
|
|
|
2006-04-25 14:19:25 +02:00
|
|
|
if __name__ == '__main__':
|
2007-12-14 12:48:21 +01:00
|
|
|
import gtk
|
|
|
|
import gnome
|
|
|
|
|
2008-02-07 15:20:52 +01:00
|
|
|
gnome.program_init(PROGRAM_NAME, VERSION)
|
2007-12-14 12:48:21 +01:00
|
|
|
|
2007-02-27 17:08:22 +01:00
|
|
|
options, params = parse_options()
|
2008-02-07 15:20:52 +01:00
|
|
|
main.options = options
|
2006-04-25 14:19:25 +02:00
|
|
|
|
2008-12-05 01:12:49 +01:00
|
|
|
for dir in main.options.workflowdir.split(';'):
|
|
|
|
if dir.strip() != "" and os.path.exists(dir):
|
|
|
|
sys.path.append(dir)
|
|
|
|
|
2007-02-27 17:08:22 +01:00
|
|
|
if options.list_workflows:
|
|
|
|
list_workflows()
|
|
|
|
sys.exit(0)
|
|
|
|
|
2010-01-19 17:45:51 +01:00
|
|
|
if options.generate_config:
|
|
|
|
generate_config()
|
|
|
|
sys.exit(0)
|
|
|
|
|
2007-12-14 12:48:21 +01:00
|
|
|
selected_wf = workflow.find_workflow(options.workflow)
|
|
|
|
if selected_wf == None: selected_wf = workflow.EmptyWorkflow
|
2007-02-27 17:08:22 +01:00
|
|
|
|
2007-12-14 12:48:21 +01:00
|
|
|
# workflow_list = workflow.workflow_list()
|
|
|
|
# for wf in workflow_list:
|
|
|
|
# if wf.ident == options.workflow:
|
|
|
|
# selected_wf = wf
|
2007-02-27 17:08:22 +01:00
|
|
|
|
2007-07-26 14:35:59 +02:00
|
|
|
main.set_workflow(selected_wf())
|
|
|
|
main.set_options(options)
|
2008-12-05 23:07:56 +01:00
|
|
|
app = laydi.LaydiApp()
|
2007-07-26 14:35:59 +02:00
|
|
|
|
|
|
|
main.set_application(app)
|
|
|
|
main.set_project(project.Project())
|
|
|
|
|
|
|
|
app.set_project(main.project)
|
2006-04-25 14:19:25 +02:00
|
|
|
app.show()
|
|
|
|
gtk.main()
|
2007-02-27 17:08:22 +01:00
|
|
|
|