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


Python Pack.get_by_ref方法代码示例

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


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

示例1: _register_pack_db

# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import get_by_ref [as 别名]
    def _register_pack_db(self, pack_name, pack_dir):
        manifest_path = os.path.join(pack_dir, MANIFEST_FILE_NAME)

        if not os.path.isfile(manifest_path):
            raise ValueError('Pack "%s" is missing %s file' % (pack_name, MANIFEST_FILE_NAME))

        content = self._meta_loader.load(manifest_path)
        if not content:
            raise ValueError('Pack "%s" metadata file is empty' % (pack_name))

        content['ref'] = pack_name

        # Include a list of pack files
        pack_file_list = get_file_list(directory=pack_dir, exclude_patterns=EXCLUDE_FILE_PATTERNS)
        content['files'] = pack_file_list

        pack_api = PackAPI(**content)
        pack_db = PackAPI.to_model(pack_api)

        try:
            pack_db.id = Pack.get_by_ref(pack_name).id
        except StackStormDBObjectNotFoundError:
            LOG.debug('Pack %s not found. Creating new one.', pack_name)

        pack_db = Pack.add_or_update(pack_db)
        LOG.debug('Pack %s registered.' % (pack_name))
        return pack_db
开发者ID:Bala96,项目名称:st2,代码行数:29,代码来源:base.py

示例2: _register_pack

# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import get_by_ref [as 别名]
    def _register_pack(self, pack_name, pack_dir):
        """
        Register a pack (create a DB object in the system).

        Note: Pack registration now happens when registering the content and not when installing
        a pack using packs.install. Eventually this will be moved to the pack management API.
        """
        manifest_path = os.path.join(pack_dir, MANIFEST_FILE_NAME)

        if not os.path.isfile(manifest_path):
            raise ValueError('Pack "%s" is missing %s file' % (pack_name, MANIFEST_FILE_NAME))

        content = self._meta_loader.load(manifest_path)
        if not content:
            raise ValueError('Pack "%s" metadata file is empty' % (pack_name))

        content['ref'] = pack_name
        pack_api = PackAPI(**content)
        pack_db = PackAPI.to_model(pack_api)

        try:
            pack_db.id = Pack.get_by_ref(pack_name).id
        except ValueError:
            LOG.debug('Pack %s not found. Creating new one.', pack_name)

        pack_db = Pack.add_or_update(pack_db)
        LOG.debug('Pack %s registered.' % (pack_name))
        return pack_db
开发者ID:ruslantum,项目名称:st2,代码行数:30,代码来源:base.py

示例3: _register_pack_db

# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import get_by_ref [as 别名]
    def _register_pack_db(self, pack_name, pack_dir):
        content = get_pack_metadata(pack_dir=pack_dir)

        # The rules for the pack ref are as follows:
        # 1. If ref attribute is available, we used that
        # 2. If pack_name is available we use that (this only applies to packs
        # 2hich are in sub-directories)
        # 2. If attribute is not available, but pack name is and pack name meets the valid name
        # criteria, we use that
        content['ref'] = get_pack_ref_from_metadata(metadata=content,
                                                    pack_directory_name=pack_name)

        # Include a list of pack files
        pack_file_list = get_file_list(directory=pack_dir, exclude_patterns=EXCLUDE_FILE_PATTERNS)
        content['files'] = pack_file_list

        pack_api = PackAPI(**content)
        pack_api.validate()
        pack_db = PackAPI.to_model(pack_api)

        try:
            pack_db.id = Pack.get_by_ref(content['ref']).id
        except StackStormDBObjectNotFoundError:
            LOG.debug('Pack %s not found. Creating new one.', pack_name)

        pack_db = Pack.add_or_update(pack_db)
        LOG.debug('Pack %s registered.' % (pack_name))
        return pack_db
开发者ID:Plexxi,项目名称:st2,代码行数:30,代码来源:base.py

示例4: _delete_pack_db_object

# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import get_by_ref [as 别名]
    def _delete_pack_db_object(self, pack):
        pack_db = None

        # 1. Try by ref
        try:
            pack_db = Pack.get_by_ref(value=pack)
        except StackStormDBObjectNotFoundError:
            pack_db = None

        # 2. Try by name (here for backward compatibility)
        # TODO: This shouldn't be needed in the future, remove it in v2.1 or similar
        if not pack_db:
            try:
                pack_db = Pack.get_by_name(value=pack)
            except StackStormDBObjectNotFoundError:
                pack_db = None

        if not pack_db:
            self.logger.exception('Pack DB object not found')
            return

        try:
            Pack.delete(pack_db)
        except:
            self.logger.exception('Failed to remove DB object %s.', pack_db)
开发者ID:nzlosh,项目名称:st2,代码行数:27,代码来源:unload.py

示例5: test_post_include_files

# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import get_by_ref [as 别名]
    def test_post_include_files(self):
        # Verify initial state
        pack_db = Pack.get_by_ref(ACTION_12["pack"])
        self.assertTrue("actions/filea.txt" not in pack_db.files)

        action = copy.deepcopy(ACTION_12)
        action["data_files"] = [{"file_path": "filea.txt", "content": "test content"}]
        post_resp = self.__do_post(action)

        # Verify file has been written on disk
        for file_path in self.to_delete_files:
            self.assertTrue(os.path.exists(file_path))

        # Verify PackDB.files has been updated
        pack_db = Pack.get_by_ref(ACTION_12["pack"])
        self.assertTrue("actions/filea.txt" in pack_db.files)
        self.__do_delete(self.__get_action_id(post_resp))
