本文整理匯總了Python中result.Result.add方法的典型用法代碼示例。如果您正苦於以下問題:Python Result.add方法的具體用法?Python Result.add怎麽用?Python Result.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類result.Result
的用法示例。
在下文中一共展示了Result.add方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_sources_are_stored
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
def test_sources_are_stored(self):
r = Result()
r.add("foo", Source("handle", "what they twote about foo", "twitter.com/linktotweet"))
s = r.get_source_list("foo")
self.assertEqual(s[0].handle, "handle")
self.assertEqual(s[0].text, "what they twote about foo")
self.assertEqual(s[0].link, "twitter.com/linktotweet")
示例2: collate_words
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
def collate_words(self, meme, sources):
"""Given a list of Sources and a Meme, populate a Result
object with matching words"""
regex = self._format_regex(meme)
result = Result()
for source in sources:
match = re.search(regex, source.text, re.IGNORECASE)
if match:
result.add(match.groups()[0].lower(), source)
#assumption: there was exactly one match
return result
示例3: run_filters
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
def run_filters(self, filters, hostIDs, vmID, properties_map):
result = Result()
request_id = str(uuid.uuid1())
log_adapter = \
utils.RequestAdapter(self._logger,
{'method': 'run_filters',
'request_id': request_id})
# run each filter in a process for robustness
log_adapter.info("got request: %s" % str(filters))
avail_f, missing_f = utils.partition(filters,
lambda f: f in self._filters)
# handle missing filters
for f in missing_f:
log_adapter.warning("Filter requested but was not found: %s" % f)
result.pluginError(f, "plugin not found: '%s'" % f)
# Prepare a generator "list" of runners
filterRunners = [
PythonMethodRunner(
self._pluginDir,
self._class_to_module_map[f],
f,
utils.FILTER,
(hostIDs, vmID, properties_map),
request_id)
for f in avail_f
]
for runner in filterRunners:
runner.start()
log_adapter.debug("Waiting for filters to finish")
# TODO add timeout config
if utils.waitOnGroup(filterRunners):
log_adapter.warning("Waiting on filters timed out")
log_adapter.debug("Aggregating results")
filters_results = self.aggregate_filter_results(filterRunners,
request_id)
if filters_results is None:
log_adapter.info('All filters failed, return the full list')
result.error("all filters failed")
filters_results = hostIDs
result.add(filters_results)
log_adapter.info('returning: %s' % str(filters_results))
return result
示例4: run_cost_functions
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
def run_cost_functions(self,
cost_functions,
hostIDs,
vmID,
properties_map):
result = Result()
request_id = str(uuid.uuid1())
log_adapter = \
utils.RequestAdapter(self._logger,
{'method': 'run_cost_functions',
'request_id': request_id})
# run each filter in a process for robustness
log_adapter.info("got request: %s" % str(cost_functions))
# Get the list of known and unknown score functions
available_cost_f, missing_cost_f = \
utils.partition(cost_functions, lambda (n, w): n in self._scores)
# Report the unknown functions
for name, weight in missing_cost_f:
log_adapter.warning("requested but was not found: %s" % name)
result.pluginError(name, "plugin not found: '%s'" % name)
# Prepare a generator "list" with runners and weights
scoreRunners = [
(PythonMethodRunner(
self._pluginDir,
self._class_to_module_map[name],
name,
utils.SCORE,
(hostIDs, vmID, properties_map),
request_id), weight)
for name, weight in available_cost_f
]
for runner, _weight in scoreRunners:
runner.start()
log_adapter.debug("Waiting for scoring to finish")
if utils.waitOnGroup([runner for runner, _weight in scoreRunners]):
log_adapter.warning("Waiting on score functions timed out")
result.error("Waiting on score functions timed out")
log_adapter.debug("Aggregating results")
results = self.aggregate_score_results(scoreRunners, request_id)
result.add(results)
log_adapter.info('returning: %s' % str(results))
return result
示例5: ArchiveBuilder
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
class ArchiveBuilder(object):
"""
root archive image builder
"""
def __init__(self, xml_state, target_dir, root_dir):
self.root_dir = root_dir
self.target_dir = target_dir
self.xml_state = xml_state
self.requested_archive_type = xml_state.get_build_type_name()
self.result = Result()
self.filename = self.__target_file_for('tar.xz')
self.checksum = self.__target_file_for('md5')
def create(self):
supported_archives = Defaults.get_archive_image_types()
if self.requested_archive_type not in supported_archives:
raise KiwiArchiveSetupError(
'Unknown archive type: %s' % self.requested_archive_type
)
if self.requested_archive_type == 'tbz':
log.info('Creating XZ compressed tar archive')
archive = ArchiveTar(
self.__target_file_for('tar')
)
archive.create_xz_compressed(self.root_dir)
checksum = Checksum(self.filename)
log.info('--> Creating archive checksum')
checksum.md5(self.checksum)
self.result.add(
'root_archive', self.filename
)
self.result.add(
'root_archive_checksum', self.checksum
)
return self.result
def __target_file_for(self, suffix):
return ''.join(
[
self.target_dir, '/',
self.xml_state.xml_data.get_name(),
'.' + platform.machine(),
'-' + self.xml_state.get_image_version(),
'.', suffix
]
)
示例6: ContainerBuilder
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
class ContainerBuilder(object):
"""
container image builder
"""
def __init__(self, xml_state, target_dir, root_dir):
self.root_dir = root_dir
self.requested_container_name = xml_state.build_type.get_container()
self.requested_container_type = xml_state.get_build_type_name()
self.filename = ''.join(
[
target_dir, '/',
xml_state.xml_data.get_name(),
'.' + platform.machine(),
'-' + xml_state.get_image_version(),
'.', self.requested_container_type, '.tar.xz'
]
)
self.result = Result()
def create(self):
setup_options = {}
if self.requested_container_name:
setup_options['container_name'] = self.requested_container_name
container_setup = ContainerSetup(
self.requested_container_type, self.root_dir, setup_options
)
log.info('Setting up %s container', self.requested_container_type)
log.info(
'--> Container name: %s', container_setup.get_container_name()
)
container_setup.setup()
log.info(
'--> Creating container archive'
)
container_image = ContainerImage(
self.requested_container_type, self.root_dir
)
container_image.create(
self.filename
)
self.result.add(
'container', self.filename
)
return self.result
示例7: run_load_balancing
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
def run_load_balancing(self, balance, hostIDs, properties_map):
result = Result()
request_id = str(uuid.uuid1())
log_adapter = \
utils.RequestAdapter(self._logger,
{'method': 'run_load_balancing',
'request_id': request_id})
log_adapter.info("got request: %s" % balance)
if balance not in self._balancers:
warn_message = "Load balance requested but was not found: %s"\
% balance
log_adapter.warning(warn_message)
result.pluginError(balance, warn_message)
return result
runner = PythonMethodRunner(self._pluginDir,
self._class_to_module_map[balance],
balance,
utils.BALANCE,
(hostIDs, properties_map),
request_id)
runner.start()
log_adapter.debug('Waiting for balance to finish')
runner.join(30)
log_adapter.info('returning: %s' % str(runner.getResults()))
if runner.getResults() is None:
result.add(['', []])
else:
result.add(runner.getResults())
return result
示例8: test_list_is_sorted
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
def test_list_is_sorted(self):
r = Result()
r.add("baz", None)
r.add("bar", None)
r.add("foo", None)
r.add("foo", None)
r.add("baz", None)
r.add("baz", None)
self.assertEqual(r.get_list(), [("baz", 3), ("foo", 2), ("bar", 1)])
示例9: PxeBuilder
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
class PxeBuilder(object):
"""
Filesystem based PXE image builder. This results in creating
a boot image(initrd) plus its appropriate kernel files and the
root filesystem image with a checksum. The result can be used
within the kiwi PXE boot infrastructure
"""
def __init__(self, xml_state, target_dir, root_dir):
self.target_dir = target_dir
self.compressed = xml_state.build_type.get_compressed()
self.image_name = xml_state.xml_data.get_name()
self.machine = xml_state.get_build_type_machine_section()
self.pxedeploy = xml_state.get_build_type_pxedeploy_section()
self.filesystem = FileSystemBuilder(
xml_state, target_dir, root_dir
)
self.system_setup = SystemSetup(
xml_state=xml_state, description_dir=None, root_dir=root_dir
)
self.boot_image_task = BootImageTask(
'kiwi', xml_state, target_dir
)
self.kernel_filename = None
self.hypervisor_filename = None
self.result = Result()
def create(self):
log.info('Creating PXE root filesystem image')
self.filesystem.create()
self.image = self.filesystem.filename
if self.compressed:
log.info('xz compressing root filesystem image')
compress = Compress(self.image)
compress.xz()
self.image = compress.compressed_filename
log.info('Creating PXE root filesystem MD5 checksum')
self.filesystem_checksum = self.filesystem.filename + '.md5'
checksum = Checksum(self.image)
checksum.md5(self.filesystem_checksum)
# prepare boot(initrd) root system
log.info('Creating PXE boot image')
self.boot_image_task.prepare()
# export modprobe configuration to boot image
self.system_setup.export_modprobe_setup(
self.boot_image_task.boot_root_directory
)
# extract kernel from boot(initrd) root system
kernel = Kernel(self.boot_image_task.boot_root_directory)
kernel_data = kernel.get_kernel()
if kernel_data:
self.kernel_filename = ''.join(
[self.image_name, '-', kernel_data.version, '.kernel']
)
kernel.copy_kernel(
self.target_dir, self.kernel_filename
)
else:
raise KiwiPxeBootImageError(
'No kernel in boot image tree %s found' %
self.boot_image_task.boot_root_directory
)
# extract hypervisor from boot(initrd) root system
if self.machine and self.machine.get_domain() == 'dom0':
kernel_data = kernel.get_xen_hypervisor()
if kernel_data:
self.hypervisor_filename = ''.join(
[self.image_name, '-', kernel_data.name]
)
kernel.copy_xen_hypervisor(
self.target_dir, self.hypervisor_filename
)
self.result.add(
'xen_hypervisor', self.hypervisor_filename
)
else:
raise KiwiPxeBootImageError(
'No hypervisor in boot image tree %s found' %
self.boot_image_task.boot_root_directory
)
# create initrd for pxe boot
self.boot_image_task.create_initrd()
self.result.add(
'kernel', self.kernel_filename
)
self.result.add(
'initrd', self.boot_image_task.initrd_filename
)
self.result.add(
'filesystem_image', self.image
)
self.result.add(
'filesystem_md5', self.filesystem_checksum
)
#.........這裏部分代碼省略.........
示例10: test_can_add_word
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
def test_can_add_word(self):
r = Result()
r.add("foo", None)
self.assertEqual(r.get_list(), [("foo", 1)])
self.assertEqual(r.count, 1)
示例11: test_can_add_duplicate_words
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
def test_can_add_duplicate_words(self):
r = Result()
r.add("foo", None)
r.add("foo", None)
self.assertEqual(r.get_list(), [("foo", 2)])
self.assertEqual(r.count, 2)
示例12: LiveImageBuilder
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
#.........這裏部分代碼省略.........
bootloader_config_grub.setup_live_boot_images(
mbrid=self.mbrid,
lookup_path=self.boot_image_task.boot_root_directory
)
bootloader_config_grub.setup_live_image_config(
mbrid=self.mbrid
)
bootloader_config_grub.write()
# create initrd for live image
log.info('Creating live ISO boot image')
self.__create_live_iso_kernel_and_initrd()
# calculate size and decide if we need UDF
if rootsize.accumulate_mbyte_file_sizes() > 4096:
log.info('ISO exceeds 4G size, using UDF filesystem')
custom_iso_args.append('-allow-limited-size')
custom_iso_args.append('-udf')
# create iso filesystem from media_dir
log.info('Creating live ISO image')
iso_image = FileSystemIsoFs(
device_provider=None,
root_dir=self.media_dir,
custom_args=custom_iso_args
)
iso_header_offset = iso_image.create_on_file(self.isoname)
# make it hybrid
if self.hybrid:
Iso.create_hybrid(
iso_header_offset, self.mbrid, self.isoname
)
self.result.add(
'live_image', self.isoname
)
return self.result
def __create_live_iso_kernel_and_initrd(self):
boot_path = self.media_dir + '/boot/x86_64/loader'
Path.create(boot_path)
kernel = Kernel(self.boot_image_task.boot_root_directory)
if kernel.get_kernel():
kernel.copy_kernel(boot_path, '/linux')
else:
raise KiwiLiveBootImageError(
'No kernel in boot image tree %s found' %
self.boot_image_task.boot_root_directory
)
if self.machine and self.machine.get_domain() == 'dom0':
if kernel.get_xen_hypervisor():
kernel.copy_xen_hypervisor(boot_path, '/xen.gz')
else:
raise KiwiLiveBootImageError(
'No hypervisor in boot image tree %s found' %
self.boot_image_task.boot_root_directory
)
self.boot_image_task.create_initrd(self.mbrid)
Command.run(
[
'mv', self.boot_image_task.initrd_filename,
boot_path + '/initrd'
]
)
def __create_live_iso_client_config(self, iso_type):
"""
Setup IMAGE and UNIONFS_CONFIG variables as they are used in
the kiwi isoboot code. Variable contents:
+ IMAGE=target_device;live_iso_name_definition
+ UNIONFS_CONFIG=rw_device,ro_device,union_type
If no real block device is used or can be predefined the
word 'loop' is set as a placeholder or indicator to use a loop
device. For more details please refer to the kiwi shell boot
code
"""
iso_client_config_file = self.media_dir + '/config.isoclient'
iso_client_params = Defaults.get_live_iso_client_parameters()
(system_device, union_device, union_type) = iso_client_params[iso_type]
with open(iso_client_config_file, 'w') as config:
config.write(
'IMAGE="%s;%s.%s;%s"\n' % (
system_device,
self.xml_state.xml_data.get_name(), self.arch,
self.xml_state.get_image_version()
)
)
config.write(
'UNIONFS_CONFIG="%s,loop,%s"\n' %
(union_device, union_type)
)
def __del__(self):
if self.media_dir:
log.info('Cleaning up %s instance', type(self).__name__)
Path.wipe(self.media_dir)
示例13: DiskBuilder
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
#.........這裏部分代碼省略.........
# create initrd cpio archive
self.boot_image_task.create_initrd(self.mbrid)
# create second stage metadata to boot
self.__copy_first_boot_files_to_system_image()
self.__write_bootloader_config_to_system_image(device_map)
self.mbrid.write_to_disk(
self.disk.storage_provider
)
# syncing system data to disk image
log.info('Syncing system to image')
if self.system_efi:
log.info('--> Syncing EFI boot data to EFI partition')
self.system_efi.sync_data()
if self.system_boot:
log.info('--> Syncing boot data at extra partition')
self.system_boot.sync_data(
self.__get_exclude_list_for_boot_data_sync()
)
log.info('--> Syncing root filesystem data')
self.system.sync_data(
self.__get_exclude_list_for_root_data_sync(device_map)
)
# install boot loader
self.__install_bootloader(device_map)
self.result.add(
'disk_image', self.diskname
)
# create install media if requested
if self.install_media:
if self.image_format:
log.warning('Install image requested, ignoring disk format')
if self.install_iso or self.install_stick:
log.info('Creating hybrid ISO installation image')
self.install_image.create_install_iso()
self.result.add(
'installation_image', self.install_image.isoname
)
if self.install_pxe:
log.info('Creating PXE installation archive')
self.install_image.create_install_pxe_archive()
self.result.add(
'installation_pxe_archive', self.install_image.pxename
)
# create disk image format if requested
elif self.image_format:
log.info('Creating %s Disk Format', self.image_format)
disk_format = DiskFormat(
self.image_format, self.xml_state,
self.root_dir, self.target_dir
)
disk_format.create_image_format()
self.result.add(
'disk_format_image',
self.target_dir + '/' + disk_format.get_target_name_for_format(
示例14: FileSystemBuilder
# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import add [as 別名]
class FileSystemBuilder(object):
"""
Filesystem image builder
"""
def __init__(self, xml_state, target_dir, root_dir):
self.custom_args = None
self.label = None
self.root_dir = root_dir
self.requested_image_type = xml_state.get_build_type_name()
if self.requested_image_type == 'pxe':
self.requested_filesystem = xml_state.build_type.get_filesystem()
else:
self.requested_filesystem = self.requested_image_type
if not self.requested_filesystem:
raise KiwiFileSystemSetupError(
'No filesystem configured in %s type' %
self.requested_image_type
)
self.filename = ''.join(
[
target_dir, '/',
xml_state.xml_data.get_name(),
'.' + platform.machine(),
'-' + xml_state.get_image_version(),
'.', self.requested_filesystem
]
)
self.blocksize = xml_state.build_type.get_target_blocksize()
self.filesystem_setup = FileSystemSetup(xml_state, root_dir)
self.filesystems_no_device_node = [
'squashfs'
]
self.result = Result()
def create(self):
log.info(
'Creating %s filesystem', self.requested_filesystem
)
supported_filesystems = Defaults.get_filesystem_image_types()
if self.requested_filesystem not in supported_filesystems:
raise KiwiFileSystemSetupError(
'Unknown filesystem: %s' % self.requested_filesystem
)
if self.requested_filesystem not in self.filesystems_no_device_node:
self.__operate_on_loop()
else:
self.__operate_on_file()
self.result.add(
'filesystem_image', self.filename
)
return self.result
def __operate_on_loop(self):
filesystem = None
loop_provider = LoopDevice(
self.filename,
self.filesystem_setup.get_size_mbytes(),
self.blocksize
)
loop_provider.create()
filesystem = FileSystem(
self.requested_filesystem, loop_provider,
self.root_dir, self.custom_args
)
filesystem.create_on_device(self.label)
log.info(
'--> Syncing data to filesystem on %s', loop_provider.get_device()
)
exclude_list = [
'image', '.profile', '.kconfig', 'var/cache/kiwi'
]
filesystem.sync_data(exclude_list)
def __operate_on_file(self):
default_provider = DeviceProvider()
filesystem = FileSystem(
self.requested_filesystem, default_provider,
self.root_dir, self.custom_args
)
filesystem.create_on_file(
self.filename, self.label
)