1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6import logging 

7 

8from pyrocko.guts import List, StringChoice, String 

9from pyrocko import has_paths 

10from . import base 

11from .. import io 

12 

13guts_prefix = 'squirrel' 

14 

15logger = logging.getLogger('psq.client.local') 

16 

17 

18class FileFormat(StringChoice): 

19 choices = ['detect'] + io.supported_formats() 

20 

21 

22class ContentKind(StringChoice): 

23 choices = io.base.g_content_kinds 

24 

25 

26class LocalData(base.Source, has_paths.HasPaths): 

27 ''' 

28 A collection of local files attachable as a Squirrel data-source. 

29 ''' 

30 paths = List.T( 

31 has_paths.Path.T(), 

32 help='Directory and file paths to add to the Squirrel ' 

33 'instance. See :py:meth:`Squirrel.add() ' 

34 '<pyrocko.squirrel.base.Squirrel.add>`.') 

35 kinds = List.T( 

36 ContentKind.T(), 

37 optional=True, 

38 help='Content kinds to be added to the Squirrel selection. By default ' 

39 'all known content kinds are added.') 

40 include = String.T( 

41 optional=True, 

42 help='If not ``None``, files are only included if their paths match ' 

43 'the given regular expression pattern.') 

44 exclude = String.T( 

45 optional=True, 

46 help='If not ``None``, files are only included if their paths do not ' 

47 'match the given regular expression pattern.') 

48 format = FileFormat.T( 

49 default='detect', 

50 help='Assume files are of given format.') 

51 

52 def describe(self): 

53 return 'localdata' 

54 

55 def setup(self, squirrel, check=True): 

56 squirrel.add( 

57 self.expand_path(self.paths), 

58 kinds=self.kinds, 

59 include=self.include, 

60 exclude=self.exclude, 

61 format=self.format, 

62 check=check) 

63 

64 

65__all__ = [ 

66 'FileFormat', 

67 'ContentKind', 

68 'LocalData']