本文整理汇总了Python中st2common.persistence.pack.Pack.add_or_update方法的典型用法代码示例。如果您正苦于以下问题:Python Pack.add_or_update方法的具体用法?Python Pack.add_or_update怎么用?Python Pack.add_or_update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.pack.Pack
的用法示例。
在下文中一共展示了Pack.add_or_update方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUpClass
# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import add_or_update [as 别名]
def setUpClass(cls):
super(PacksControllerTestCase, cls).setUpClass()
cls.pack_db_1 = PackDB(name='pack1', description='foo', version='0.1.0', author='foo',
email='[email protected]', ref='pack1')
cls.pack_db_2 = PackDB(name='pack2', description='foo', version='0.1.0', author='foo',
email='[email protected]', ref='pack2')
Pack.add_or_update(cls.pack_db_1)
Pack.add_or_update(cls.pack_db_2)
示例2: _insert_common_mock_resources
# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import add_or_update [as 别名]
def _insert_common_mock_resources(self):
pack_1_db = PackDB(name='test_pack_1', ref='test_pack_1', description='',
version='0.1.0', author='foo', email='[email protected]')
pack_1_db = Pack.add_or_update(pack_1_db)
self.resources['pack_1'] = pack_1_db
pack_2_db = PackDB(name='test_pack_2', ref='test_pack_2', description='',
version='0.1.0', author='foo', email='[email protected]')
pack_2_db = Pack.add_or_update(pack_2_db)
self.resources['pack_2'] = pack_2_db
示例3: _register_pack
# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import add_or_update [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
示例4: _register_pack_db
# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import add_or_update [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
示例5: _register_pack_db
# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import add_or_update [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
示例6: _insert_common_mock_resources
# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import add_or_update [as 别名]
def _insert_common_mock_resources(self):
pack_1_db = PackDB(
name="test_pack_1",
ref="test_pack_1",
description="",
version="0.1.0",
author="foo",
email="[email protected]",
)
pack_1_db = Pack.add_or_update(pack_1_db)
self.resources["pack_1"] = pack_1_db
pack_2_db = PackDB(
name="test_pack_2",
ref="test_pack_2",
description="",
version="0.1.0",
author="foo",
email="[email protected]",
)
pack_2_db = Pack.add_or_update(pack_2_db)
self.resources["pack_2"] = pack_2_db
示例7: test_uid_is_populated_on_save
# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import add_or_update [as 别名]
def test_uid_is_populated_on_save(self):
pack_1_db = PackDB(ref='test_pack', name='test', description='foo', version='1.0.0',
author='dev', email='[email protected]')
pack_1_db = Pack.add_or_update(pack_1_db)
pack_1_db.reload()
self.assertEqual(pack_1_db.uid, 'pack:test_pack')
action_1_db = ActionDB(name='local', pack='core', ref='core.local', entry_point='',
runner_type={'name': 'local-shell-cmd'})
action_1_db = Action.add_or_update(action_1_db)
action_1_db.reload()
self.assertEqual(action_1_db.uid, 'action:core:local')
示例8: _update_pack_model
# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import add_or_update [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
示例9: _register_pack_db
# 需要导入模块: from st2common.persistence.pack import Pack [as 别名]
# 或者: from st2common.persistence.pack.Pack import add_or_update [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