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

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

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

#!/usr/bin/env python 

# 

# LSST Data Management System 

# Copyright 2016 LSST Corporation. 

# 

# This product includes software developed by the 

# LSST Project (http://www.lsst.org/). 

# 

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

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

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

# (at your option) any later version. 

# 

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

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

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the LSST License Statement and 

# the GNU General Public License along with this program. If not, 

# see <http://www.lsstcorp.org/LegalNotices/>. 

# 

 

from lsst.daf.persistence import Policy 

 

import yaml 

 

 

class AccessCfg(Policy, yaml.YAMLObject): 

yaml_tag = u"!AccessCfg" 

 

def __init__(self, cls, storageCfg): 

super().__init__({'storageCfg': storageCfg, 'cls': cls}) 

 

 

class Access: 

"""Implements an butler framework interface for Transport, Storage, and Registry 

 

.. warning:: 

 

Access is 'wet paint' and very likely to change. Use of it in production 

code other than via the 'old butler' API is strongly discouraged. 

 

""" 

 

@classmethod 

def cfg(cls, storageCfg): 

"""Helper func to create a properly formatted Policy to configure an Access instance. 

 

:param storageCfg: a cfg to instantiate a storage. 

:return: 

""" 

return AccessCfg(cls=cls, storageCfg=storageCfg) 

 

def __init__(self, cfg): 

"""Initializer 

 

:param cfg: a Policy that defines the configuration for this class. It is recommended that the cfg be 

created by calling Access.cfg() 

:return: 

""" 

self.storage = cfg['storageCfg.cls'](cfg['storageCfg']) 

 

def __repr__(self): 

return 'Access(storage=%s)' % self.storage 

 

def mapperClass(self): 

"""Get the mapper class associated with a repository root. 

 

:return: the mapper class 

""" 

return self.storage.mapperClass() 

 

def root(self): 

"""Get the repository root as defined by the Storage class, this refers to the 'top' of a persisted 

repository. The exact type of Root can vary based on Storage type. 

 

:return: the root of the persisted repository. 

""" 

 

return self.storage.root 

 

def locationWithRoot(self, location): 

"""Given a location, get a fully qualified handle to location including storage root. 

 

Note; at the time of this writing the only existing storage type is PosixStorage. This returns the 

root+location. 

:param location: 

:return: 

""" 

return self.storage.locationWithRoot(location) 

 

def setCfg(self, repoCfg): 

"""Writes the repository configuration to Storage. 

 

:param repoCfg: the Policy cfg to be written 

:return: None 

""" 

self.storage.setCfg(repoCfg) 

 

def loadCfg(self): 

"""Reads the repository configuration from Storage. 

 

:return: the Policy cfg 

""" 

return self.storage.loadCfg() 

 

def write(self, butlerLocation, obj): 

"""Passes an object to Storage to be written into the repository. 

 

:param butlerLocation: the location & formatting for the object to be written. 

:param obj: the object to be written. 

:return: None 

""" 

self.storage.write(butlerLocation, obj) 

 

def read(self, butlerLocation): 

"""Reads an object from storage 

 

:param butlerLocation: describes the location & how to load the object. 

:return: 

""" 

return self.storage.read(butlerLocation=butlerLocation) 

 

def exists(self, location): 

"""Query if a location exists. 

 

As of this writing the only storage type is PosixStorage, and it works to say that 'location' is a 

simple locaiton descriptor. In the case of PosixStorage that's a path. If this needs to become more 

complex it could be changed to be a butlerLocation, or something else, as needed. 

:param location: a simple location descriptor, type is dependent on Storage. 

:return: True if location exists, else False. 

""" 

return self.storage.exists(location) 

 

def lookup(self, *args, **kwargs): 

"""Perform a lookup in the registry. 

 

Returns a list of dataId for each valid lookup (right? TODO VERIFY)""" 

return self.storage.lookup(*args, **kwargs)