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

146 lines
3.9 KiB
Python
Executable File

#!/usr/bin/python
from getopt import getopt
import os
import sys
from laydi import laydi, project, projectview, 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='default',
help='Start with selected workflow')
op.add_option('-c', '--generate-config',
action='store_true',
help='Generate configuration file ~/.laydi if it does not exist.')
op.add_option('-n', '--new-project',
action='store_true',
help='Create new project directory.')
for cf in conf_files:
if os.path.isfile(cf):
cp.add_file(cf)
options, params = cp.parse(op)
if len(params) != 1:
print "error: project directory must be specified."
print "notice: to create a new project use -n /path/to/project"
sys.exit(1)
return options, params
if __name__ == '__main__':
import gtk
import gnome
gnome.program_init(PROGRAM_NAME, VERSION)
options, params = parse_options()
## Workflow setup
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()
## Project setup
prjroot = params[0]
if not project.is_project_directory(prjroot):
if options.new_project:
project.make_project_directory(prjroot)
else:
print "error: project directory not found: %s" % prjroot
print "notice: use the -n option to make a new project"
sys.exit(2)
proj = project.Project(prjroot)
main.project = proj
main.set_application(app)
main.set_projectview(projectview.ProjectView(proj))
app.set_projectview(main.projectview)
app.show()
gtk.main()