def _get_pet(self, species, name): entries = pets.get(species) if entries is None: return None entry = entries.get(name) if entry is None: return None handle = ResourceHandle(species, dict(name=name)) return self.pool.get_resource_from_handle(handle)
def get_variant(variant_handle): """Create a variant given its handle (or serialized dict equivalent) Args: variant_handle (`ResourceHandle` or dict): Resource handle, or equivalent serialized dict representation from ResourceHandle.to_dict Returns: `Variant`. """ if isinstance(variant_handle, dict): variant_handle = ResourceHandle.from_dict(variant_handle) variant_resource = package_repository_manager.get_resource_from_handle(variant_handle) variant = Variant(variant_resource) return variant
def get_package_from_handle(package_handle): """Create a package given its handle (or serialized dict equivalent) Args: package_handle (`ResourceHandle` or dict): Resource handle, or equivalent serialized dict representation from ResourceHandle.to_dict Returns: `Package`. """ if isinstance(package_handle, dict): package_handle = ResourceHandle.from_dict(package_handle) package_resource = package_repository_manager.get_resource_from_handle(package_handle) package = Package(package_resource) return package
def get_variant(variant_handle): """Create a variant given its handle. Args: variant_handle (`ResourceHandle` or dict): Resource handle, or equivalent dict. Returns: `Variant`. """ if isinstance(variant_handle, dict): variant_handle = ResourceHandle.from_dict(variant_handle) variant_resource = package_repository_manager.get_resource(variant_handle) variant = Variant(variant_resource) return variant
def get_variant(variant_handle, context=None): """Create a variant given its handle (or serialized dict equivalent) Args: variant_handle (`ResourceHandle` or dict): Resource handle, or equivalent serialized dict representation from ResourceHandle.to_dict context (`ResolvedContext`): The context this variant is associated with, if any. Returns: `Variant`. """ if isinstance(variant_handle, dict): variant_handle = ResourceHandle.from_dict(variant_handle) variant_resource = package_repository_manager.get_resource_from_handle(variant_handle) variant = Variant(variant_resource, context=context) return variant
def make_resource_handle(self, resource_key, **variables): """Create a `ResourceHandle` Nearly all `ResourceHandle` creation should go through here, because it gives the various resource classes a chance to normalize / standardize the resource handles, to improve caching / comparison / etc. """ if variables.get("repository_type", self.name()) != self.name(): raise ResourceError("repository_type mismatch - requested %r, " "repository_type is %r" % (variables["repository_type"], self.name())) variables["repository_type"] = self.name() if variables.get("location", self.location) != self.location: raise ResourceError("location mismatch - requested %r, repository " "location is %r" % (variables["location"], self.location)) variables["location"] = self.location resource_cls = self.pool.get_resource_class(resource_key) variables = resource_cls.normalize_variables(variables) return ResourceHandle(resource_key, variables)
def get_resource(self, resource_key, variables=None): variables = variables or {} handle = ResourceHandle(resource_key, variables) return self.get_resource_from_handle(handle)
def get_resource(self, resource_key, **variables): variables["repository_type"] = self.name() handle = ResourceHandle(resource_key, variables) return self.get_resource_from_handle(handle)