From 73eb64b4ec1cc09ac86cb6820df04197830d1129 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Fri, 12 Feb 2016 21:59:41 +0000 Subject: filter-active: Add optional colour-coding of status Add options to enable/disable colour-coding, and enable by default if writing to a terminal. git-svn-id: svn+ssh://svn.debian.org/svn/kernel-sec@4155 e094ebfe-e918-0410-adfb-c712417f3574 --- scripts/filter-active.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/filter-active.py b/scripts/filter-active.py index 4fb599f0..ca2b166b 100755 --- a/scripts/filter-active.py +++ b/scripts/filter-active.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import os, re, sys +import os, re, sys, curses from optparse import OptionParser from debian import deb822 @@ -94,6 +94,9 @@ if __name__ == '__main__': parser.add_option("-r", "--release", action="append") parser.add_option("-s", "--states", action="append") parser.add_option("-n", "--notstates", action="append") + parser.add_option("-c", "--color", "--colour", action="store_true") + parser.add_option("--no-color", "--no-colour", + action="store_false", dest="color") (options, args) = parser.parse_args() @@ -103,6 +106,24 @@ if __name__ == '__main__': if not options.states and not options.notstates: print('I: Excluding N/A, ignored and released issues') options.notstates = ['N/A', 'ignored', 'released'] + if options.color is None: + options.color = sys.stdout.isatty() + if options.color: + curses.setupterm() + status_color = {"needed": curses.tparm(curses.tigetstr("setaf"), + curses.COLOR_RED), + "ignored": curses.tparm(curses.tigetstr("setaf"), + curses.COLOR_YELLOW), + "pending": curses.tparm(curses.tigetstr("setaf"), + curses.COLOR_MAGENTA), + "released": curses.tparm(curses.tigetstr("setaf"), + curses.COLOR_GREEN), + "N/A": curses.tparm(curses.tigetstr("setaf"), + curses.COLOR_GREEN)} + color_off = curses.tparm(curses.tigetstr("op")) + else: + color_off = '' + issues = [] for d in options.dirs: issues = issues + get_issues(d) @@ -130,6 +151,12 @@ if __name__ == '__main__': for i in issues: sys.stdout.write(" %s:" % i.name) for release in options.release: - sys.stdout.write(" %-*.*s " % - (min_width, max_width, i.status(release) or "unknown")) + status = i.status(release) or "unknown" + status_short = status.split(' ')[0] + if options.color and status_color.has_key(status_short): + color_on = status_color[status_short] + else: + color_on = '' + sys.stdout.write(" %s%-*.*s%s " % + (color_on, min_width, max_width, status, color_off)) sys.stdout.write("\n") -- cgit v1.2.3