Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/squirrel/tool/commands/files.py: 25%
20 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-04 09:52 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-04 09:52 +0000
1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6'''
7Implementation of :app:`squirrel files`.
8'''
10headline = 'Lookup files providing given content selection.'
13def make_subparser(subparsers):
14 return subparsers.add_parser(
15 'files',
16 help=headline,
17 description=headline)
20def setup(parser):
21 parser.add_argument(
22 '--relative',
23 action='store_true',
24 default=False,
25 help='Reveal path as it is stored in the database. This is relative '
26 'for files inside a Squirrel environment.')
28 parser.add_squirrel_selection_arguments()
29 parser.add_squirrel_query_arguments()
32def run(parser, args):
33 d = args.squirrel_query
34 squirrel = args.make_squirrel()
36 paths = set()
37 if d:
38 for nut in squirrel.iter_nuts(**d):
39 paths.add(nut.file_path)
41 db = squirrel.get_database()
42 for path in sorted(paths):
43 print(db.relpath(path) if args.relative else path)
45 else:
46 for path in squirrel.iter_paths(raw=args.relative):
47 print(path)