LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
LSSTDataManagementBasePackage
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.daf.persistence.storage.Storage Class Reference

Public Member Functions

def __init__ (self)
 
def getRepositoryCfg (self, uri)
 

Static Public Member Functions

def registerStorageClass (scheme, cls)
 
def putRepositoryCfg (cfg, uri)
 
def getMapperClass (uri)
 
def makeFromURI (uri, create=True)
 
def isPosix (uri)
 
def relativePath (fromUri, toUri)
 
def absolutePath (fromUri, toUri)
 
def search (uri, path)
 
def storageExists (uri)
 

Public Attributes

 repositoryCfgs
 

Static Public Attributes

dictionary storages = {}
 

Detailed Description

Base class for storages

Definition at line 32 of file storage.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.daf.persistence.storage.Storage.__init__ (   self)

Definition at line 37 of file storage.py.

37  def __init__(self):
38  self.repositoryCfgs = {}
39 
def __init__(self, minimum, dataRange, Q)

Member Function Documentation

◆ absolutePath()

def lsst.daf.persistence.storage.Storage.absolutePath (   fromUri,
  toUri 
)
static
Get an absolute path for the path from fromUri to toUri

Parameters
----------
fromUri : the starting location
    Description
toUri : the location relative to fromUri
    Description

Returns
-------
string
    URI that is absolutepath fromUri + toUri, if one exists. If toUri is absolute or if fromUri is not
    related to toUri (e.g. are of different storage types) then toUri will be returned.

Definition at line 223 of file storage.py.

223  def absolutePath(fromUri, toUri):
224  """Get an absolute path for the path from fromUri to toUri
225 
226  Parameters
227  ----------
228  fromUri : the starting location
229  Description
230  toUri : the location relative to fromUri
231  Description
232 
233  Returns
234  -------
235  string
236  URI that is absolutepath fromUri + toUri, if one exists. If toUri is absolute or if fromUri is not
237  related to toUri (e.g. are of different storage types) then toUri will be returned.
238  """
239  fromUriParseRes = urllib.parse.urlparse(fromUri)
240  toUriParseRes = urllib.parse.urlparse(toUri)
241  if fromUriParseRes.scheme != toUriParseRes.scheme:
242  return toUri
243  storage = Storage.storages.get(fromUriParseRes.scheme, None)
244  if not storage:
245  return toUri
246  return storage.absolutePath(fromUri, toUri)
247 

◆ getMapperClass()

def lsst.daf.persistence.storage.Storage.getMapperClass (   uri)
static
Get a mapper class cfg value from location described by uri.

Note that in legacy repositories the mapper may be specified by a file called _mapper at the uri
location, and in newer repositories the mapper would be specified by a RepositoryCfg stored at the uri
location.

.. warning::

    Storage is 'wet paint' and very likely to change during factorization of Butler back end and
    storage formats (DM-6225). Use of it in production code other than via the 'old butler' API is
    strongly discouraged.

Definition at line 106 of file storage.py.

106  def getMapperClass(uri):
107  """Get a mapper class cfg value from location described by uri.
108 
109  Note that in legacy repositories the mapper may be specified by a file called _mapper at the uri
110  location, and in newer repositories the mapper would be specified by a RepositoryCfg stored at the uri
111  location.
112 
113  .. warning::
114 
115  Storage is 'wet paint' and very likely to change during factorization of Butler back end and
116  storage formats (DM-6225). Use of it in production code other than via the 'old butler' API is
117  strongly discouraged.
118 
119  """
120  ret = None
121  parseRes = urllib.parse.urlparse(uri)
122  if parseRes.scheme in Storage.storages:
123  ret = Storage.storages[parseRes.scheme].getMapperClass(uri)
124  else:
125  raise RuntimeError("No storage registered for scheme %s" % parseRes.scheme)
126  return ret
127 

◆ getRepositoryCfg()

