Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/galaxy/util/script.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author | shellac |
---|---|
date | Sat, 02 May 2020 07:14:21 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26e78fe6e8c4 |
---|---|
1 """Utilities for Galaxy scripts | |
2 """ | |
3 import argparse | |
4 import os | |
5 import sys | |
6 | |
7 from galaxy.util.properties import find_config_file, load_app_properties | |
8 | |
9 DESCRIPTION = None | |
10 ACTIONS = None | |
11 ARGUMENTS = None | |
12 DEFAULT_ACTION = None | |
13 | |
14 ARG_HELP_CONFIG_FILE = """ | |
15 Galaxy config file (defaults to $GALAXY_ROOT/config/galaxy.yml if that file exists | |
16 or else to ./config/galaxy.ini if that exists). If this isn't set on the | |
17 command line it can be set with the environment variable GALAXY_CONFIG_FILE. | |
18 """ | |
19 | |
20 # ARG_HELP_CONFIG_SECTION = """ | |
21 # Section containing application configuration in the target config file specified with | |
22 # -c/--config-file. This defaults to 'galaxy' for YAML/JSON configuration files and 'main' | |
23 # with 'app:' prepended for INI. If this isn't set on the command line it can be set with | |
24 # the environment variable GALAXY_CONFIG_SECTION. | |
25 # """ | |
26 | |
27 | |
28 def main_factory(description=None, actions=None, arguments=None, default_action=None): | |
29 global DESCRIPTION, ACTIONS, ARGUMENTS, DEFAULT_ACTION | |
30 DESCRIPTION = description | |
31 ACTIONS = actions or {} | |
32 ARGUMENTS = arguments or [] | |
33 DEFAULT_ACTION = default_action | |
34 return main | |
35 | |
36 | |
37 def main(argv=None): | |
38 """Entry point for conversion process.""" | |
39 if argv is None: | |
40 argv = sys.argv[1:] | |
41 args = _arg_parser().parse_args(argv) | |
42 kwargs = app_properties_from_args(args) | |
43 action = args.action | |
44 action_func = ACTIONS[action] | |
45 action_func(args, kwargs) | |
46 | |
47 | |
48 def app_properties_from_args(args, legacy_config_override=None, app=None): | |
49 config_file = config_file_from_args(args, legacy_config_override=legacy_config_override, app=app) | |
50 config_section = getattr(args, "config_section", None) | |
51 app_properties = load_app_properties(config_file=config_file, config_section=config_section) | |
52 return app_properties | |
53 | |
54 | |
55 def config_file_from_args(args, legacy_config_override=None, app=None): | |
56 app = app or getattr(args, "app", "galaxy") | |
57 config_file = legacy_config_override or args.config_file or find_config_file(app) | |
58 return config_file | |
59 | |
60 | |
61 def populate_config_args(parser): | |
62 # config and config-file respected because we have used different arguments at different | |
63 # time for scripts. | |
64 | |
65 # Options (e.g. option_name) not found in this file can have their defaults overridden | |
66 # set setting GALAXY_CONFIG_OPTION_NAME where OPTION_NAME is option_name converted to upper case. | |
67 # Options specified in that file can be overridden for this program set setting | |
68 # GALAXY_CONFIG_OVERRIDE_OPTION_NAME to a new value. | |
69 parser.add_argument("-c", "--config-file", "--config", | |
70 default=os.environ.get('GALAXY_CONFIG_FILE', None), | |
71 help=ARG_HELP_CONFIG_FILE) | |
72 parser.add_argument("--config-section", | |
73 default=os.environ.get('GALAXY_CONFIG_SECTION', None), | |
74 help=argparse.SUPPRESS) # See ARG_HELP_CONFIG_SECTION comment above for unsuppressed details. | |
75 | |
76 | |
77 def _arg_parser(): | |
78 parser = argparse.ArgumentParser(description=DESCRIPTION) | |
79 parser.add_argument('action', metavar='ACTION', type=str, | |
80 choices=list(ACTIONS.keys()), | |
81 default=DEFAULT_ACTION, | |
82 nargs='?' if DEFAULT_ACTION is not None else None, | |
83 help='action to perform') | |
84 populate_config_args(parser) | |
85 parser.add_argument("--app", | |
86 default=os.environ.get('GALAXY_APP', 'galaxy')) | |
87 for argument in ARGUMENTS: | |
88 parser.add_argument(*argument[0], **argument[1]) | |
89 return parser |