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-10 23:00:32 +0100 |
commit | b372e85d9b41ab8ceb4695c223fdf4c35913323b (patch) | |
tree | 08605d698e8aa954071c5cff9e12c0dccf4239dd /bitbake/bin | |
parent | 5f7bf1f66d21155dfa5328aa57b4302cc64c132b (diff) | |
download | poky-b372e85d9b41ab8ceb4695c223fdf4c35913323b.tar.gz |
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 <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/bin')
-rwxr-xr-x | bitbake/bin/bitbake-diffsigs | 18 |
1 files changed, 12 insertions, 6 deletions
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 | |||
34 | 34 | ||
35 | logger = bb.msg.logger_create('bitbake-diffsigs') | 35 | logger = bb.msg.logger_create('bitbake-diffsigs') |
36 | 36 | ||
37 | def find_compare_task(bbhandler, pn, taskname, sig1=None, sig2=None): | 37 | def find_compare_task(bbhandler, pn, taskname, sig1=None, sig2=None, color=False): |
38 | """ Find the most recent signature files for the specified PN/task and compare them """ | 38 | """ Find the most recent signature files for the specified PN/task and compare them """ |
39 | 39 | ||
40 | if not hasattr(bb.siggen, 'find_siginfo'): | 40 | if not hasattr(bb.siggen, 'find_siginfo'): |
@@ -79,7 +79,7 @@ def find_compare_task(bbhandler, pn, taskname, sig1=None, sig2=None): | |||
79 | elif not hash2 in hashfiles: | 79 | elif not hash2 in hashfiles: |
80 | recout.append("Unable to find matching sigdata for %s with hash %s" % (key, hash2)) | 80 | recout.append("Unable to find matching sigdata for %s with hash %s" % (key, hash2)) |
81 | else: | 81 | else: |
82 | out2 = bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2], recursecb) | 82 | out2 = bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2], recursecb, color=color) |
83 | for change in out2: | 83 | for change in out2: |
84 | for line in change.splitlines(): | 84 | for line in change.splitlines(): |
85 | recout.append(' ' + line) | 85 | recout.append(' ' + line) |
@@ -89,7 +89,7 @@ def find_compare_task(bbhandler, pn, taskname, sig1=None, sig2=None): | |||
89 | # Recurse into signature comparison | 89 | # Recurse into signature comparison |
90 | logger.debug("Signature file (previous): %s" % latestfiles[-2]) | 90 | logger.debug("Signature file (previous): %s" % latestfiles[-2]) |
91 | logger.debug("Signature file (latest): %s" % latestfiles[-1]) | 91 | logger.debug("Signature file (latest): %s" % latestfiles[-1]) |
92 | output = bb.siggen.compare_sigfiles(latestfiles[-2], latestfiles[-1], recursecb) | 92 | output = bb.siggen.compare_sigfiles(latestfiles[-2], latestfiles[-1], recursecb, color=color) |
93 | if output: | 93 | if output: |
94 | print('\n'.join(output)) | 94 | print('\n'.join(output)) |
95 | sys.exit(0) | 95 | sys.exit(0) |
@@ -103,6 +103,10 @@ parser.add_argument('-d', '--debug', | |||
103 | help='Enable debug output', | 103 | help='Enable debug output', |
104 | action='store_true') | 104 | action='store_true') |
105 | 105 | ||
106 | parser.add_argument('--color', | ||
107 | help='Colorize output (where %(metavar)s is %(choices)s)', | ||
108 | choices=['auto', 'always', 'never'], default='auto', metavar='color') | ||
109 | |||
106 | parser.add_argument("-t", "--task", | 110 | parser.add_argument("-t", "--task", |
107 | help="find the signature data files for last two runs of the specified task and compare them", | 111 | help="find the signature data files for last two runs of the specified task and compare them", |
108 | action="store", dest="taskargs", nargs=2, metavar=('recipename', 'taskname')) | 112 | action="store", dest="taskargs", nargs=2, metavar=('recipename', 'taskname')) |
@@ -125,20 +129,22 @@ options = parser.parse_args() | |||
125 | if options.debug: | 129 | if options.debug: |
126 | logger.setLevel(logging.DEBUG) | 130 | logger.setLevel(logging.DEBUG) |
127 | 131 | ||
132 | color = (options.color == 'always' or (options.color == 'auto' and sys.stdout.isatty())) | ||
133 | |||
128 | if options.taskargs: | 134 | if options.taskargs: |
129 | with bb.tinfoil.Tinfoil() as tinfoil: | 135 | with bb.tinfoil.Tinfoil() as tinfoil: |
130 | tinfoil.prepare(config_only=True) | 136 | tinfoil.prepare(config_only=True) |
131 | if options.sigargs: | 137 | if options.sigargs: |
132 | find_compare_task(tinfoil, options.taskargs[0], options.taskargs[1], options.sigargs[0], options.sigargs[1]) | 138 | find_compare_task(tinfoil, options.taskargs[0], options.taskargs[1], options.sigargs[0], options.sigargs[1], color=color) |
133 | else: | 139 | else: |
134 | find_compare_task(tinfoil, options.taskargs[0], options.taskargs[1]) | 140 | find_compare_task(tinfoil, options.taskargs[0], options.taskargs[1], color=color) |
135 | else: | 141 | else: |
136 | if options.sigargs: | 142 | if options.sigargs: |
137 | logger.error('-s/--signature can only be used together with -t/--task') | 143 | logger.error('-s/--signature can only be used together with -t/--task') |
138 | sys.exit(1) | 144 | sys.exit(1) |
139 | try: | 145 | try: |
140 | if options.sigdatafile1 and options.sigdatafile2: | 146 | if options.sigdatafile1 and options.sigdatafile2: |
141 | output = bb.siggen.compare_sigfiles(options.sigdatafile1, options.sigdatafile2) | 147 | output = bb.siggen.compare_sigfiles(options.sigdatafile1, options.sigdatafile2, color=color) |
142 | elif options.sigdatafile1: | 148 | elif options.sigdatafile1: |
143 | output = bb.siggen.dump_sigfile(options.sigdatafile1) | 149 | output = bb.siggen.dump_sigfile(options.sigdatafile1) |
144 | except IOError as e: | 150 | except IOError as e: |