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