diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2017-04-07 09:52:11 +1200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-04-07 00:51:12 +0100 |
commit | 04a023c8fdea1e1812fcdcaf00345aab59f9abe1 (patch) | |
tree | febbd47e72e8f1a71a0b03cfe250f7314b490dd8 /bin | |
parent | 20db6b6553c80e18afc4f43dc2495435f7477822 (diff) | |
download | bitbake-contrib-04a023c8fdea1e1812fcdcaf00345aab59f9abe1.tar.gz |
bitbake-diffsigs: colourise output
If the output is a TTY, add colour to the output in order to make it
easier to read. At the moment this is fairly basic, just add colour to
the "titles" of each change and to the diff output.
I tried to introduce this without changing the code too much - rather
than moving everything over to the new python formatting style, I've
introduced a color_format() function which takes care of the colour
formatting, either accepting additional format arguments or
alternatively leaving the caller to use the old-style formatting (%) to
insert values.
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/bitbake-diffsigs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/bin/bitbake-diffsigs b/bin/bitbake-diffsigs index e9fdb4899..884be1e3c 100755 --- a/bin/bitbake-diffsigs +++ b/bin/bitbake-diffsigs @@ -34,7 +34,7 @@ import bb.msg logger = bb.msg.logger_create('bitbake-diffsigs') -def find_compare_task(bbhandler, pn, taskname, sig1=None, sig2=None): +def find_compare_task(bbhandler, pn, taskname, sig1=None, sig2=None, color=False): """ Find the most recent signature files for the specified PN/task and compare them """ if not hasattr(bb.siggen, 'find_siginfo'): @@ -79,7 +79,7 @@ def find_compare_task(bbhandler, pn, taskname, sig1=None, sig2=None): elif not hash2 in hashfiles: recout.append("Unable to find matching sigdata for %s with hash %s" % (key, hash2)) else: - out2 = bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2], recursecb) + out2 = bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2], recursecb, color=color) for change in out2: for line in change.splitlines(): recout.append(' ' + line) @@ -89,7 +89,7 @@ def find_compare_task(bbhandler, pn, taskname, sig1=None, sig2=None): # Recurse into signature comparison logger.debug("Signature file (previous): %s" % latestfiles[-2]) logger.debug("Signature file (latest): %s" % latestfiles[-1]) - output = bb.siggen.compare_sigfiles(latestfiles[-2], latestfiles[-1], recursecb) + output = bb.siggen.compare_sigfiles(latestfiles[-2], latestfiles[-1], recursecb, color=color) if output: print('\n'.join(output)) sys.exit(0) @@ -103,6 +103,10 @@ parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true') +parser.add_argument('--color', + help='Colorize output (where %(metavar)s is %(choices)s)', + choices=['auto', 'always', 'never'], default='auto', metavar='color') + parser.add_argument("-t", "--task", help="find the signature data files for last two runs of the specified task and compare them", action="store", dest="taskargs", nargs=2, metavar=('recipename', 'taskname')) @@ -125,20 +129,22 @@ options = parser.parse_args() if options.debug: logger.setLevel(logging.DEBUG) +color = (options.color == 'always' or (options.color == 'auto' and sys.stdout.isatty())) + if options.taskargs: with bb.tinfoil.Tinfoil() as tinfoil: tinfoil.prepare(config_only=True) if options.sigargs: - find_compare_task(tinfoil, options.taskargs[0], options.taskargs[1], options.sigargs[0], options.sigargs[1]) + find_compare_task(tinfoil, options.taskargs[0], options.taskargs[1], options.sigargs[0], options.sigargs[1], color=color) else: - find_compare_task(tinfoil, options.taskargs[0], options.taskargs[1]) + find_compare_task(tinfoil, options.taskargs[0], options.taskargs[1], color=color) else: if options.sigargs: logger.error('-s/--signature can only be used together with -t/--task') sys.exit(1) try: if options.sigdatafile1 and options.sigdatafile2: - output = bb.siggen.compare_sigfiles(options.sigdatafile1, options.sigdatafile2) + output = bb.siggen.compare_sigfiles(options.sigdatafile1, options.sigdatafile2, color=color) elif options.sigdatafile1: output = bb.siggen.dump_sigfile(options.sigdatafile1) except IOError as e: |