当前位置: 首页>>代码示例>>Python>>正文


Python HydroShare.getResourceTypes方法代码示例

本文整理汇总了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)
开发者ID:mtpain,项目名称:hs_restclient,代码行数:16,代码来源:test_hs_restclient.py

示例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]
开发者ID:hydroshare,项目名称:hydroshare-jupyterhub,代码行数:69,代码来源:hydroshare.py


注:本文中的hs_restclient.HydroShare.getResourceTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。