本文整理汇总了Python中pyon.core.bootstrap.IonObject.resource方法的典型用法代码示例。如果您正苦于以下问题:Python IonObject.resource方法的具体用法?Python IonObject.resource怎么用?Python IonObject.resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.core.bootstrap.IonObject
的用法示例。
在下文中一共展示了IonObject.resource方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_extended_resource_container
# 需要导入模块: from pyon.core.bootstrap import IonObject [as 别名]
# 或者: from pyon.core.bootstrap.IonObject import resource [as 别名]
def create_extended_resource_container(self, extended_resource_type, resource_id, computed_resource_type=None,
ext_associations=None, ext_exclude=None):
if not self.service_provider or not self.resource_registry:
raise Inconsistent("This class is not initialized properly")
if extended_resource_type not in getextends(OT.ResourceContainer):
raise BadRequest('Requested resource %s is not extended from %s' % ( extended_resource_type, OT.ResourceContainer) )
if computed_resource_type and computed_resource_type not in getextends(OT.ComputedAttributes):
raise BadRequest('Requested resource %s is not extended from %s' % ( computed_resource_type, OT.ComputedAttributes) )
resource_object = self.resource_registry.read(resource_id)
if not resource_object:
raise NotFound("Resource %s does not exist" % resource_id)
res_container = IonObject(extended_resource_type)
res_container._id = resource_object._id
res_container.resource = resource_object
self.set_container_field_values(res_container, ext_exclude)
self.set_computed_attributes(res_container, computed_resource_type, ext_exclude)
self.set_extended_associations(res_container, ext_associations, ext_exclude)
res_container.ts_created = get_ion_ts()
return res_container
示例2: create_prepare_resource_support
# 需要导入模块: from pyon.core.bootstrap import IonObject [as 别名]
# 或者: from pyon.core.bootstrap.IonObject import resource [as 别名]
def create_prepare_resource_support(self, resource_id="", prepare_resource_type=None, origin_resource_type=None):
if not isinstance(resource_id, types.StringType):
raise Inconsistent("The parameter resource_id is not a single resource id string")
if not self.service_provider or not self._rr:
raise Inconsistent("This class is not initialized properly")
if prepare_resource_type is not None and prepare_resource_type not in getextends(OT.ResourcePrepareSupport):
raise BadRequest('The requested resource %s is not extended from %s' % (prepare_resource_type, OT.ResourcePrepareSupport))
resource_data = IonObject(prepare_resource_type)
# Check to make sure the extended resource decorator raise OriginResourceType matches the type of the resource type
origin_resource_decorator = resource_data.get_class_decorator_value('OriginResourceType')
if origin_resource_decorator is None and origin_resource_type is None:
raise NotFound('OriginResourceType decorator not found in object specification %s', prepare_resource_type)
origin_resource_type = origin_resource_type if origin_resource_type is not None else origin_resource_decorator
if origin_resource_type is None:
raise NotFound('OriginResourceType decorator not found in object specification %s', prepare_resource_type)
resource_object = None
if resource_id:
resource_object = self._rr.read(resource_id)
if origin_resource_type != resource_object.type_ and not issubtype(resource_object.type_, origin_resource_type):
raise Inconsistent('The OriginResourceType decorator of the requested resource %s(%s) does not match the type of the specified resource id(%s).' % (
prepare_resource_type, origin_resource_type, resource_object.type_))
resource_data._id = resource_object._id
else:
resource_object = IonObject(origin_resource_type)
resource_data.resource = resource_object
resource_data.resource_schema = get_object_schema(origin_resource_type)
for field in resource_data._schema:
deco_value = resource_data.get_decorator_value(field, 'AssociatedResources')
assoc_dict = {}
if deco_value is not None:
if deco_value.find(',') == -1:
associated_resources = [deco_value]
else:
associated_resources = deco_value.split(',')
for res in associated_resources:
assoc = self.get_associated_resource_info(origin_resource_type, resource_id, res)
assoc_dict[assoc.key] = assoc
setattr(resource_data, field, assoc_dict)
continue
return resource_data
示例3: create_extended_resource_container
# 需要导入模块: from pyon.core.bootstrap import IonObject [as 别名]
# 或者: from pyon.core.bootstrap.IonObject import resource [as 别名]
def create_extended_resource_container(self, extended_resource_type, resource_id, computed_resource_type=None,
ext_associations=None, ext_exclude=None):
overall_start_time = time.time()
if not isinstance(resource_id, types.StringType):
raise Inconsistent("The parameter resource_id is not a single resource id string")
if not self.service_provider or not self._rr:
raise Inconsistent("This class is not initialized properly")
if extended_resource_type not in getextends(OT.ResourceContainer):
raise BadRequest('The requested resource %s is not extended from %s' % (extended_resource_type, OT.ResourceContainer))
if computed_resource_type and computed_resource_type not in getextends(OT.ComputedAttributes):
raise BadRequest('The requested resource %s is not extended from %s' % (computed_resource_type, OT.ComputedAttributes))
resource_object = self._rr.read(resource_id)
if not resource_object:
raise NotFound("The Resource %s does not exist" % resource_id)
res_container = IonObject(extended_resource_type)
# @TODO - replace with object level decorators and raise exceptions
if not hasattr(res_container, 'origin_resource_type'):
log.error('The requested resource %s does not contain a properly set origin_resource_type field.' , extended_resource_type)
#raise Inconsistent('The requested resource %s does not contain a properly set origin_resource_type field.' % extended_resource_type)
if hasattr(res_container, 'origin_resource_type') and res_container.origin_resource_type != resource_object.type_\
and not issubtype(resource_object.type_, res_container.origin_resource_type):
log.error('The origin_resource_type of the requested resource %s(%s) does not match the type of the specified resource id(%s).' % (
extended_resource_type, res_container.origin_resource_type, resource_object.type_))
#raise Inconsistent('The origin_resource_type of the requested resource %s(%s) does not match the type of the specified resource id(%s).' % (extended_resource_type, res_container.origin_resource_type, resource_object.type_))
res_container._id = resource_object._id
res_container.resource = resource_object
self.set_container_lcstate_info(res_container)
self.set_container_field_values(res_container, ext_exclude)
self.set_computed_attributes(res_container, computed_resource_type, ext_exclude)
self.set_extended_associations(res_container, ext_associations, ext_exclude)
res_container.ts_created = get_ion_ts()
overall_stop_time = time.time()
log.debug("Time to process extended resource container %s %f secs", extended_resource_type, overall_stop_time - overall_start_time )
return res_container
示例4: create_extended_resource_container
# 需要导入模块: from pyon.core.bootstrap import IonObject [as 别名]
# 或者: from pyon.core.bootstrap.IonObject import resource [as 别名]
def create_extended_resource_container(
self,
extended_resource_type,
resource_id,
computed_resource_type=None,
ext_associations=None,
ext_exclude=None,
**kwargs
):
"""
Returns an extended resource container for a given resource_id.
"""
overall_start_time = time.time()
self.ctx = None # Clear the context in case this instance gets reused
if not isinstance(resource_id, types.StringType):
raise Inconsistent("The parameter resource_id is not a single resource id string")
if not self.service_provider or not self._rr:
raise Inconsistent("This class is not initialized properly")
if extended_resource_type not in getextends(OT.ResourceContainer):
raise BadRequest(
"The requested resource %s is not extended from %s" % (extended_resource_type, OT.ResourceContainer)
)
if computed_resource_type and computed_resource_type not in getextends(OT.BaseComputedAttributes):
raise BadRequest(
"The requested resource %s is not extended from %s"
% (computed_resource_type, OT.BaseComputedAttributes)
)
resource_object = self._rr.read(resource_id)
if not resource_object:
raise NotFound("The Resource %s does not exist" % resource_id)
res_container = IonObject(extended_resource_type)
# Check to make sure the extended resource decorator raise OriginResourceType matches the type of the resource type
originResourceType = res_container.get_class_decorator_value("OriginResourceType")
if originResourceType is None:
log.error(
"The requested extended resource %s does not contain an OriginResourceType decorator.",
extended_resource_type,
)
elif originResourceType != resource_object.type_ and not issubtype(resource_object.type_, originResourceType):
raise Inconsistent(
"The OriginResourceType decorator of the requested resource %s(%s) does not match the type of the specified resource id(%s)."
% (extended_resource_type, originResourceType, resource_object.type_)
)
res_container._id = resource_object._id
res_container.resource = resource_object
# Initialize context object field and load resource associations
self._prepare_context(resource_object._id)
# Fill lcstate related resource container fields
self.set_container_lcstate_info(res_container)
# Fill resource container info; currently only type_version
self.set_res_container_info(res_container)
# Fill resource container fields
self.set_container_field_values(res_container, ext_exclude, **kwargs)
# Fill computed attributes
self.set_computed_attributes(res_container, computed_resource_type, ext_exclude, **kwargs)
# Fill additional associations
self.set_extended_associations(res_container, ext_associations, ext_exclude)
res_container.ts_created = get_ion_ts()
overall_stop_time = time.time()
log.debug(
"Time to process extended resource container %s %f secs",
extended_resource_type,
overall_stop_time - overall_start_time,
)
# log.info("ResourceContainer: %s" % res_container)
return res_container