1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6headline = 'Lookup files providing given content selection.' 

7 

8 

9def make_subparser(subparsers): 

10 return subparsers.add_parser( 

11 'files', 

12 help=headline, 

13 description=headline) 

14 

15 

16def setup(parser): 

17 parser.add_argument( 

18 '--relative', 

19 action='store_true', 

20 default=False, 

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

22 'for files inside a Squirrel environment.') 

23 

24 parser.add_squirrel_selection_arguments() 

25 parser.add_squirrel_query_arguments() 

26 

27 

28def run(parser, args): 

29 d = args.squirrel_query 

30 squirrel = args.make_squirrel() 

31 

32 paths = set() 

33 if d: 

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

35 paths.add(nut.file_path) 

36 

37 db = squirrel.get_database() 

38 for path in sorted(paths): 

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

40 

41 else: 

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

43 print(path)