#!/usr/bin/env python # -*- coding: utf-8 -*- # # # STATUS_KEYS # STATUS_AVAILABLE = 'AVAILABLE' STATUS_CLEAN = 'CLEAN' STATUS_RELEASED = 'RELEASED' STATUS_SUCCESS = 'SUCCESS' # STATUS_CHANGED = 'CHANGED' STATUS_EXISTS = 'EXISTS' STATUS_IN_WORK = 'IN_WORK' STATUS_OLD = 'OLD' STATUS_INCOMPLETE = 'INCOMPLETE' # STATUS_FAILED = 'FAILED' STATUS_MISSING = 'MISSING' STATUS_UNKNOWN = 'UNKNOWN' class termcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' BOLD = '\033[1m' UNDERLINE = '\033[4m' STATUS_COLORS = { STATUS_AVAILABLE: termcolors.OKGREEN, STATUS_CLEAN: termcolors.OKGREEN, STATUS_RELEASED: termcolors.OKGREEN, STATUS_SUCCESS: termcolors.OKGREEN, # STATUS_CHANGED: termcolors.WARNING, STATUS_EXISTS: termcolors.WARNING, STATUS_IN_WORK: termcolors.WARNING, STATUS_OLD: termcolors.WARNING, STATUS_INCOMPLETE: termcolors.WARNING, # STATUS_FAILED: termcolors.FAIL, STATUS_MISSING: termcolors.FAIL, STATUS_UNKNOWN: termcolors.FAIL, } def print_header(txt): print(termcolors.BOLD + termcolors.WARNING + txt + termcolors.ENDC) def print_action(txt): print(termcolors.BOLD + ' * ' + txt + termcolors.ENDC) def status_output(txt, default_color): return STATUS_COLORS.get(txt, default_color) + txt + termcolors.ENDC def print_info(txt, default_color=termcolors.ENDC): print(' ' + status_output(txt, default_color)) def coverage_output(lcov, bcov, length=None): if lcov is None or bcov is None: length = length or len(STATUS_UNKNOWN) return (length - len(STATUS_UNKNOWN)) * ' ' + status_output(STATUS_UNKNOWN, termcolors.FAIL) elif lcov > 90: rv = termcolors.OKGREEN + '%3d%% (%3d%%)' % (lcov, bcov) + termcolors.ENDC else: rv = termcolors.WARNING + '%3d%% (%3d%%)' % (lcov, bcov) + termcolors.ENDC if length is None: return rv else: return (length - 11) * ' ' + rv def print_coverage(lcov, bcov): print(' ' + coverage_output(lcov, bcov))