23 from future
import standard_library
24 standard_library.install_aliases()
25 from builtins
import object
33 yaml_tag =
u"!AccessCfg"
36 super(AccessCfg, self).
__init__({
'storageCfg': storageCfg,
'cls': cls})
40 """Implements an butler framework interface for Transport, Storage, and Registry
44 Access is 'wet paint' and very likely to change. Use of it in production
45 code other than via the 'old butler' API is strongly discouraged.
50 def cfg(cls, storageCfg):
51 """Helper func to create a properly formatted Policy to configure an Access instance.
53 :param storageCfg: a cfg to instantiate a storage.
56 return AccessCfg(cls=cls, storageCfg=storageCfg)
61 :param cfg: a Policy that defines the configuration for this class. It is recommended that the cfg be
62 created by calling Access.cfg()
65 self.
storage = cfg[
'storageCfg.cls'](cfg[
'storageCfg'])
68 return 'Access(storage=%s)' % self.
storage
71 """Get the mapper class associated with a repository root.
73 :return: the mapper class
75 return self.storage.mapperClass()
78 """Get the repository root as defined by the Storage class, this refers to the 'top' of a persisted
79 repository. The exact type of Root can vary based on Storage type.
81 :return: the root of the persisted repository.
84 return self.storage.root
87 """Given a location, get a fully qualified handle to location including storage root.
89 Note; at the time of this writing the only existing storage type is PosixStorage. This returns the
94 return self.storage.locationWithRoot(location)
97 """Writes the repository configuration to Storage.
99 :param repoCfg: the Policy cfg to be written
102 self.storage.setCfg(repoCfg)
105 """Reads the repository configuration from Storage.
107 :return: the Policy cfg
109 return self.storage.loadCfg()
111 def write(self, butlerLocation, obj):
112 """Passes an object to Storage to be written into the repository.
114 :param butlerLocation: the location & formatting for the object to be written.
115 :param obj: the object to be written.
118 self.storage.write(butlerLocation, obj)
120 def read(self, butlerLocation):
121 """Reads an object from storage
123 :param butlerLocation: describes the location & how to load the object.
126 return self.storage.read(butlerLocation=butlerLocation)
129 """Query if a location exists.
131 As of this writing the only storage type is PosixStorage, and it works to say that 'location' is a
132 simple locaiton descriptor. In the case of PosixStorage that's a path. If this needs to become more
133 complex it could be changed to be a butlerLocation, or something else, as needed.
134 :param location: a simple location descriptor, type is dependent on Storage.
135 :return: True if location exists, else False.
137 return self.storage.exists(location)
140 """Perform a lookup in the registry.
142 Returns a list of dataId for each valid lookup (right? TODO VERIFY)"""
143 return self.storage.lookup(*args, **kwargs)