def _change_phase(self, timestamp, phase): """ returns True if there are other messages to process False if all messages have been processed """ self.setPhase(phase) has_more = True hexacolor = None if phase == GLOBAL_DONE: if self._rollback_occurred: return False hexacolor = COLOR_SUCCESS message = tr("The new configuration has been successfully applied") if self._final_success_msg: message = self._final_success_msg message = htmlBold(message) has_more = False elif phase == GLOBAL_APPLY_SKIPPED: hexacolor = COLOR_SUCCESS message = tr("Application skipped") message = htmlBold(message) has_more = False elif phase == GLOBAL: hexacolor = COLOR_EMPHASIZED message = tr("Applying the new configuration") message = htmlBold(message) elif phase == APPLYING: hexacolor = COLOR_EMPHASIZED message = tr("Normal application phase started") elif phase == APPLYING_DONE: hexacolor = COLOR_EMPHASIZED message = tr("Normal application phase completed") elif phase == ROLLING_BACK: self.rollback() hexacolor = COLOR_ERROR message = tr("The application of the new configuration failed: " "restoring the previous configuration") if self._rollback_error_msg: message = self._rollback_error_msg message = htmlBold(message) elif phase == ROLLING_BACK_DONE: self._rollback_occurred = True hexacolor = COLOR_ERROR message = tr("The application of the new configuration failed: " "the previous configuration has been restored") if self._final_error_msg: message = self._final_error_msg message = htmlBold(message) else: message = Html(phase) if self.mainwindow.debug \ or phase not in (APPLYING, APPLYING_DONE): prefix = formatTimestamp(timestamp, True) html = message + BR self.mainwindow.addHTMLToInfoArea(html, hexacolor, prefix) return has_more
def printServerTime(self, time): server_time = unicode(datetime.fromtimestamp(float(time))) server_time = unicode(htmlBold(server_time)) html = tr("Server time: %s") % server_time html = Html(html, escape=False) self.addToInfoArea(html) QMessageBox.information(self, tr("Server time"), tr("Server time: %s") % server_time)
def createInformation(self): options = [] title = unicode(self) extra = [] template = self.getTemplate() if template: extra.append(template) if not self['enabled']: extra.append(tr('disabled')) if not self['mandatory']: extra.append(tr('optional')) if extra: title += ' (%s)' % u', '.join(extra) decision = htmlImage(self.getIcon(), align="middle") decision += NBSP + Html(self['decision']) options.extend(( (tr('Decision'), decision), (tr('Chain'), self['chain']), (tr('Sources'), formatObjects(self.getSources())), (tr('Destinations'), formatObjects(self.getDestinations())), (tr('Protocols'), formatObjects(self['protocols'])), )) if self['user_groups']: options.append((tr('User Groups'), formatObjects(self['user_groups']))) if self['applications']: options.append((tr('Applications'), formatObjects(self['applications']))) if self['operating_systems']: options.append((tr('Operating Systems'), formatObjects(self['operating_systems']))) if self['periodicities']: options.append((tr('Time Criteria'), formatObjects(self['periodicities']))) if self['durations']: options.append((tr('Durations'), formatObjects(self['durations']))) log = htmlBold(humanYesNo(self['log'])) if 'log_prefix' in self: log = tr('%s, prefix="%s"') % (log, htmlBold(self['log_prefix'])) options.extend(( (tr('Logging'), Html(log, escape=False)), (tr('Input'), self['input'].createHTML()), (tr('Output'), self['output'].createHTML()), )) if 'comment' in self: options.append((tr('Comment'), self['comment'])) return title, options
def createInformation(self): title = tr('Group') objects = (self.library[identifier] for identifier in self['objects']) objects = formatObjects(objects) options = [ (tr('Identifier'), htmlBold(self['id'])), (tr('Objects'), objects), (tr('References'), self.createReferencesHTML()), ] return title, options
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 createReferencesHTML(self, glue=None, icon=True): if not self['references']: return tr("(none)") references = [] get_model = self.library.window.getModel if glue: glue = Html(glue) else: glue = BR for update_domain, object_id in self['references']: model = get_model(update_domain) try: object = model[object_id] except KeyError: html = u'Broken reference: %s[%s]' % (update_domain, object_id) html = htmlBold(html) else: html = object.createHTML(icon=icon, tooltip=True) references.append(html) return glue.join(references)
def _set_last_fired_component(self, component_name): translated = self.component_label(component_name) self._last_fired_component = translated self._last_fired_component_formatted = htmlBold( htmlColor(translated, COLOR_EMPHASIZED) )
def formatObjects(objects): if not objects: return htmlBold(tr("(any)")) return BR.join(object.createHTML(tooltip=True) for object in objects)