示例#1
0
class CornerMark(object):
    """Displays a 5 char colored empty string
    at the bottom right corner of terminal in case an error, fatal or warning
    is found."""

    MARK = 5 * " "
    markable = {'FATAL': 'backgroundemph',
            'ERROR': 'backgroundemph',
            'WARN': 'onyellowemph',
            'WARNING': 'onyellowemph',
            'TARGET': 'oncyanemph'}

    def __init__(self, gaptime):
        self.corner_time = float(gaptime)
        self.termcolors = TermColorCodes()
        self.len_mark = len(self.MARK)
        self.timer = Timer(self.corner_time)
        self.count = 0
        self.flagged = False
        self.emphcolor = 'backgroundemph'

    def corner_mark_time(self):
        return self.corner_time

    def notify(self, message, log):
        """Displays a 5 char colored empty string in case a message comes in
        with the level specified in the class attribute markable. First time we
        get a markable level, a timer is started with the number of seconds
        specified in self.corner_time and a colored string will be displayed
        for that number of seconds. The timer will not be restarted during that
        time.

        :param message: the message object wrapping the current log trace
        :param log: the log associated with the current message
        """
        level = message.messageLevel.upper()
        isTarget = message.isATarget()
        # target has priority over markable levels
        if isTarget:
            self.flagged = True
            self.emphcolor = self.markable.get("TARGET")
        elif level in self.markable:
            self.flagged = True
            self.emphcolor = self.markable.get(level)
        if self.flagged:
            if self.count == 0:
                self.timer.startTimer()
            self.count += 1
            if self.timer.corner_mark_ellapsed() < self.corner_time:
                padding = term_num_cols() - self.len_mark
                trace = (padding * " " + getattr(self.termcolors,
                    self.emphcolor) + self.MARK + self.termcolors.reset)
                print trace
            else:
                self.timer.stopTimer()
                self.count = 0
                self.flagged = False
示例#2
0
 def test_stop_timer(self):
     timer = Timer(time_counter=TimeCounter(10))
     self.assertEqual(timer.stopTimer(), 0)