Example #1
0
    def wrapper(self, result, *args, **kwargs):
        self.lock(lock=False)
        if result_nok:
            result = htmlColor(handleerror(result), COLOR_ERROR)
        else:
            result = htmlColor(parseresult(result), COLOR_SUCCESS)

        timestamp = htmlColor("[%s]" % unicode(datetime.now()), TIMESTAMP_COLOR)
        result = "%s %s" % (timestamp, result)
        return function(self, result, *args, **kwargs)
Example #2
0
 def _display_err(self, timestamp, err):
     name = self._last_fired_component
     html = tr("%s triggered the following error") % name
     html = htmlColor(html, COLOR_ERROR)
     err = Html(err) # content is an error
     html = tr("%s: %s") % (unicode(html), unicode(err))
     if not self._rollback_occurred:
         self._apply_error = Html(html, escape=False)
     self.logWithTimestamp(timestamp, html)
Example #3
0
def formatTimestamp(timestamp=None, server_time=False):
    if timestamp is None:
        timestamp = datetime.now()
    # strip microseconds
    timestamp = unicode(timestamp)
    timestamp = timestamp.split(u".", 1)[0]
    if server_time:
        html = tr("server: %s") % timestamp
    else:
        html = timestamp
    html = u"[%s]" % html
    return htmlColor(html, COLOR_TIMESTAMP) + ' '
Example #4
0
 def display_message(self, timestamp, message, color=None, prefix=None):
     if color is not None:
         html = htmlColor(message, color)
     else:
         html = Html(message)
     self.logWithTimestamp(timestamp, html)
Example #5
0
 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)
         )
Example #6
0
    def __process_logs(self, logs):
        """
        Does everything that has to be done with logs

        -Write them on the console.
        -take any relevant action

        returns True if there are other messages to process
                False if all messages have been processed
        """
        has_more = True
        if len(logs) == 0:
            if self._interval < _MAX_INTERVAL:
                self._interval *= 2
        for log in logs:
            self._interval = _BASE_INTERVAL
            self._last_read_index += 1
            timestamp, message_type, content = log
            timestamp = parseDatetime(timestamp)
            if message_type == PHASE_CHANGE:
                has_more = self._change_phase(timestamp, content)
            elif message_type in ERRORS:
                self._display_err(timestamp, content)
            elif message_type in (GLOBAL_ERROR, GLOBAL_WARNING):
                colors = {GLOBAL_ERROR:COLOR_ERROR ,GLOBAL_WARNING:COLOR_WARNING}
                format, substitutions = content
                message = tr(format) % substitutions
                self.display_message(timestamp, message, color=colors[message_type])
            elif message_type in COMPONENT_LISTS:
                self._process_component_list(timestamp, message_type, content)
            elif message_type in COMPONENT_FIRED:
                self._set_last_fired_component(content)
                message = tr("%(COMPONENT_NAME)s is being configured") % {
                    "COMPONENT_NAME": self._last_fired_component_formatted}
                splash_message = self._last_fired_component
                self._component_counter += 1
                if self._rollback_occurred:
                    components = self._rolled_back_component_list
                else:
                    components = self._applied_component_list
                if components:
                    progress = " (%s/%s)" % (self._component_counter, len(components))
                    message += progress
                    splash_message += progress
                self.logWithTimestamp(timestamp, message)
                self.splash.setText(splash_message)
            elif COMPONENT_MESSAGE == message_type:
                format, substitutions = content
                message = tr(format) % substitutions
                message = htmlColor(message, COLOR_VERBOSE)
                message = tr("%s: %s") % (
                    self._last_fired_component,
                    unicode(message))
                self.logWithTimestamp(timestamp, message)
            else:
                # unknow message type
                message = tr("%s (unknown message type: '%s')")
                message = message % (content, message_type)
                message = htmlColor(message, COLOR_INVALID)
                self.logWithTimestamp(timestamp, message)

        return has_more