Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0
This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
laydi/bin/laydi

122 lines
3.1 KiB
Python
Executable File

#!/usr/bin/python
from getopt import getopt
import os
import sys
from laydi import laydi, project, workflow, main
#import workflows
from laydi import cfgparse
import optparse
PROGRAM_NAME = 'laydi'
VERSION = '0.1.0'
def list_workflows():
print 'laydi %s' % VERSION
print
print 'Available workflows:'
wfs = workflow.workflow_list()
for wf in wfs:
print ' %s (%s)' % (wf.ident, wf.name)
print
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)
def parse_options():
conf_files = ['/etc/laydirc',
os.path.join(os.environ['HOME'], '.laydi')]
cp = cfgparse.ConfigParser()
cp.add_option('home', type='string',
default=os.environ['HOME'])
cp.add_option('datadir', type='string',
default=os.environ['HOME'])
cp.add_option('workflowdir', type='string',
default='workflows')
cp.parse()
op = optparse.OptionParser()
op.add_option('-l', '--list-workflows',
action='store_true',
default=False,
help='List available workflows.')
op.add_option('-w', '--workflow',
default='chemometric',
help='Start with selected workflow')
op.add_option('-c', '--generate-config',
action='store_true',
help='Generate configuration file ~/.laydi if it does not exist.')
for cf in conf_files:
if os.path.isfile(cf):
cp.add_file(cf)
return cp.parse(op)
if __name__ == '__main__':
import gtk
import gnome
gnome.program_init(PROGRAM_NAME, VERSION)
options, params = parse_options()
main.options = options
for dir in main.options.workflowdir.split(';'):
if dir.strip() != "" and os.path.exists(dir):
sys.path.append(dir)
if options.list_workflows:
list_workflows()
sys.exit(0)
if options.generate_config:
generate_config()
sys.exit(0)
selected_wf = workflow.find_workflow(options.workflow)
if selected_wf == None: selected_wf = workflow.EmptyWorkflow
# workflow_list = workflow.workflow_list()
# for wf in workflow_list:
# if wf.ident == options.workflow:
# selected_wf = wf
main.set_workflow(selected_wf())
main.set_options(options)
app = laydi.LaydiApp()
main.set_application(app)
main.set_project(project.Project())
app.set_project(main.project)
app.show()
gtk.main()