LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
butlerLocation.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #
4 # LSST Data Management System
5 # Copyright 2008, 2009, 2010 LSST Corporation.
6 #
7 # This product includes software developed by the
8 # LSST Project (http://www.lsst.org/).
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the LSST License Statement and
21 # the GNU General Public License along with this program. If not,
22 # see <http://www.lsstcorp.org/LegalNotices/>.
23 #
24 
25 
26 """This module defines the ButlerLocation class."""
27 
28 import lsst.daf.base as dafBase
29 
30 import yaml
31 
32 from . import iterify
33 
34 
35 class ButlerLocation(yaml.YAMLObject):
36  """ButlerLocation is a struct-like class that holds information needed to
37  persist and retrieve an object using the LSST Persistence Framework.
38 
39  Mappers should create and return ButlerLocations from their
40  map_{datasetType} methods."""
41 
42  yaml_tag = u"!ButlerLocation"
43  yaml_loader = yaml.Loader
44  yaml_dumper = yaml.Dumper
45 
46  def __repr__(self):
47  return \
48  'ButlerLocation(pythonType=%r, cppType=%r, storageName=%r, locationList=%r,' \
49  ' additionalData=%r, mapper=%r)' % \
50  (self.pythonType, self.cppType, self.storageName, self.locationList,
51  self.additionalData, self.mapper)
52 
53  def __init__(self, pythonType, cppType, storageName, locationList, dataId, mapper, storage=None):
54  self.pythonType = pythonType
55  self.cppType = cppType
56  self.storageName = storageName
57  self.mapper = mapper
58  self.storage = storage
59  self.locationList = iterify(locationList)
61  for k, v in dataId.items():
62  self.additionalData.set(k, v)
63  self.dataId = dataId
64 
65  def __str__(self):
66  s = "%s at %s(%s)" % (self.pythonType, self.storageName,
67  ", ".join(self.locationList))
68  return s
69 
70  @staticmethod
71  def to_yaml(dumper, obj):
72  """Representer for dumping to YAML
73  :param dumper:
74  :param obj:
75  :return:
76  """
77  return dumper.represent_mapping(ButlerLocation.yaml_tag,
78  {'pythonType': obj.pythonType, 'cppType': obj.cppType,
79  'storageName': obj.storageName,
80  'locationList': obj.locationList, 'mapper': obj.mapper,
81  'storage': obj.storage, 'dataId': obj.dataId})
82 
83  @staticmethod
84  def from_yaml(loader, node):
85  obj = loader.construct_mapping(node)
86  return ButlerLocation(**obj)
87 
88  def setRepository(self, repository):
89  self.repository = repository
90 
91  def getRepository(self):
92  return self.repository
93 
94  def getPythonType(self):
95  return self.pythonType
96 
97  def getCppType(self):
98  return self.cppType
99 
100  def getStorageName(self):
101  return self.storageName
102 
103  def getLocations(self):
104  return self.locationList
105 
106  def getAdditionalData(self):
107  return self.additionalData
Class for storing generic metadata.
Definition: PropertySet.h:82