1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

# http://pyrocko.org - GPLv3 

# 

# The Pyrocko Developers, 21st Century 

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

 

from __future__ import absolute_import, print_function 

 

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

from .. import common 

 

 

def setup(subparsers): 

p = common.add_parser( 

subparsers, 'persistent', 

help='Manage persistent selections.', 

description='''Manage persistent selections. 

 

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

application through a runtime selection which is discarded again when the 

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

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

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

--persistent option can be used. 

 

This command allows to list and delete persistent selections. 

''') 

 

p.add_argument( 

'action', 

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

help='Select action to perform.') 

 

p.add_argument( 

'names', 

nargs='*', 

help='Persistent selection names.') 

 

return p 

 

 

def call(parser, args): 

env = environment.get_environment() 

db = database.get_database(env.database_path) 

 

available = sorted(db.get_persistent_names()) 

for name in args.names: 

if name not in available: 

raise error.SquirrelError( 

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

 

if args.action == 'list': 

if not args.names: 

names = available 

else: 

names = args.names 

 

for name in names: 

print(name) 

 

elif args.action == 'delete': 

for name in args.names: 

sq = base.Squirrel(persistent=name) 

sq.delete() 

 

else: 

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