def formatWarnings(message, warnings): message = htmlParagraph(message) if warnings: html = htmlImage(WARNING_ICON32, align="middle") html += NBSP + Html(tr("Warnings:")) message += htmlParagraph(html) message += htmlList( tr(format) % tuple(arguments) for format, arguments in warnings) return unicode(message)
def _cleanupTraceback(lines, first_line): if (not lines) or (len(lines) < 3): return u'' # Remove first line del lines[0] try: clean = [] index = 0 indent = " \t" while index < len(lines): line = lines[index] if (0 < index) and not line.startswith(" "): # Skip the message at the end (only keep the backtrace) break line = line.lstrip(indent) match = FILE_REGEX.match(line) if match is None: raise SyntaxError("Unable to parse backtrace") filename = truncateFilename(match.group('filename'), 40, 5) line_number = match.group('line') try: source = lines[index + 1].lstrip(indent) except IndexError: source = None if (not source) or FILE_REGEX.match(source): # Traceback without source code: # File ".../core.py", line 365, in callService # File ".../component.py", line 31, in __call__ source = htmlItalic('<%s()>' % match.group('function')) index += 1 else: # Traceback with source code: # File ".../core.py", line 365, in callService # return self.function(*args) # File ".../component.py", line 31, in __call__ index += 2 where = htmlBold("%s:%s" % (filename, line_number)) text = Html("%s: %s" % (where, source), escape=False) clean.append(text) return htmlParagraph(first_line) + htmlList(clean) except Exception: # Ignore exceptions when cleanup the traceback pass return htmlParagraph(first_line) + htmlPre(u'\n'.join(lines))
def _formatMessages(self, title, messages, icon): html = Html() errors = [] for format, args in messages: errors.append(formatMessage(self.window, True, format, args)) if errors: text = htmlImage(icon, align="middle") + NBSP + title html += htmlParagraph(text) html += htmlList(errors) return html
def success(self, result): duration = time() - self.before self.window.unfreeze() self.window.clearErrors() seconds = u"%.1f" % duration html = htmlHeader(3, tr('Rule set')) if 'consistency_errors' in result: self.consistency_error = bool(result['consistency_errors']) else: # Old ufwi_ruleset backend self.consistency_error = (not result['applied']) if result['applied']: html += htmlParagraph(tr("Rules applied correctly in %s sec.") % seconds) else: html += htmlParagraph(tr("Unable to apply rules!")) result_html = self.formatResult(result) if result_html: html += result_html self.window.disableRepaint() try: self.window.setInfo(html, is_error=not result['applied'], show_dock=True) self.consistencyFilter(result) finally: self.window.enableRepaint()
def formatException(err, debug, traceback=None, errtype=None): if errtype is None: errtype = type(err) if isinstance(err, RpcdError): message = unicode(err) if debug or (not message): message = u"[%s] %s" % (err.type, message) else: message = exceptionAsUnicode(err, add_type=False) if debug or (not message): message = u"[%s] %s" % (errtype.__name__, message) message = htmlParagraph(message) if debug: traceback = _getTraceback(err, errtype, traceback) if traceback: message += traceback return unicode(message)
def __init__(self, rule_list, rule_id, edit_key, network, align_right): icon = network.getIcon() icon = htmlImage(icon, align="middle") identifier = network.formatID() if align_right: html = icon + NBSP + Html(identifier) else: html = Html(identifier) + NBSP + icon html = htmlParagraph(html) ClickableLabel.__init__(self, html, network, rule_list, rule_id, edit_key) policy = self.sizePolicy() policy.setHorizontalPolicy(QSizePolicy.Expanding) self.setSizePolicy(policy ) align = Qt.AlignVCenter if align_right: align |= Qt.AlignRight else: align |= Qt.AlignLeft self.setAlignment(align)