1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6from __future__ import absolute_import, print_function
8import logging
10from pyrocko.guts import List, StringChoice, String
11from pyrocko import has_paths
12from . import base
13from .. import io
15guts_prefix = 'squirrel'
17logger = logging.getLogger('psq.client.local')
20class FileFormat(StringChoice):
21 choices = ['detect'] + io.supported_formats()
24class ContentKind(StringChoice):
25 choices = io.base.g_content_kinds
28class LocalData(base.Source, has_paths.HasPaths):
29 '''
30 A collection of local files attachable as a Squirrel data-source.
31 '''
32 paths = List.T(
33 has_paths.Path.T(),
34 help='Directory and file paths to add to the Squirrel '
35 'instance. See :py:meth:`Squirrel.add() '
36 '<pyrocko.squirrel.base.Squirrel.add>`.')
37 kinds = List.T(
38 ContentKind.T(),
39 optional=True,
40 help='Content kinds to be added to the Squirrel selection. By default '
41 'all known content kinds are added.')
42 include = String.T(
43 optional=True,
44 help='If not ``None``, files are only included if their paths match '
45 'the given regular expression pattern.')
46 exclude = String.T(
47 optional=True,
48 help='If not ``None``, files are only included if their paths do not '
49 'match the given regular expression pattern.')
50 format = FileFormat.T(
51 default='detect',
52 help='Assume files are of given format.')
54 def describe(self):
55 return 'localdata'
57 def setup(self, squirrel, check=True):
58 squirrel.add(
59 self.expand_path(self.paths),
60 kinds=self.kinds,
61 include=self.include,
62 exclude=self.exclude,
63 format=self.format,
64 check=check)
67__all__ = [
68 'FileFormat',
69 'ContentKind',
70 'LocalData']