1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6from __future__ import absolute_import, print_function
8headline = 'Lookup files providing given content selection.'
11def make_subparser(subparsers):
12 return subparsers.add_parser(
13 'files',
14 help=headline,
15 description=headline)
18def setup(parser):
19 parser.add_argument(
20 '--relative',
21 action='store_true',
22 default=False,
23 help='Reveal path as it is stored in the database. This is relative '
24 'for files inside a Squirrel environment.')
26 parser.add_squirrel_selection_arguments()
27 parser.add_squirrel_query_arguments()
30def run(parser, args):
31 d = args.squirrel_query
32 squirrel = args.make_squirrel()
34 paths = set()
35 if d:
36 for nut in squirrel.iter_nuts(**d):
37 paths.add(nut.file_path)
39 db = squirrel.get_database()
40 for path in sorted(paths):
41 print(db.relpath(path) if args.relative else path)
43 else:
44 for path in squirrel.iter_paths(raw=args.relative):
45 print(path)