开发者ID:rlugojr,项目名称:st2,代码行数:19,代码来源:test_actions.py

示例6: test_post_include_files

# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import get_by_ref [as 别名]
    def test_post_include_files(self):
        # Verify initial state
        pack_db = Pack.get_by_ref(ACTION_12['pack'])
        self.assertTrue('actions/filea.txt' not in pack_db.files)

        action = copy.deepcopy(ACTION_12)
        action['data_files'] = [
            {
                'file_path': 'filea.txt',
                'content': 'test content'
            }
        ]
        post_resp = self.__do_post(action)

        # Verify file has been written on disk
        for file_path in self.to_delete_files:
            self.assertTrue(os.path.exists(file_path))

        # Verify PackDB.files has been updated
        pack_db = Pack.get_by_ref(ACTION_12['pack'])
        self.assertTrue('actions/filea.txt' in pack_db.files)
        self.__do_delete(self.__get_action_id(post_resp))
开发者ID:E-LLP,项目名称:st2,代码行数:24,代码来源:test_actions.py

示例7: _update_pack_model

# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import get_by_ref [as 别名]
    def _update_pack_model(self, pack_name, data_files, written_file_paths):
        """
        Update PackDB models (update files list).
        """
        file_paths = []  # A list of paths relative to the pack directory for new files
        for file_path in written_file_paths:
            file_path = get_relative_path_to_pack(pack_name=pack_name, file_path=file_path)
            file_paths.append(file_path)

        pack_db = Pack.get_by_ref(pack_name)
        pack_db.files = set(pack_db.files)
        pack_db.files.update(set(file_paths))
        pack_db.files = list(pack_db.files)
        pack_db = Pack.add_or_update(pack_db)

        return pack_db
开发者ID:jspittman,项目名称:st2,代码行数:18,代码来源:actions.py

示例8: _register_pack_db

# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import get_by_ref [as 别名]
    def _register_pack_db(self, pack_name, pack_dir):
        pack_name = pack_name or ''
        manifest_path = os.path.join(pack_dir, MANIFEST_FILE_NAME)

        if not os.path.isfile(manifest_path):
            raise ValueError('Pack "%s" is missing %s file' % (pack_name, MANIFEST_FILE_NAME))

        content = self._meta_loader.load(manifest_path)
        if not content:
            raise ValueError('Pack "%s" metadata file is empty' % (pack_name))

        # The rules for the pack ref are as follows:
        # 1. If ref attribute is available, we used that
        # 2. If pack_name is available we use that (this only applies to packs
        # 2hich are in sub-directories)
        # 2. If attribute is not available, but pack name is and pack name meets the valid name
        # criteria, we use that
        content['ref'] = get_pack_ref_from_metadata(metadata=content,
                                                    pack_directory_name=pack_name)

        # Include a list of pack files
        pack_file_list = get_file_list(directory=pack_dir, exclude_patterns=EXCLUDE_FILE_PATTERNS)
        content['files'] = pack_file_list

        pack_api = PackAPI(**content)
        pack_api.validate()
        pack_db = PackAPI.to_model(pack_api)

        try:
            pack_db.id = Pack.get_by_ref(content['ref']).id
        except StackStormDBObjectNotFoundError:
            LOG.debug('Pack %s not found. Creating new one.', pack_name)

        pack_db = Pack.add_or_update(pack_db)
        LOG.debug('Pack %s registered.' % (pack_name))
        return pack_db
开发者ID:LindsayHill,项目名称:st2,代码行数:38,代码来源:base.py

示例9: test_get_pack_files_binary_files_are_excluded

# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import get_by_ref [as 别名]
    def test_get_pack_files_binary_files_are_excluded(self):
        binary_files = [
            'icon.png',
            'etc/permissions.png',
            'etc/travisci.png',
            'etc/generate_new_token.png'
        ]

        pack_db = Pack.get_by_ref('dummy_pack_1')

        all_files_count = len(pack_db.files)
        non_binary_files_count = all_files_count - len(binary_files)

        resp = self.app.get('/v1/packs/views/files/dummy_pack_1')
        self.assertEqual(resp.status_int, httplib.OK)
        self.assertEqual(len(resp.json), non_binary_files_count)

        for file_path in binary_files:
            self.assertTrue(file_path in pack_db.files)

        # But not in files controller response
        for file_path in binary_files:
            item = [item for item in resp.json if item['file_path'] == file_path]
            self.assertFalse(item)
开发者ID:peak6,项目名称:st2,代码行数:26,代码来源:test_packs_views.py

示例10: get_pack_by_ref

# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import get_by_ref [as 别名]
def get_pack_by_ref(pack_ref):
    """
    Retrieve PackDB by the provided reference.
    """
    pack_db = Pack.get_by_ref(pack_ref)
    return pack_db
开发者ID:LindsayHill,项目名称:st2,代码行数:8,代码来源:packs.py

示例11: get_pack_common_libs_path_for_pack_ref

# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import get_by_ref [as 别名]
def get_pack_common_libs_path_for_pack_ref(pack_ref):
    pack_db = Pack.get_by_ref(pack_ref)
    pack_common_libs_path = get_pack_common_libs_path_for_pack_db(pack_db=pack_db)
    return pack_common_libs_path
开发者ID:StackStorm,项目名称:st2,代码行数:6,代码来源:pack.py


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