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


Python ContentPackLoader.get_content方法代码示例

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


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

示例1: test_invalid_content_type

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content [as 别名]
 def test_invalid_content_type(self):
     packs_base_path = os.path.join(
         os.path.dirname(os.path.realpath(__file__)), 'resources/packs/')
     loader = ContentPackLoader()
     try:
         loader.get_content(base_dir=packs_base_path, content_type='stuff')
         self.fail('Asking for invalid content should have thrown.')
     except:
         pass
开发者ID:bjoernbessert,项目名称:st2,代码行数:11,代码来源:test_content_loader.py

示例2: _get_api_models_from_disk

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content [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

示例3: _get_user_sensors

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content [as 别名]
def _get_user_sensors():
    sensors_dict = defaultdict(list)
    pack_loader = ContentPackLoader()
    sensor_loader = SensorLoader()
    packs = pack_loader.get_content(base_dir=cfg.CONF.content.packs_base_path,
                                    content_type='sensors')
    for pack, sensor_dir in six.iteritems(packs):
        try:
            LOG.info('Loading sensors from pack: %s, dir: %s', pack, sensor_dir)
            if _is_requirements_ok(sensor_dir):
                base_dir = os.path.realpath(sensor_dir)
                pack_sensors = sensor_loader.get_sensors(base_dir=base_dir)

                # Include content pack name on the sensor class
                # TODO: This is nasty
                pack_sensors_augmented = defaultdict(list)
                for filename, sensors in pack_sensors.iteritems():
                    for sensor in sensors:
                        sensor.pack = pack
                        pack_sensors_augmented[filename].append(sensor)

                sensors_dict.update(pack_sensors_augmented)
            else:
                LOG.warning('Not registering sensors in sensor_dir: %s.', sensor_dir)
        except:
            LOG.exception('Failed loading sensors from dir: %s' % sensor_dir)
    return sensors_dict
开发者ID:bjoernbessert,项目名称:st2,代码行数:29,代码来源:sensormanager.py

示例4: register_actions_from_packs

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content [as 别名]
 def register_actions_from_packs(self, base_dir):
     pack_loader = ContentPackLoader()
     dirs = pack_loader.get_content(base_dir=base_dir,
                                    content_type='actions')
     for pack, actions_dir in six.iteritems(dirs):
         try:
             actions = self._get_actions_from_pack(actions_dir)
             self._register_actions_from_pack(pack, actions)
         except:
             LOG.exception('Failed registering all actions from pack: %s', actions_dir)
开发者ID:ojacques,项目名称:st2,代码行数:12,代码来源:actionsregistrar.py

示例5: register_rules_from_packs

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content [as 别名]
 def register_rules_from_packs(self, base_dir):
     pack_loader = ContentPackLoader()
     dirs = pack_loader.get_content(base_dir=base_dir,
                                    content_type='rules')
     for pack, rules_dir in six.iteritems(dirs):
         try:
             LOG.info('Registering rules from pack: %s', pack)
             rules = self._get_rules_from_pack(rules_dir)
             self._register_rules_from_pack(pack, rules)
         except:
             LOG.exception('Failed registering all rules from pack: %s', rules_dir)
开发者ID:bjoernbessert,项目名称:st2,代码行数:13,代码来源:rulesregistrar.py

示例6: register_sensors_from_packs

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content [as 别名]
    def register_sensors_from_packs(self, base_dir):
        pack_loader = ContentPackLoader()
        dirs = pack_loader.get_content(base_dir=base_dir, content_type='sensors')

        # Add system sensors to the core pack
        dirs['core'] = {}
        dirs['core'] = SYSTEM_SENSORS_PATH

        for pack, sensors_dir in six.iteritems(dirs):
            try:
                LOG.info('Registering sensors from pack: %s', pack)
                sensors = self._get_sensors_from_pack(sensors_dir)
                self._register_sensors_from_pack(pack=pack, sensors=sensors)
            except Exception as e:
                LOG.exception('Failed registering all sensors from pack "%s": %s', sensors_dir,
                              str(e))
开发者ID:nagyist,项目名称:StackStorm-st2,代码行数:18,代码来源:sensorsregistrar.py

示例7: test_get_content_multiple_directories

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content [as 别名]
    def test_get_content_multiple_directories(self):
        packs_base_path_1 = os.path.join(RESOURCES_DIR, 'packs/')
        packs_base_path_2 = os.path.join(RESOURCES_DIR, 'packs2/')
        base_dirs = [packs_base_path_1, packs_base_path_2]

        LOG.warning = Mock()

        loader = ContentPackLoader()
        sensors = loader.get_content(base_dirs=base_dirs, content_type='sensors')
        self.assertTrue('pack1' in sensors)  # from packs/
        self.assertTrue('pack3' in sensors)  # from packs2/

        # Assert that a warning is emitted when a duplicated pack is found
        expected_msg = ('Pack "pack1" already found in '
                        '"%s/packs/", ignoring content from '
                        '"%s/packs2/"' % (RESOURCES_DIR, RESOURCES_DIR))
        LOG.warning.assert_called_once_with(expected_msg)
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:19,代码来源:test_content_loader.py

示例8: test_get_sensors

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content [as 别名]
 def test_get_sensors(self):
     packs_base_path = os.path.join(RESOURCES_DIR, 'packs/')
     loader = ContentPackLoader()
     pack_sensors = loader.get_content(base_dirs=[packs_base_path], content_type='sensors')
     self.assertTrue(pack_sensors.get('pack1', None) is not None)
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:7,代码来源:test_content_loader.py

示例9: test_get_sensors

# 需要导入模块: from st2common.content.loader import ContentPackLoader [as 别名]
# 或者: from st2common.content.loader.ContentPackLoader import get_content [as 别名]
 def test_get_sensors(self):
     packs_base_path = os.path.join(
         os.path.dirname(os.path.realpath(__file__)), 'resources/packs/')
     loader = ContentPackLoader()
     pack_sensors = loader.get_content(base_dir=packs_base_path, content_type='sensors')
     self.assertTrue(pack_sensors.get('pack1', None) is not None)
开发者ID:bjoernbessert,项目名称:st2,代码行数:8,代码来源:test_content_loader.py


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