From b372e85d9b41ab8ceb4695c223fdf4c35913323b Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Fri, 7 Apr 2017 09:52:11 +1200 Subject: bitbake: 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. (Bitbake rev: 04a023c8fdea1e1812fcdcaf00345aab59f9abe1) Signed-off-by: Paul Eggleton Signed-off-by: Richard Purdie --- bitbake/bin/bitbake-diffsigs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'bitbake/bin') diff --git a/bitbake/bin/bitbake-diffsigs b/bitbake/bin/bitbake-diffsigs index e9fdb48993..884be1e3c7 100755 --- a/bitbake/bin/bitbake-diffsigs +++ b/bitbake/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: -- cgit v1.2.3-54-g00ecf