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-09-28 10:39 +0000

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6''' 

7Implementation of :app:`squirrel files`. 

8''' 

9 

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

11 

12 

13def make_subparser(subparsers): 

14 return subparsers.add_parser( 

15 'files', 

16 help=headline, 

17 description=headline) 

18 

19 

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.') 

27 

28 parser.add_squirrel_selection_arguments() 

29 parser.add_squirrel_query_arguments() 

30 

31 

32def run(parser, args): 

33 d = args.squirrel_query 

34 squirrel = args.make_squirrel() 

35 

36 paths = set() 

37 if d: 

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

39 paths.add(nut.file_path) 

40 

41 db = squirrel.get_database() 

42 for path in sorted(paths): 

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

44 

45 else: 

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

47 print(path)