Debian Codegraph @

cylc/flow/scripts/get_resources.py

raw
1 #!/usr/bin/env python3
2 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
3 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 """cylc get-resources [OPTIONS] ARGS
18
19 Extract resources from the cylc.flow package.
20
21 If the directory is omitted the resource will be copied either to your
22 current working directory for regular resources, or to the first configured
23 "source" directory (~/cylc-src by default) for the tutorials.
24
25 Examples:
26 # list all resources
27 $ cylc get-resources --list
28
29 # copy the Cylc wrapper script to the current directory:
30 $ cylc get-resources cylc
31
32 # copy the Cylc wrapper script to a/b/c:
33 $ cylc get-resources cylc a/b/c
34
35 # copy the "runtime-tutorial" to your "source" directory:
36 $ cylc get-resources tutorial/runtime-tutorial
37
38 # copy all of the tutorials to your "source" directory:
39 $ cylc get-resources tutorial
40 """
41
42 import sys
43
44 from cylc.flow import LOG
45 from cylc.flow.exceptions import CylcError
46 import cylc.flow.flags
47 from cylc.flow.loggingutil import set_timestamps
48 from cylc.flow.option_parsers import CylcOptionParser as COP
49 from cylc.flow.resources import get_resources, list_resources
50 from cylc.flow.terminal import cli_function
51
52
53 def get_option_parser():
54 parser = COP(
55 __doc__,
56 argdoc=[
57 COP.optional(
58 ('RESOURCE', 'Resource to extract.')
59 ),
60 COP.optional(
61 ('DIR', 'Target directory.')
62 )
63 ]
64 )
65
66 parser.add_option(
67 '--list',
68 help="List available resources.",
69 default=False,
70 action='store_true',
71 )
72
73 return parser
74
75
76 @cli_function(get_option_parser)
77 def main(parser, opts, resource=None, tgt_dir=None):
78 # Intercept requests for syntax/cylc.vim:
79 if resource == "syntax/cylc.vim":
80 raise CylcError(
81 'syntax/cylc.vim has been replaced by '
82 'https://github.com/cylc/cylc.vim'
83 )
84
85 if cylc.flow.flags.verbosity < 2:
86 set_timestamps(LOG, False)
87 if not resource or opts.list:
88 list_resources()
89 sys.exit(0)
90 get_resources(resource, tgt_dir)