Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/squirrel/tool/commands/persistent.py: 25%

24 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2024-03-07 11:54 +0000

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6''' 

7Implementation of :app:`squirrel persistent`. 

8''' 

9 

10from pyrocko.squirrel import error, environment, database, base 

11 

12headline = 'Manage persistent selections.' 

13 

14 

15def make_subparser(subparsers): 

16 return subparsers.add_parser( 

17 'persistent', 

18 help=headline, 

19 description=headline + ''' 

20 

21Usually, the contents of files given to Squirrel are made available within the 

22application through a runtime selection which is discarded again when the 

23application quits. Getting the cached meta-data into the runtime selection can 

24be a bottleneck for application startup with large datasets. To speed up 

25startup of Squirrel-based applications, persistent selections created with the 

26``--persistent`` option can be used. 

27 

28This command allows to list and delete persistent selections. 

29''') 

30 

31 

32def setup(parser): 

33 parser.add_argument( 

34 'action', 

35 choices=['list', 'delete'], 

36 help='Select action to perform.') 

37 

38 parser.add_argument( 

39 'names', 

40 nargs='*', 

41 help='Persistent selection names.') 

42 

43 

44def run(parser, args): 

45 env = environment.get_environment() 

46 db = database.get_database(env.expand_path(env.database_path)) 

47 

48 available = sorted(db.get_persistent_names()) 

49 for name in args.names: 

50 if name not in available: 

51 raise error.SquirrelError( 

52 'No such persistent selection: %s' % name) 

53 

54 if args.action == 'list': 

55 if not args.names: 

56 names = available 

57 else: 

58 names = args.names 

59 

60 for name in names: 

61 print(name) 

62 

63 elif args.action == 'delete': 

64 for name in args.names: 

65 sq = base.Squirrel(persistent=name) 

66 sq.delete() 

67 

68 else: 

69 raise error.SquirrelError('Invalid action: %s' % args.action)