diff options
author | Ben Hutchings <benh@debian.org> | 2016-02-12 21:59:41 +0000 |
---|---|---|
committer | Ben Hutchings <benh@debian.org> | 2016-02-12 21:59:41 +0000 |
commit | 73eb64b4ec1cc09ac86cb6820df04197830d1129 (patch) | |
tree | 7cd6f7e4bdf87ced4a7147d080c846183e0baa20 /scripts | |
parent | 62db74b621cfa2c9bf00938371fc1dcccb7fd492 (diff) |
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
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/filter-active.py | 33 |
1 files changed, 30 insertions, 3 deletions
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") |