本文整理汇总了Python中hs_restclient.HydroShare.getResourceTypes方法的典型用法代码示例。如果您正苦于以下问题:Python HydroShare.getResourceTypes方法的具体用法?Python HydroShare.getResourceTypes怎么用?Python HydroShare.getResourceTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hs_restclient.HydroShare
的用法示例。
在下文中一共展示了HydroShare.getResourceTypes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_resource_types
# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getResourceTypes [as 别名]
def test_get_resource_types(self):
hs = HydroShare()
res_type_proto = {'GenericResource',
'ModelInstanceResource',
'ModelProgramResource',
'NetcdfResource',
'RasterResource',
'RefTimeSeries',
'SWATModelInstanceResource',
'TimeSeriesResource',
'ToolResource'}
res_types = hs.getResourceTypes()
self.assertSetEqual(res_type_proto, res_types)
示例2: hydroshare
# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getResourceTypes [as 别名]
#.........这里部分代码省略.........
args:
-- resid: hydroshare resource id
returns:
-- resource metadata object
"""
science_meta = self.hs.getScienceMetadata(resid)
system_meta = self.hs.getSystemMetadata(resid)
return resource.ResourceMetadata(system_meta, science_meta)
def createHydroShareResource(self, abstract, title, derivedFromId=None,
keywords=[], resource_type='GenericResource',
content_files=[], public=False):
"""Creates a hydroshare resource.
args:
-- abstract: abstract for resource (str, required)
-- title: title of resource (str, required)
-- derivedFromId: id of parent hydroshare resource (str, default=>None)
-- keywords: list of subject keywords (list, default=>[])
-- resource_type: type of resource to create (str, default=>
'GenericResource')
-- content_files: data to save as resource content (list, default=>[])
-- public: resource sharing status (bool, default=>False)
returns:
-- None
"""
# query the hydroshare resource types and make sure that
# resource_type is valid
restypes = {r.lower(): r for r in self.hs.getResourceTypes()}
try:
res_type = restypes[resource_type]
except KeyError:
display(HTML('<b style="color:red;">[%s] is not a valid '
'HydroShare resource type.</p>' % resource_type))
return None
# get the 'derived resource' metadata
if derivedFromId is not None:
try:
# update the abstract and keyword metadata
meta = self.getResourceMetadata(derivedFromId)
abstract = meta.abstract \
+ '\n\n[Modified in JupyterHub on %s]\n%s' \
% (dt.now(), abstract)
keywords = set(keywords + meta.keywords)
except:
display(HTML('<b style="color:red;">Encountered an error '
' while setting the derivedFrom relationship '
' using id=%s. Make sure this resource is '
' is accessible to your account. '
% derivedFromId))
display(HTML('<a href=%s target="_blank">%s<a>' %
('https://www.hydroshare.org/resource/%s'
% derivedFromId, 'View the "DerivedFrom" '
'Resource')))
return None
f = None if len(content_files) == 0 else content_files[0]