def lsst.daf.persistence.storage.Storage.getRepositoryCfg (   self,
  uri 
)
Get a RepositoryCfg from a location specified by uri.

If a cfg is found then it is cached by the uri, so that multiple lookups
are not performed on storages that might be remote.

RepositoryCfgs are not supposed to change once they are created so this
should not lead to stale data.

Definition at line 73 of file storage.py.

73  def getRepositoryCfg(self, uri):
74  """Get a RepositoryCfg from a location specified by uri.
75 
76  If a cfg is found then it is cached by the uri, so that multiple lookups
77  are not performed on storages that might be remote.
78 
79  RepositoryCfgs are not supposed to change once they are created so this
80  should not lead to stale data.
81  """
82  cfg = self.repositoryCfgs.get(uri, None)
83  if cfg:
84  return cfg
85  parseRes = urllib.parse.urlparse(uri)
86  if parseRes.scheme in Storage.storages:
87  cfg = Storage.storages[parseRes.scheme].getRepositoryCfg(uri)
88  if cfg:
89  self.repositoryCfgs[uri] = cfg
90  else:
91  raise RuntimeError("No storage registered for scheme %s" % parseRes.scheme)
92  return cfg
93 

◆ isPosix()

def lsst.daf.persistence.storage.Storage.isPosix (   uri)
static
Test if a URI is for a local filesystem storage.

This is mostly for backward compatibility; Butler V1 repositories were only ever on the local
filesystem. They may exist but not have a RepositoryCfg class. This enables conditional checking for a
V1 Repository.

This function treats 'file' and '' (no scheme) as posix storages, see
the class docstring for more details.

Parameters
----------
uri : string
    URI to the root of a Repository.

Returns
-------
Bool
    True if the URI is associated with a posix storage, else false.

Definition at line 171 of file storage.py.

171  def isPosix(uri):
172  """Test if a URI is for a local filesystem storage.
173 
174  This is mostly for backward compatibility; Butler V1 repositories were only ever on the local
175  filesystem. They may exist but not have a RepositoryCfg class. This enables conditional checking for a
176  V1 Repository.
177 
178  This function treats 'file' and '' (no scheme) as posix storages, see
179  the class docstring for more details.
180 
181  Parameters
182  ----------
183  uri : string
184  URI to the root of a Repository.
185 
186  Returns
187  -------
188  Bool
189  True if the URI is associated with a posix storage, else false.
190  """
191  parseRes = urllib.parse.urlparse(uri)
192  if parseRes.scheme in ('file', ''):
193  return True
194  return False
195 

◆ makeFromURI()

def lsst.daf.persistence.storage.Storage.makeFromURI (   uri,
  create = True 
)
static
Instantiate a StorageInterface sublcass from a URI.

.. warning::

    Storage is 'wet paint' and very likely to change during factorization of Butler back end and
    storage formats (DM-6225). Use of it in production code other than via the 'old butler' API is
    strongly discouraged.

Parameters
----------
uri : string
    The uri to the root location of a repository.
create : bool, optional
    If True The StorageInterface subclass should create a new
    repository at the root location. If False then a new repository
    will not be created.

Returns
-------
A Storage subclass instance, or if create is False and a repository
does not exist at the root location then returns None.

Raises
------
RuntimeError
    When a StorageInterface subclass does not exist for the scheme
    indicated by the uri.

Definition at line 129 of file storage.py.

