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 

8 

9def make_subparser(subparsers): 

10 return subparsers.add_parser( 

11 'files', 

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

13 

14 

15def setup(parser): 

16 parser.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 parser.add_squirrel_selection_arguments() 

24 parser.add_squirrel_query_arguments() 

25 

26 

27def run(parser, args): 

28 d = args.squirrel_query 

29 squirrel = args.make_squirrel() 

30 

31 paths = set() 

32 if d: 

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

34 paths.add(nut.file_path) 

35 

36 db = squirrel.get_database() 

37 for path in sorted(paths): 

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

39 

40 else: 

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

42 print(path)