Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# This file is part of daf_butler. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <http://www.gnu.org/licenses/>. 

21 

22import fnmatch 

23import re 

24 

25from .. import Butler 

26 

27 

28def _translateExpr(expr): 

29 """Translate glob-style search terms to regex. 

30 

31 Parameters 

32 ---------- 

33 expr : `str` or `...` 

34 A glob-style pattern string to convert, or an Ellipsis. 

35 

36 Returns 

37 ------- 

38 expressions : [`str` or `...`] 

39 A list of expressions that are either regex or Ellipsis. 

40 """ 

41 if expr == ...: 

42 return expr 

43 return re.compile(fnmatch.translate(expr)) 

44 

45 

46def queryDatasetTypes(repo, verbose, glob, components): 

47 """Get the dataset types in a repository. 

48 

49 Parameters 

50 ---------- 

51 repo : `str` 

52 URI to the location of the repo or URI to a config file describing the 

53 repo and its location. 

54 verbose : `bool` 

55 If false only return the name of the dataset types. If false return 

56 name, dimensions, and storage class of each dataset type. 

57 glob : [`str`] 

58 A list of glob-style search string that fully or partially identify 

59 the dataset type names to search for. 

60 components : `bool` or `None` 

61 If `True`, apply all glob patterns to component dataset type 

62 names as well. If `False`, never apply patterns to components. If 

63 `None` (default), apply patterns to components only if their parent 

64 datasets were not matched by the expression. Fully-specified component 

65 datasets (`str` or `DatasetType` instances) are always included. 

66 

67 Returns 

68 ------- 

69 collections : `dict` [`str`, [`str`]] 

70 A dict whose key is 'datasetTypes' and whose value is a list of 

71 collection names. 

72 """ 

73 butler = Butler(repo) 

74 kwargs = dict() 

75 if glob: 

76 kwargs['expression'] = [_translateExpr(g) for g in glob] 

77 kwargs['components'] = components 

78 datasetTypes = butler.registry.queryDatasetTypes(**kwargs) 

79 if verbose: 

80 info = [dict(name=datasetType.name, 

81 dimensions=list(datasetType.dimensions.names), 

82 storageClass=datasetType.storageClass.name) 

83 for datasetType in datasetTypes] 

84 else: 

85 info = [datasetType.name for datasetType in datasetTypes] 

86 return {'datasetTypes': info}