129  def makeFromURI(uri, create=True):
130  '''Instantiate a StorageInterface sublcass from a URI.
131 
132  .. warning::
133 
134  Storage is 'wet paint' and very likely to change during factorization of Butler back end and
135  storage formats (DM-6225). Use of it in production code other than via the 'old butler' API is
136  strongly discouraged.
137 
138  Parameters
139  ----------
140  uri : string
141  The uri to the root location of a repository.
142  create : bool, optional
143  If True The StorageInterface subclass should create a new
144  repository at the root location. If False then a new repository
145  will not be created.
146 
147  Returns
148  -------
149  A Storage subclass instance, or if create is False and a repository
150  does not exist at the root location then returns None.
151 
152  Raises
153  ------
154  RuntimeError
155  When a StorageInterface subclass does not exist for the scheme
156  indicated by the uri.
157  '''
158  ret = None
159  parseRes = urllib.parse.urlparse(uri)
160  if parseRes.scheme in Storage.storages:
161  theClass = Storage.storages[parseRes.scheme]
162  try:
163  ret = theClass(uri=uri, create=create)
164  except NoRepositroyAtRoot:
165  pass
166  else:
167  raise RuntimeError("No storage registered for scheme %s" % parseRes.scheme)
168  return ret
169 

◆ putRepositoryCfg()

def lsst.daf.persistence.storage.Storage.putRepositoryCfg (   cfg,
  uri 
)
static
Write a RepositoryCfg object to a location described by uri

Definition at line 95 of file storage.py.

95  def putRepositoryCfg(cfg, uri):
96  """Write a RepositoryCfg object to a location described by uri"""
97  ret = None
98  parseRes = urllib.parse.urlparse(uri)
99  if parseRes.scheme in Storage.storages:
100  ret = Storage.storages[parseRes.scheme].putRepositoryCfg(cfg, uri)
101  else:
102  raise RuntimeError("No storage registered for scheme %s" % parseRes.scheme)
103  return ret
104 

◆ registerStorageClass()

def lsst.daf.persistence.storage.Storage.registerStorageClass (   scheme,
  cls 
)
static
Register derived classes for lookup by URI scheme.

A scheme is a name that describes the form a resource at the beginning of a URI
e.g. 'http' indicates HTML and related code, such as is found in http://www.lsst.org

The only currently supported schemes are:
* 'file' where the portion of the URI after the // indicates an absolute locaiton on disk.
  for example: file:/my_repository_folder/
* '' (no scheme) where the entire string is a relative path on the local system
  for example "my_repository_folder" will indicate a folder in the current working directory with the
  same name.

See documentation for the urlparse python library for more information.

.. warning::

    Storage is 'wet paint' and very likely to change during factorization of Butler back end and
    storage formats (DM-6225). Use of it in production code other than via the 'old butler' API is
    strongly discouraged.

Parameters
----------
scheme : str
    Name of the `scheme` the class is being registered for, which appears at the beginning of a URI.
cls : class object
    A class object that should be used for a given scheme.

Definition at line 41 of file storage.py.

41  def registerStorageClass(scheme, cls):
42  """Register derived classes for lookup by URI scheme.
43 
44  A scheme is a name that describes the form a resource at the beginning of a URI
45  e.g. 'http' indicates HTML and related code, such as is found in http://www.lsst.org
46 
47  The only currently supported schemes are:
48  * 'file' where the portion of the URI after the // indicates an absolute locaiton on disk.
49  for example: file:/my_repository_folder/
50  * '' (no scheme) where the entire string is a relative path on the local system
51  for example "my_repository_folder" will indicate a folder in the current working directory with the
52  same name.
53 
54  See documentation for the urlparse python library for more information.
55 
56  .. warning::
57 
58  Storage is 'wet paint' and very likely to change during factorization of Butler back end and
59  storage formats (DM-6225). Use of it in production code other than via the 'old butler' API is
60  strongly discouraged.
61 
62  Parameters
63  ----------
64  scheme : str
65  Name of the `scheme` the class is being registered for, which appears at the beginning of a URI.
66  cls : class object
67  A class object that should be used for a given scheme.
68  """
69  if scheme in Storage.storages:
70  raise RuntimeError("Scheme '%s' already registered:%s" % (scheme, Storage.storages[scheme]))
71  Storage.storages[scheme] = cls
72 

◆ relativePath()

def lsst.daf.persistence.storage.Storage.relativePath (   fromUri,
  toUri 
)
static
Get a relative path from a location to a location, if a relative path for these 2 locations exists.

