Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/squirrel/client/local.py: 91%

23 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-10-06 15:01 +0000

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6''' 

7Data-source definition providing access local data. 

8''' 

9 

10import logging 

11 

12from pyrocko.guts import List, StringChoice, String 

13from pyrocko import has_paths 

14from . import base 

15from .. import io 

16 

17guts_prefix = 'squirrel' 

18 

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

20 

21 

22class FileFormat(StringChoice): 

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

24 

25 

26class ContentKind(StringChoice): 

27 choices = io.base.g_content_kinds 

28 

29 

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

31 ''' 

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

33 ''' 

34 paths = List.T( 

35 has_paths.Path.T(), 

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

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

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

39 kinds = List.T( 

40 ContentKind.T(), 

41 optional=True, 

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

43 'all known content kinds are added.') 

44 include = String.T( 

45 optional=True, 

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

47 'the given regular expression pattern.') 

48 exclude = String.T( 

49 optional=True, 

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

51 'match the given regular expression pattern.') 

52 format = FileFormat.T( 

53 default='detect', 

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

55 

56 def describe(self): 

57 return 'localdata' 

58 

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

60 squirrel.add( 

61 self.expand_path(self.paths), 

62 kinds=self.kinds, 

63 include=self.include, 

64 exclude=self.exclude, 

65 format=self.format, 

66 check=check) 

67 

68 

69__all__ = [ 

70 'FileFormat', 

71 'ContentKind', 

72 'LocalData']