1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6from __future__ import absolute_import, print_function
8from pyrocko.squirrel import error, environment, database, base
10headline = 'Manage persistent selections.'
13def make_subparser(subparsers):
14 return subparsers.add_parser(
15 'persistent',
16 help=headline,
17 description=headline + '''
19Usually, the contents of files given to Squirrel are made available within the
20application through a runtime selection which is discarded again when the
21application quits. Getting the cached meta-data into the runtime selection can
22be a bottleneck for application startup with large datasets. To speed up
23startup of Squirrel-based applications, persistent selections created with the
24``--persistent`` option can be used.
26This command allows to list and delete persistent selections.
27''')
30def setup(parser):
31 parser.add_argument(
32 'action',
33 choices=['list', 'delete'],
34 help='Select action to perform.')
36 parser.add_argument(
37 'names',
38 nargs='*',
39 help='Persistent selection names.')
42def run(parser, args):
43 env = environment.get_environment()
44 db = database.get_database(env.expand_path(env.database_path))
46 available = sorted(db.get_persistent_names())
47 for name in args.names:
48 if name not in available:
49 raise error.SquirrelError(
50 'No such persistent selection: %s' % name)
52 if args.action == 'list':
53 if not args.names:
54 names = available
55 else:
56 names = args.names
58 for name in names:
59 print(name)
61 elif args.action == 'delete':
62 for name in args.names:
63 sq = base.Squirrel(persistent=name)
64 sq.delete()
66 else:
67 raise error.SquirrelError('Invalid action: %s' % args.action)