Parameters
----------
fromPath : string
    A URI that describes a location at which to start.
toPath : string
    A URI that describes a target location.

Returns
-------
string
    A relative path that describes the path from fromUri to toUri, provided one exists. If a relative
    path between the two URIs does not exist then the entire toUri path is returned.

Definition at line 197 of file storage.py.

197  def relativePath(fromUri, toUri):
198  """Get a relative path from a location to a location, if a relative path for these 2 locations exists.
199 
200  Parameters
201  ----------
202  fromPath : string
203  A URI that describes a location at which to start.
204  toPath : string
205  A URI that describes a target location.
206 
207  Returns
208  -------
209  string
210  A relative path that describes the path from fromUri to toUri, provided one exists. If a relative
211  path between the two URIs does not exist then the entire toUri path is returned.
212  """
213  fromUriParseRes = urllib.parse.urlparse(fromUri)
214  toUriParseRes = urllib.parse.urlparse(toUri)
215  if fromUriParseRes.scheme != toUriParseRes.scheme:
216  return toUri
217  storage = Storage.storages.get(fromUriParseRes.scheme, None)
218  if not storage:
219  return toUri
220  return storage.relativePath(fromUri, toUri)
221 

◆ search()

def lsst.daf.persistence.storage.Storage.search (   uri,
  path 
)
static
Look for the given path in a storage root at URI; return None if it can't be found.

If the path contains an HDU indicator (a number in brackets before the
dot, e.g. 'foo.fits[1]', this will be stripped when searching and so
will match filenames without the HDU indicator, e.g. 'foo.fits'. The
path returned WILL contain the indicator though, e.g. ['foo.fits[1]'].


Parameters
----------
root : string
    URI to the the root location to search
path : string
    A filename (and optionally prefix path) to search for within root.

Returns
-------
string or None
    The location that was found, or None if no location was found.

Definition at line 249 of file storage.py.

249  def search(uri, path):
250  """Look for the given path in a storage root at URI; return None if it can't be found.
251 
252  If the path contains an HDU indicator (a number in brackets before the
253  dot, e.g. 'foo.fits[1]', this will be stripped when searching and so
254  will match filenames without the HDU indicator, e.g. 'foo.fits'. The
255  path returned WILL contain the indicator though, e.g. ['foo.fits[1]'].
256 
257 
258  Parameters
259  ----------
260  root : string
261  URI to the the root location to search
262  path : string
263  A filename (and optionally prefix path) to search for within root.
264 
265  Returns
266  -------
267  string or None
268  The location that was found, or None if no location was found.
269  """
270  parseRes = urllib.parse.urlparse(uri)
271  storage = Storage.storages.get(parseRes.scheme, None)
272  if storage:
273  return storage.search(uri, path)
274  return None
275 

◆ storageExists()

def lsst.daf.persistence.storage.Storage.storageExists (   uri)
static
Ask if a storage at the location described by uri exists

Parameters
----------
root : string
    URI to the the root location of the storage

Returns
-------
bool
    True if the storage exists, false if not

Definition at line 277 of file storage.py.

277  def storageExists(uri):
278  """Ask if a storage at the location described by uri exists
279 
280  Parameters
281  ----------
282  root : string
283  URI to the the root location of the storage
284 
285  Returns
286  -------
287  bool
288  True if the storage exists, false if not
289  """
290  parseRes = urllib.parse.urlparse(uri)
291  storage = Storage.storages.get(parseRes.scheme, None)
292  if storage:
293  return storage.storageExists(uri)
294  return None
295 

Member Data Documentation

◆ repositoryCfgs

lsst.daf.persistence.storage.Storage.repositoryCfgs

Definition at line 38 of file storage.py.

◆ storages

dictionary lsst.daf.persistence.storage.Storage.storages = {}
static

Definition at line 35 of file storage.py.


The documentation for this class was generated from the following file: