ng6_cli.py 2.76 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#
# Copyright (C) 2012 INRA
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import sys
import argparse

try:
    import _preamble
except ImportError:
    sys.exc_clear()

from jflow.workflows_manager import WorkflowsManager
from jflow.workflow import Workflow
from ng6.project import Project


if __name__ == '__main__':

    # Create the top-level parser
    parser = argparse.ArgumentParser(prog='ng6')
    subparsers = parser.add_subparsers(title='Available pipelines')
    
    # Add project menu
    sub_parser = subparsers.add_parser("addproject", help="Add a brand new project")
    sub_parser.add_argument("--name", type=str, help="Give a name to your project (has to be unique)",
                            required=True, dest="project_name", metavar="STR")
    sub_parser.add_argument("--description", type=str, help="Give a description to your project",
                            required=True, dest="description", metavar="STR")
    sub_parser.add_argument("--admin-login", type=str, help="Who is the project administrator",
                            required=True, dest="admin_login", metavar="STR")
    sub_parser.set_defaults(cmd_object="addproject")
    
    # Add available pipelines
    wf_instances = WorkflowsManager.get_workflows()
    for instance in wf_instances:
        # create the subparser for each applications
        sub_parser = subparsers.add_parser(instance.name, help=instance.description)
        for param in instance.parameters:
            sub_parser.add_argument(param.flag, type=param.type, help=param.help,
                                    required=param.required, dest=param.name,
                                    metavar=param.metavar.upper(), default=param.default)
        sub_parser.set_defaults(cmd_object=instance)
    args = vars(parser.parse_args())
    
    if isinstance(args["cmd_object"], Workflow):
        #try:
        args["cmd_object"].execute(args)
        #except (IOError, NameError), e: 
        #    sys.exit("Error: " + str(e))
    elif args["cmd_object"] == "addproject":
        #try:
        my_project = Project(args["project_name"], args["description"], args["admin_login"])
        #except NameError, e:
        #     sys.exit("Error: " + str(e))