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