1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

4# ---|P------/S----------~Lg---------- 

5 

6from __future__ import absolute_import, print_function 

7 

8from .. import common 

9 

10 

11def setup(subparsers): 

12 p = common.add_parser( 

13 subparsers, 'files', 

14 help='Lookup files providing given content selection.') 

15 

16 p.add_argument( 

17 '--relative', 

18 action='store_true', 

19 default=False, 

20 help='Reveal path as it is stored in the database. This is relative ' 

21 'for files inside a Squirrel environment.') 

22 

23 common.add_selection_arguments(p) 

24 common.add_query_arguments(p) 

25 

26 return p 

27 

28 

29def call(parser, args): 

30 d = common.squirrel_query_from_arguments(args) 

31 squirrel = common.squirrel_from_selection_arguments(args) 

32 

33 paths = set() 

34 if d: 

35 for nut in squirrel.iter_nuts(**d): 

36 paths.add(nut.file_path) 

37 

38 db = squirrel.get_database() 

39 for path in sorted(paths): 

40 print(db.relpath(path) if args.relative else path) 

41 

42 else: 

43 for path in squirrel.iter_paths(raw=args.relative): 

44 print(path)