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


Python ContentPackLoader.get_content_from_pack方法代码示例

本文整理汇总了Python中st2common.content.loader.ContentPackLoader.get_content_from_pack方法的典型用法代码示例。如果您正苦于以下问题:Python ContentPackLoader.get_content_from_pack方法的具体用法?Python ContentPackLoader.get_content_from_pack怎么用?Python ContentPackLoader.get_content_from_pack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在st2common.content.loader.ContentPackLoader的用法示例。


在下文中一共展示了ContentPackLoader.get_content_from_pack方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_api_models_from_disk

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content_from_pack [as 别名]
def _get_api_models_from_disk(artifact_type, pack_dir=None):
    loader = ContentPackLoader()
    artifacts = None

    if pack_dir:
        artifacts_dir = loader.get_content_from_pack(pack_dir, artifact_type)
        pack_name = os.path.basename(os.path.normpath(pack_dir))
        artifacts = {pack_name: artifacts_dir}
    else:
        packs_dirs = content_utils.get_packs_base_paths()
        artifacts = loader.get_content(packs_dirs, artifact_type)

    artifacts_dict = {}
    for pack_name, pack_path in artifacts.items():
        artifacts_paths = registrar.get_resources_from_pack(pack_path)
        for artifact_path in artifacts_paths:
            artifact = meta_loader.load(artifact_path)
            if artifact_type == "sensors":
                sensors_dir = os.path.dirname(artifact_path)
                sensor_file_path = os.path.join(sensors_dir, artifact["entry_point"])
                artifact["artifact_uri"] = "file://" + sensor_file_path
            name = artifact.get("name", None) or artifact.get("class_name", None)
            if not artifact.get("pack", None):
                artifact["pack"] = pack_name
            ref = ResourceReference.to_string_reference(name=name, pack=pack_name)
            API_MODEL = API_MODELS_ARTIFACT_TYPES[artifact_type]
            # Following conversions are required because we add some fields with
            # default values in db model. If we don't do these conversions,
            # we'll see a unnecessary diff for those fields.
            artifact_api = API_MODEL(**artifact)
            artifact_db = API_MODEL.to_model(artifact_api)
            artifact_api = API_MODEL.from_model(artifact_db)
            artifacts_dict[ref] = artifact_api

    return artifacts_dict
开发者ID:azamsheriff,项目名称:st2,代码行数:37,代码来源:diff-db-disk.py

示例2: _get_action_alias_db_by_name

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content_from_pack [as 别名]
    def _get_action_alias_db_by_name(self, name):
        """
        Retrieve ActionAlias DB object for the provided alias name.
        """
        base_pack_path = self._get_base_pack_path()
        pack_yaml_path = os.path.join(base_pack_path, MANIFEST_FILE_NAME)

        if os.path.isfile(pack_yaml_path):
            # 1. 1st try to infer pack name from pack metadata file
            meta_loader = MetaLoader()
            pack_metadata = meta_loader.load(pack_yaml_path)
            pack = get_pack_ref_from_metadata(metadata=pack_metadata)
        else:
            # 2. If pack.yaml is not available, fail back to directory name
            # Note: For this to work, directory name needs to match pack name
            _, pack = os.path.split(base_pack_path)

        pack_loader = ContentPackLoader()
        registrar = AliasesRegistrar(use_pack_cache=False)

        aliases_path = pack_loader.get_content_from_pack(pack_dir=base_pack_path,
                                                         content_type='aliases')
        aliases = registrar._get_aliases_from_pack(aliases_dir=aliases_path)
        for alias_path in aliases:
            action_alias_db = registrar._get_action_alias_db(pack=pack,
                                                             action_alias=alias_path,
                                                             ignore_metadata_file_error=True)

            if action_alias_db.name == name:
                return action_alias_db

        raise ValueError('Alias with name "%s" not found' % (name))
开发者ID:nzlosh,项目名称:st2,代码行数:34,代码来源:action_aliases.py

示例3: _get_action_alias_db_by_name

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content_from_pack [as 别名]
    def _get_action_alias_db_by_name(self, name):
        """
        Retrieve ActionAlias DB object for the provided alias name.
        """
        base_pack_path = self._get_base_pack_path()
        _, pack = os.path.split(base_pack_path)

        pack_loader = ContentPackLoader()
        registrar = AliasesRegistrar(use_pack_cache=False)

        aliases_path = pack_loader.get_content_from_pack(pack_dir=base_pack_path,
                                                         content_type='aliases')
        aliases = registrar._get_aliases_from_pack(aliases_dir=aliases_path)
        for alias_path in aliases:
            action_alias_db = registrar._get_action_alias_db(pack=pack,
                                                             action_alias=alias_path)

            if action_alias_db.name == name:
                return action_alias_db

        raise ValueError('Alias with name "%s" not found' % (name))
开发者ID:E-LLP,项目名称:st2,代码行数:23,代码来源:action_aliases.py

示例4: test_get_content_from_pack_no_sensors

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content_from_pack [as 别名]
    def test_get_content_from_pack_no_sensors(self):
        loader = ContentPackLoader()
        pack_path = os.path.join(RESOURCES_DIR, 'packs/pack2')

        result = loader.get_content_from_pack(pack_dir=pack_path, content_type='sensors')
        self.assertEqual(result, None)
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:8,代码来源:test_content_loader.py

示例5: test_get_content_from_pack_success

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content_from_pack [as 别名]
    def test_get_content_from_pack_success(self):
        loader = ContentPackLoader()
        pack_path = os.path.join(RESOURCES_DIR, 'packs/pack1')

        sensors = loader.get_content_from_pack(pack_dir=pack_path, content_type='sensors')
        self.assertTrue(sensors.endswith('packs/pack1/sensors'))
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:8,代码来源:test_content_loader.py


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