1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6import logging
8from . import common
9from .commands import command_modules
12logger = logging.getLogger('psq.cli')
15g_program_name = 'squirrel'
18def main(args=None):
19 run(
20 args=args,
21 prog=g_program_name,
22 subcommands=command_modules,
23 description='''
24Pyrocko Squirrel - Prompt seismological data access with a fluffy tail.
26This is ```squirrel```, a command-line front-end to the Squirrel data access
27infrastructure. The Squirrel infrastructure offers meta-data caching, blazingly
28fast data lookup for large datasets and transparent online data download to
29applications building on it.
31In most cases, the Squirrel does its business discretely under the hood and
32does not require human interaction or awareness. However, using this tool, some
33aspects can be configured for the benefit of greater performance or
34convenience, including (1) using a separate (isolated, local) environment for a
35specific project, (2) using named selections to speed up access to very large
36datasets, (3), pre-scanning/indexing of file collections. It can also be used
37to inspect various aspects of a data collection.
39This tool's functionality is available through several subcommands. Run
40```squirrel SUBCOMMAND --help``` to get further help.''')
43def run(
44 args=None,
45 command=None,
46 subcommands=[],
47 description='''
48Pyrocko Squirrel based script.
50Run with --help to get further help.''',
51 **kwargs):
53 '''
54 Setup and run Squirrel-based application.
56 The implementation of the tool can be provided by one or multiple
57 :py:class:`~pyrocko.squirrel.tool.SquirrelCommand` instances. This driver
58 function sets up a
59 :py:class:`~pyrocko.squirrel.tool.SquirrelArgumentParser`, and processes
60 command line arguments, and dispatches execution to the selected command or
61 subcommand. The program is set up to provide and automatically handle
62 ``--help``, ``--loglevel``, and ``--progress``. If an exception of type
63 :py:exc:`pyrocko.squirrel.error.SquirrelError` or
64 :py:exc:`pyrocko.squirrel.error.ToolError` is caught, the error is logged
65 and the program is terminated with exit code 1.
67 :param args:
68 Arguments passed to
69 :py:meth:`~pyrocko.squirrel.tool.SquirrelArgumentParser.parse_args.
70 By default uses py:attr:`sys.argv`.
71 :type args:
72 :py:class:`list` of :py:class:`str`
74 :param command:
75 Implementation of the command. It must provide ``setup(parser)`` and
76 ``run(parser, args)``.
77 :type command:
78 :py:class:`~pyrocko.squirrel.tool.SquirrelCommand` or module
80 :param subcommands:
81 Configures the program to offer multiple subcommands. The command to
82 execute is selected with the first argument passed to ``args``.
83 Implementations must provide ``make_subparser(subparsers)``,
84 ``setup(parser)``, and ``run(parser, args)``.
85 :type subcommands:
86 :py:class:`list` of
87 :py:class:`~pyrocko.squirrel.tool.SquirrelCommand` instances or
88 modules
90 :param description:
91 Description of the program.
92 :type description:
93 str
94 '''
96 parser = common.SquirrelArgumentParser(
97 command=command,
98 subcommands=subcommands,
99 description=description, **kwargs)
101 return parser.run(args)
104__all__ = [
105 'main',
106 'run',
107]