本文整理汇总了Python中safe.utilities.utilities.get_error_message函数的典型用法代码示例。如果您正苦于以下问题:Python get_error_message函数的具体用法?Python get_error_message怎么用?Python get_error_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_error_message函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_stacktrace_html
def test_stacktrace_html(self):
"""Stack traces can be caught and rendered as html
"""
# This is about general exception handling, so ok to use catch-all
# pylint: disable=W0703
try:
bbox_intersection('aoeu', 'oaeu', [])
except Exception, e:
# Display message and traceback
message = get_error_message(e)
# print message
message = message.to_text()
self.assertIn(str(e), message)
self.assertIn('line', message)
self.assertIn('file', message)
message = get_error_message(e)
message = message.to_html()
assert str(e) in message
message = message.decode('string_escape')
control_file_path = test_data_path(
'control',
'files',
'test-stacktrace-html.txt')
expected_results = open(control_file_path).read().replace('\n', '')
self.assertIn(expected_results, message)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:29,代码来源:test_utilities.py
示例2: accept
def accept(self):
"""Automatic slot executed when the ok button is pressed.
It will write out the keywords for the layer that is active.
"""
self.apply_changes()
keywords = self.get_keywords()
# If it's postprocessing layer, we need to check if age ratio is valid
if self.radPostprocessing.isChecked():
valid_age_ratio, sum_age_ratios = self.age_ratios_are_valid(
keywords)
if not valid_age_ratio:
message = self.tr(
'The sum of age ratios is %s which exceeds 1. Please '
'adjust the age ration defaults so that their cumulative '
'value is not greater than 1.' % sum_age_ratios)
if not self.test:
# noinspection PyCallByClass,PyTypeChecker,PyArgumentList
QtGui.QMessageBox.warning(
self, self.tr('InaSAFE'), message)
return
try:
self.keyword_io.write_keywords(layer=self.layer, keywords=keywords)
except InaSAFEError, e:
error_message = get_error_message(e)
message = self.tr(
'An error was encountered when saving the keywords:\n'
'%s' % error_message.to_html())
# noinspection PyCallByClass,PyTypeChecker,PyArgumentList
QtGui.QMessageBox.warning(self, self.tr('InaSAFE'), message)
开发者ID:severinmenard,项目名称:inasafe,代码行数:32,代码来源:keywords_dialog.py
示例3: save_current_keywords
def save_current_keywords(self):
"""Save keywords to the layer.
It will write out the keywords for the current layer.
This method is based on the KeywordsDialog class.
"""
current_keywords = self.get_keywords()
try:
self.keyword_io.write_keywords(
layer=self.layer, keywords=current_keywords)
except InaSAFEError as e:
error_message = get_error_message(e)
# noinspection PyCallByClass,PyTypeChecker,PyArgumentList
QMessageBox.warning(
self,
tr('InaSAFE'),
tr('An error was encountered when saving the following '
'keywords:\n {error_message}').format(
error_message=error_message.to_html()))
if self.dock is not None:
# noinspection PyUnresolvedReferences
self.dock.get_layers()
# Save default value to QSetting
if current_keywords.get('inasafe_default_values'):
for key, value in (
list(current_keywords['inasafe_default_values'].items())):
set_inasafe_default_value_qsetting(
self.setting, RECENT, key, value)
开发者ID:inasafe,项目名称:inasafe,代码行数:29,代码来源:wizard_dialog.py
示例4: save_metadata
def save_metadata(self):
"""Save metadata based on the field mapping state."""
metadata = self.field_mapping_widget.get_field_mapping()
for key, value in metadata['fields'].items():
# Delete the key if it's set to None
if key in self.metadata['inasafe_default_values']:
self.metadata['inasafe_default_values'].pop(key)
if value is None or value == []:
if key in self.metadata['inasafe_fields']:
self.metadata['inasafe_fields'].pop(key)
else:
self.metadata['inasafe_fields'][key] = value
for key, value in metadata['values'].items():
# Delete the key if it's set to None
if key in self.metadata['inasafe_fields']:
self.metadata['inasafe_fields'].pop(key)
if value is None:
if key in self.metadata['inasafe_default_values']:
self.metadata['inasafe_default_values'].pop(key)
else:
self.metadata['inasafe_default_values'][key] = value
# Save metadata
try:
self.keyword_io.write_keywords(
layer=self.layer, keywords=self.metadata)
except InaSAFEError, e:
error_message = get_error_message(e)
# noinspection PyCallByClass,PyTypeChecker,PyArgumentList
QMessageBox.warning(
self, self.tr('InaSAFE'),
((self.tr(
'An error was encountered when saving the following '
'keywords:\n %s') % error_message.to_html())))
开发者ID:akbargumbira,项目名称:inasafe,代码行数:35,代码来源:field_mapping_dialog.py
示例5: fake_error
def fake_error(self):
"""Make a fake error (helper for other tests)
:returns: Contents of the message viewer as string and with newlines
stripped off.
:rtype : str
"""
e = Exception()
context = 'Something went wrong'
message = get_error_message(e, context=context)
self.message_viewer.error_message_event(None, message)
text = self.message_viewer.page_to_text().replace('\n', '')
return text
开发者ID:codeforresilience,项目名称:inasafe,代码行数:12,代码来源:test_message_viewer.py
示例6: test_issue157
def test_issue157(self):
"""Verify that we get the error class name back - issue #157
.. seealso:: https://github.com/AIFDR/inasafe/issues/121
"""
try:
bbox_intersection('aoeu', 'oaeu', [])
except BoundingBoxError, e:
message = get_error_message(e)
myString = 'BoundingBoxError'
assert myString in message.to_text(), message
myString = 'Western boundary'
assert myString in message.to_text(), message
开发者ID:jobel-openscience,项目名称:inasafe,代码行数:12,代码来源:test_styling.py
示例7: analysis_error
def analysis_error(self, exception, message):
"""A helper to spawn an error and halt processing.
An exception will be logged, busy status removed and a message
displayed.
.. note:: Copied from the dock
:param message: an ErrorMessage to display
:type message: ErrorMessage, Message
:param exception: An exception that was raised
:type exception: Exception
"""
self.hide_busy()
LOGGER.exception(message)
message = get_error_message(exception, context=message)
self.show_error_message(message)
self.analysisDone.emit(False)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:19,代码来源:analysis_handler.py
示例8: analysis_error
def analysis_error(sender, exception, message):
"""A helper to spawn an error and halt processing.
An exception will be logged, busy status removed and a message
displayed.
.. versionadded:: 3.3
:param sender: The sender.
:type sender: object
:param message: an ErrorMessage to display
:type message: ErrorMessage, Message
:param exception: An exception that was raised
:type exception: Exception
"""
LOGGER.exception(message)
message = get_error_message(exception, context=message)
send_error_message(sender, message)
开发者ID:timlinux,项目名称:inasafe,代码行数:20,代码来源:signals.py
示例9: process_components
def process_components(self):
"""Process context for each component and a given template.
:returns: Tuple of error code and message
:type: tuple
.. versionadded:: 4.0
"""
message = m.Message()
warning_heading = m.Heading(
tr('Report Generation issue'), **WARNING_STYLE)
message.add(warning_heading)
failed_extract_context = m.Heading(tr(
'Failed to extract context'), **WARNING_STYLE)
failed_render_context = m.Heading(tr(
'Failed to render context'), **WARNING_STYLE)
failed_find_extractor = m.Heading(tr(
'Failed to load extractor method'), **WARNING_STYLE)
failed_find_renderer = m.Heading(tr(
'Failed to load renderer method'), **WARNING_STYLE)
generation_error_code = self.REPORT_GENERATION_SUCCESS
for component in self.metadata.components:
# load extractors
try:
if not component.context:
if callable(component.extractor):
_extractor_method = component.extractor
else:
_package_name = (
'%(report-key)s.extractors.%(component-key)s')
_package_name %= {
'report-key': self.metadata.key,
'component-key': component.key
}
# replace dash with underscores
_package_name = _package_name.replace('-', '_')
_extractor_path = os.path.join(
self.metadata.template_folder,
component.extractor
)
_module = imp.load_source(
_package_name, _extractor_path)
_extractor_method = getattr(_module, 'extractor')
else:
LOGGER.info('Predefined context. Extractor not needed.')
except Exception as e: # pylint: disable=broad-except
generation_error_code = self.REPORT_GENERATION_FAILED
LOGGER.info(e)
if self.impact_function.debug_mode:
raise
else:
message.add(failed_find_extractor)
message.add(component.info)
message.add(get_error_message(e))
continue
# method signature:
# - this ImpactReport
# - this component
try:
if not component.context:
context = _extractor_method(self, component)
component.context = context
else:
LOGGER.info('Using predefined context.')
except Exception as e: # pylint: disable=broad-except
generation_error_code = self.REPORT_GENERATION_FAILED
LOGGER.info(e)
if self.impact_function.debug_mode:
raise
else:
message.add(failed_extract_context)
message.add(get_error_message(e))
continue
try:
# load processor
if callable(component.processor):
_renderer = component.processor
else:
_package_name = '%(report-key)s.renderer.%(component-key)s'
_package_name %= {
'report-key': self.metadata.key,
'component-key': component.key
}
# replace dash with underscores
_package_name = _package_name.replace('-', '_')
_renderer_path = os.path.join(
self.metadata.template_folder,
component.processor
)
_module = imp.load_source(_package_name, _renderer_path)
_renderer = getattr(_module, 'renderer')
except Exception as e: # pylint: disable=broad-except
generation_error_code = self.REPORT_GENERATION_FAILED
LOGGER.info(e)
if self.impact_function.debug_mode:
raise
#.........这里部分代码省略.........
开发者ID:timlinux,项目名称:inasafe,代码行数:101,代码来源:impact_report.py
示例10: print_map_to_pdf
def print_map_to_pdf(self, impact_report):
"""Print map to PDF given MapReport instance.
:param impact_report: Impact Report instance that is ready to print
:type impact_report: ImpactReport
"""
impact_report.setup_composition()
# Get Filename
map_title = impact_report.map_title
if map_title is not None:
default_file_name = map_title + '.pdf'
default_file_name = default_file_name.replace(' ', '_')
else:
self.show_error_message(
self.tr('Keyword "map_title" not found.'))
return
# Get output path
# noinspection PyCallByClass,PyTypeChecker
output_path = QtGui.QFileDialog.getSaveFileName(
self.parent,
self.tr('Write to PDF'),
os.path.join(temp_dir(), default_file_name),
self.tr('Pdf File (*.pdf)'))
output_path = str(output_path)
if output_path is None or output_path == '':
self.show_dynamic_message(
self,
m.Message(
m.Heading(self.tr('Map Creator'), **WARNING_STYLE),
m.Text(self.tr('Printing cancelled!'))))
return
try:
map_pdf_path, table_pdf_path = impact_report.print_to_pdf(
output_path)
# Make sure the file paths can wrap nicely:
wrapped_map_path = map_pdf_path.replace(os.sep, '<wbr>' + os.sep)
wrapped_table_path = table_pdf_path.replace(os.sep,
'<wbr>' + os.sep)
status = m.Message(
m.Heading(self.tr('Map Creator'), **INFO_STYLE),
m.Paragraph(self.tr(
'Your PDF was created....opening using the default PDF '
'viewer on your system. The generated pdfs were saved '
'as:')),
m.Paragraph(wrapped_map_path),
m.Paragraph(self.tr('and')),
m.Paragraph(wrapped_table_path))
# noinspection PyCallByClass,PyTypeChecker,PyTypeChecker
QtGui.QDesktopServices.openUrl(
QtCore.QUrl.fromLocalFile(table_pdf_path))
# noinspection PyCallByClass,PyTypeChecker,PyTypeChecker
QtGui.QDesktopServices.openUrl(
QtCore.QUrl.fromLocalFile(map_pdf_path))
self.show_dynamic_message(self, status)
except TemplateLoadingError, e:
self.show_error_message(get_error_message(e))
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:63,代码来源:analysis_handler.py
示例11: open_map_in_composer
m.Paragraph(wrapped_map_path),
m.Paragraph(self.tr('and')),
m.Paragraph(wrapped_table_path))
# noinspection PyCallByClass,PyTypeChecker,PyTypeChecker
QtGui.QDesktopServices.openUrl(
QtCore.QUrl.fromLocalFile(table_pdf_path))
# noinspection PyCallByClass,PyTypeChecker,PyTypeChecker
QtGui.QDesktopServices.openUrl(
QtCore.QUrl.fromLocalFile(map_pdf_path))
self.show_dynamic_message(self, status)
except TemplateLoadingError, e:
self.show_error_message(get_error_message(e))
except Exception, e: # pylint: disable=broad-except
self.show_error_message(get_error_message(e))
def open_map_in_composer(self, impact_report):
"""Open map in composer given MapReport instance.
..note:: (AG) See https://github.com/AIFDR/inasafe/issues/911. We
need to set the composition to the composer before loading the
template.
:param impact_report: Impact Report to be opened in composer.
:type impact_report: ImpactReport
"""
impact_report.setup_composition()
self.composer = self.iface.createNewComposer()
self.composer.setComposition(impact_report.composition)
impact_report.load_template()
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:31,代码来源:analysis_handler.py
示例12: send_error_message
m.Paragraph(self.tr('and')),
m.Paragraph(wrapped_table_path))
# noinspection PyCallByClass,PyTypeChecker,PyArgumentList
QtGui.QDesktopServices.openUrl(
QtCore.QUrl.fromLocalFile(table_pdf_path))
# noinspection PyCallByClass,PyTypeChecker,PyArgumentList
QtGui.QDesktopServices.openUrl(
QtCore.QUrl.fromLocalFile(map_pdf_path))
# noinspection PyTypeChecker
self.show_dynamic_message(self, status)
except TemplateLoadingError, e:
send_error_message(self, get_error_message(e))
except Exception, e: # pylint: disable=broad-except
send_error_message(self, get_error_message(e))
def open_map_in_composer(self, impact_report):
"""Open map in composer given MapReport instance.
..note:: (AG) See https://github.com/AIFDR/inasafe/issues/911. We
need to set the composition to the composer before loading the
template.
:param impact_report: Impact Report to be opened in composer.
:type impact_report: ImpactReport
"""
impact_report.setup_composition()
self.composer = self.iface.createNewComposer()
self.composer.setComposition(impact_report.composition)
impact_report.load_template()
开发者ID:easmetz,项目名称:inasafe,代码行数:31,代码来源:analysis_handler.py
示例13: clip_by_extent
#.........这里部分代码省略.........
:param layer: The layer to clip.
:type layer: QgsRasterLayer
:param extent: The extent.
:type extent: QgsRectangle
:return: Clipped layer.
:rtype: QgsRasterLayer
.. versionadded:: 4.0
"""
parameters = dict()
# noinspection PyBroadException
try:
output_layer_name = quick_clip_steps['output_layer_name']
output_layer_name = output_layer_name % layer.keywords['layer_purpose']
output_raster = unique_filename(suffix='.tif', dir=temp_dir())
# We make one pixel size buffer on the extent to cover every pixels.
# See https://github.com/inasafe/inasafe/issues/3655
pixel_size_x = layer.rasterUnitsPerPixelX()
pixel_size_y = layer.rasterUnitsPerPixelY()
buffer_size = max(pixel_size_x, pixel_size_y)
extent = extent.buffered(buffer_size)
if is_raster_y_inverted(layer):
# The raster is Y inverted. We need to switch Y min and Y max.
bbox = [
str(extent.xMinimum()),
str(extent.xMaximum()),
str(extent.yMaximum()),
str(extent.yMinimum())
]
else:
# The raster is normal.
bbox = [
str(extent.xMinimum()),
str(extent.xMaximum()),
str(extent.yMinimum()),
str(extent.yMaximum())
]
# These values are all from the processing algorithm.
# https://github.com/qgis/QGIS/blob/master/python/plugins/processing/
# algs/gdal/ClipByExtent.py
# Please read the file to know these parameters.
parameters['INPUT'] = layer.source()
parameters['NO_DATA'] = ''
parameters['PROJWIN'] = ','.join(bbox)
parameters['DATA_TYPE'] = 5
parameters['COMPRESS'] = 4
parameters['JPEGCOMPRESSION'] = 75
parameters['ZLEVEL'] = 6
parameters['PREDICTOR'] = 1
parameters['TILED'] = False
parameters['BIGTIFF'] = 0
parameters['TFW'] = False
parameters['EXTRA'] = ''
parameters['OUTPUT'] = output_raster
initialize_processing()
feedback = create_processing_feedback()
context = create_processing_context(feedback=feedback)
result = processing.run(
"gdal:cliprasterbyextent",
parameters,
context=context)
if result is None:
raise ProcessingInstallationError
clipped = QgsRasterLayer(result['OUTPUT'], output_layer_name)
# We transfer keywords to the output.
clipped.keywords = layer.keywords.copy()
clipped.keywords['title'] = output_layer_name
check_layer(clipped)
except Exception as e:
# This step clip_raster_by_extent was nice to speedup the analysis.
# As we got an exception because the layer is invalid, we are not going
# to stop the analysis. We will return the original raster layer.
# It will take more processing time until we clip the vector layer.
# Check https://github.com/inasafe/inasafe/issues/4026 why we got some
# exceptions with this step.
LOGGER.exception(parameters)
LOGGER.exception(
'Error from QGIS clip raster by extent. Please check the QGIS '
'logs too !')
LOGGER.info(
'Even if we got an exception, we are continuing the analysis. The '
'layer was not clipped.')
LOGGER.exception(str(e))
LOGGER.exception(get_error_message(e).to_text())
clipped = layer
return clipped
开发者ID:inasafe,项目名称:inasafe,代码行数:101,代码来源:clip_bounding_box.py
注:本文中的safe.utilities.utilities.get_error_message函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论