26 """This module defines the ButlerLocation class.""" 30 from collections
import namedtuple
32 from past.builtins
import basestring
35 from .
import iterify, doImport
43 assembler : function object 44 Function object or importable string to a function object that can be called with the assembler 45 signature: (dataId, componentDict, cls). 46 disassembler : function object 47 Function object or importable string to a function object that can be called with the disassembler 48 signature: (object, dataId, componentDict). 50 A python class object or importable string to a class object that can be used by the assembler to 51 instantiate an object to be returned. 52 dataId : dict or DataId 53 The dataId that is used to look up components. 54 mapper : Mapper instance 55 A reference to the mapper that created this ButlerComposite object. 60 """Information about a butler composite object. Some details come from the policy and some are filled 61 in by the butler. Component info is used while assembling and disassembling a composite object in 62 butler. It is used as an input to assemblers and disassemblers (which are part of the butler public 68 The datasetType of the component. 70 The python object instance that is this component. 72 The name of the function in the parent object to set this component. 73 Optional - may be None 75 The name of the function in the parent object to get this component. 76 Optional - may be None 78 If true, indicates that the obj should be a list of objects found via butlerSubset. 80 If true, indicates that the obj should not be serialized when performing a butler.put. 82 def __init__(self, datasetType, obj, setter, getter, subset, inputOnly):
91 return 'ComponentInfo(datasetType:%s, obj:%s, setter:%s, getter:%s, subset:%s)' % \
96 return 'ButlerComposite(assembler:%s, disassembler:%s, python:%s, dataId:%s, mapper:%s, componentInfo:%s, repository:%s)' % \
106 return "ComponentInfo(datasetType=%s, obj=%s, setter=%s, getter=%s)" % (
107 self.datasetType, self.obj, self.setter, self.getter)
110 def __init__(self, assembler, disassembler, python, dataId, mapper):
119 def add(self, id, datasetType, setter, getter, subset, inputOnly):
120 """Add a description of a component needed to fetch the composite dataset. 125 The name of the component in the policy definition. 127 The name of the datasetType of the component. 128 setter : string or None 129 The name of the function used to set this component into the python type that contains it. 130 Specifying a setter is optional, use None if the setter won't be specified or used. 131 getter : string or None 132 The name of the function used to get this component from the python type that contains it. 133 Specifying a setter is optional, use None if the setter won't be specified or used. 135 If true, indicates that the obj should be a list of objects found via butlerSubset. 137 If true, indicates that the obj should not be serialized when performing a butler.put. 147 return "ButlerComposite(assembler=%s, disassembler=%s, python=%s, dataId=%s, components=%s)" % (
161 """ButlerLocation is a struct-like class that holds information needed to 162 persist and retrieve an object using the LSST Persistence Framework. 164 Mappers should create and return ButlerLocations from their 165 map_{datasetType} methods. 169 pythonType - string or class instance 170 This is the type of python object that should be created when reading the location. 172 cppType - string or None 173 The type of cpp object represented by the location (optional, may be None) 176 The type of storage the object is in or should be place into. 178 locationList - list of string 179 A list of URI to place the object or where the object might be found. (Typically when reading the 180 length is expected to be exactly 1). 183 The dataId that was passed in when mapping the location. This may include keys that were not used for 184 mapping this location. 186 mapper - mapper class instance 187 The mapper object that mapped this location. 189 storage - storage class instance 190 The storage interface that can be used to read or write this location. 193 The dataId components that were used to map this location. If the mapper had to look up keys those 194 will be in this dict (even though they may not appear in the dataId parameter). If the dataId 195 parameter contained keys that were not required to map this item then those keys will NOT be in this 199 The datasetType that this location represents. 202 yaml_tag =
u"!ButlerLocation" 203 yaml_loader = yaml.Loader
204 yaml_dumper = yaml.Dumper
208 'ButlerLocation(pythonType=%r, cppType=%r, storageName=%r, storage=%r, locationList=%r,' \
209 ' additionalData=%r, mapper=%r, dataId=%r)' % \
213 def __init__(self, pythonType, cppType, storageName, locationList, dataId, mapper, storage,
214 usedDataId=None, datasetType=None):
216 self.
pythonType = str(pythonType)
if isinstance(pythonType, basestring)
else pythonType
223 for k, v
in dataId.items():
236 """Representer for dumping to YAML 241 return dumper.represent_mapping(ButlerLocation.yaml_tag,
242 {
'pythonType': obj.pythonType,
'cppType': obj.cppType,
243 'storageName': obj.storageName,
244 'locationList': obj.locationList,
'mapper': obj.mapper,
245 'storage': obj.storage,
'dataId': obj.dataId})
249 obj = loader.construct_mapping(node)
def getAdditionalData(self)
def __init__(self, datasetType, obj, setter, getter, subset, inputOnly)
def from_yaml(loader, node)
def __init__(self, assembler, disassembler, python, dataId, mapper)
def __init__(self, pythonType, cppType, storageName, locationList, dataId, mapper, storage, usedDataId=None, datasetType=None)
def setRepository(self, repository)
def getLocationsWithRoot(self)
def add(self, id, datasetType, setter, getter, subset, inputOnly)
def setRepository(self, repository)