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

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

# http://pyrocko.org - GPLv3 

# 

# The Pyrocko Developers, 21st Century 

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

 

import sys 

 

from pyrocko import util 

 

from . import common 

from .commands import command_modules 

from pyrocko import squirrel as sq 

 

 

g_program_name = 'squirrel' 

 

 

def main(args=None): 

command( 

args=args, 

program_name=g_program_name, 

subcommands=command_modules, 

description=''' 

Pyrocko Squirrel - Prompt seismological data access with a fluffy tail. 

 

This is `squirrel`, a command-line front-end to the Squirrel data access 

infrastructure. The Squirrel infrastructure offers meta-data caching, blazingly 

fast data lookup for large datasets and transparent online data download to 

applications building on it. 

 

In most cases, the Squirrel does its business discretely under the hood and 

does not require human interaction or awareness. However, using this tool, some 

aspects can be configured for the benefit of greater performance or 

convenience, including (1) using a separate (isolated, local) environment for a 

specific project, (2) using named selections to speed up access to very large 

datasets, (3), pre-scanning/indexing of file collections. It can also be used 

to inspect various aspects of a data collection. 

 

This tool's functionality is available through several subcommands. Run 

`squirrel [subcommand] --help` to get further help.''') 

 

 

def command( 

args=None, 

program_name=None, 

description=''' 

Pyrocko Squirrel based script. 

 

Run with --help to get further help.''', 

subcommands=[]): 

 

if program_name is None: 

program_name = sys.argv[0] 

 

if args is None: 

args = sys.argv[1:] 

 

parser = common.PyrockoArgumentParser( 

prog=program_name, 

add_help=False, 

description=description) 

 

parser.add_argument( 

'--help', '-h', 

action='store_true', 

help='Show this help message and exit.') 

 

parser.add_argument( 

'--loglevel', '-l', 

choices=['critical', 'error', 'warning', 'info', 'debug'], 

default='info', 

help='Set logger level. Default: %(default)s') 

 

if subcommands: 

subparsers = parser.add_subparsers( 

title='Subcommands') 

 

for mod in subcommands: 

subparser = mod.setup(subparsers) 

subparser.set_defaults(target=mod.call, subparser=subparser) 

else: 

common.add_selection_arguments(parser) 

 

args = parser.parse_args(args) 

subparser = args.__dict__.pop('subparser', None) 

if args.help: 

(subparser or parser).print_help() 

sys.exit(0) 

 

loglevel = args.__dict__.pop('loglevel') 

util.setup_logging(g_program_name, loglevel) 

 

target = args.__dict__.pop('target', None) 

 

if target: 

try: 

target(parser, args) 

except sq.SquirrelError as e: 

sys.exit(str(e)) 

 

elif not subcommands: 

return common.squirrel_from_selection_arguments(args) 

 

else: 

parser.print_help() 

sys.exit(0) 

 

 

__all__ = [ 

'main', 

'command', 

]