mirror of
https://git.yoctoproject.org/poky
synced 2026-06-01 13:09:50 +00:00
buildhistory-diff: add support for colourising the output
Colour value removes in red and additions in green, making it easier to scan the output for relevant changes. This adds a --colour option to specify whether colouring should be on, off, or detected. The default is detected, and depends on whether stdout is a TTY (same behaviour as git). (From OE-Core rev: 4208f1546c92f069e432d1865269ce539db8cea7) Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
c1058ac4f2
commit
1c88db7a1c
@@ -40,6 +40,26 @@ related_fields['PKGSIZE'] = ['FILELIST']
|
|||||||
related_fields['files-in-image.txt'] = ['installed-package-names.txt', 'USER_CLASSES', 'IMAGE_CLASSES', 'ROOTFS_POSTPROCESS_COMMAND', 'IMAGE_POSTPROCESS_COMMAND']
|
related_fields['files-in-image.txt'] = ['installed-package-names.txt', 'USER_CLASSES', 'IMAGE_CLASSES', 'ROOTFS_POSTPROCESS_COMMAND', 'IMAGE_POSTPROCESS_COMMAND']
|
||||||
related_fields['installed-package-names.txt'] = ['IMAGE_FEATURES', 'IMAGE_LINGUAS', 'IMAGE_INSTALL', 'BAD_RECOMMENDATIONS', 'NO_RECOMMENDATIONS', 'PACKAGE_EXCLUDE']
|
related_fields['installed-package-names.txt'] = ['IMAGE_FEATURES', 'IMAGE_LINGUAS', 'IMAGE_INSTALL', 'BAD_RECOMMENDATIONS', 'NO_RECOMMENDATIONS', 'PACKAGE_EXCLUDE']
|
||||||
|
|
||||||
|
colours = {
|
||||||
|
'colour_default': '',
|
||||||
|
'colour_add': '',
|
||||||
|
'colour_remove': '',
|
||||||
|
}
|
||||||
|
|
||||||
|
def init_colours(use_colours):
|
||||||
|
global colours
|
||||||
|
if use_colours:
|
||||||
|
colours = {
|
||||||
|
'colour_default': '\033[0m',
|
||||||
|
'colour_add': '\033[1;32m',
|
||||||
|
'colour_remove': '\033[1;31m',
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
colours = {
|
||||||
|
'colour_default': '',
|
||||||
|
'colour_add': '',
|
||||||
|
'colour_remove': '',
|
||||||
|
}
|
||||||
|
|
||||||
class ChangeRecord:
|
class ChangeRecord:
|
||||||
def __init__(self, path, fieldname, oldvalue, newvalue, monitored):
|
def __init__(self, path, fieldname, oldvalue, newvalue, monitored):
|
||||||
@@ -110,9 +130,9 @@ class ChangeRecord:
|
|||||||
lines.append('removed all items "%s"' % ' '.join(removed))
|
lines.append('removed all items "%s"' % ' '.join(removed))
|
||||||
else:
|
else:
|
||||||
if removed:
|
if removed:
|
||||||
lines.append('removed "%s"' % ' '.join(removed))
|
lines.append('removed "{colour_remove}{value}{colour_default}"'.format(value=' '.join(removed), **colours))
|
||||||
if added:
|
if added:
|
||||||
lines.append('added "%s"' % ' '.join(added))
|
lines.append('added "{colour_add}{value}{colour_default}"'.format(value=' '.join(added), **colours))
|
||||||
else:
|
else:
|
||||||
lines.append('changed order')
|
lines.append('changed order')
|
||||||
|
|
||||||
@@ -125,9 +145,9 @@ class ChangeRecord:
|
|||||||
percentchg = ((bval - aval) / float(aval)) * 100
|
percentchg = ((bval - aval) / float(aval)) * 100
|
||||||
else:
|
else:
|
||||||
percentchg = 100
|
percentchg = 100
|
||||||
out = '%s changed from %s to %s (%s%d%%)' % (self.fieldname, self.oldvalue or "''", self.newvalue or "''", '+' if percentchg > 0 else '', percentchg)
|
out = '{} changed from {colour_remove}{}{colour_default} to {colour_add}{}{colour_default} ({}{:.0f}%)'.format(self.fieldname, self.oldvalue or "''", self.newvalue or "''", '+' if percentchg > 0 else '', percentchg, **colours)
|
||||||
elif self.fieldname in defaultval_map:
|
elif self.fieldname in defaultval_map:
|
||||||
out = '%s changed from %s to %s' % (self.fieldname, self.oldvalue, self.newvalue)
|
out = '{} changed from {colour_remove}{}{colour_default} to {colour_add}{}{colour_default}'.format(self.fieldname, self.oldvalue, self.newvalue, **colours)
|
||||||
if self.fieldname == 'PKG' and '[default]' in self.newvalue:
|
if self.fieldname == 'PKG' and '[default]' in self.newvalue:
|
||||||
out += ' - may indicate debian renaming failure'
|
out += ' - may indicate debian renaming failure'
|
||||||
elif self.fieldname in ['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm']:
|
elif self.fieldname in ['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm']:
|
||||||
@@ -163,7 +183,7 @@ class ChangeRecord:
|
|||||||
else:
|
else:
|
||||||
out = ''
|
out = ''
|
||||||
else:
|
else:
|
||||||
out = '%s changed from "%s" to "%s"' % (self.fieldname, self.oldvalue, self.newvalue)
|
out = '{} changed from "{colour_remove}{}{colour_default}" to "{colour_add}{}{colour_default}"'.format(self.fieldname, self.oldvalue, self.newvalue, **colours)
|
||||||
|
|
||||||
if self.related:
|
if self.related:
|
||||||
for chg in self.related:
|
for chg in self.related:
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ def get_args_parser():
|
|||||||
parser.add_argument('-e', '--exclude-path',
|
parser.add_argument('-e', '--exclude-path',
|
||||||
action='append',
|
action='append',
|
||||||
help="Exclude path from the output")
|
help="Exclude path from the output")
|
||||||
|
parser.add_argument('-c', '--colour',
|
||||||
|
choices=('yes', 'no', 'auto'),
|
||||||
|
default="auto",
|
||||||
|
help="Whether to colourise (defaults to auto)")
|
||||||
parser.add_argument('revisions',
|
parser.add_argument('revisions',
|
||||||
default = ['build-minus-1', 'HEAD'],
|
default = ['build-minus-1', 'HEAD'],
|
||||||
nargs='*',
|
nargs='*',
|
||||||
@@ -107,10 +111,11 @@ def main():
|
|||||||
elif len(args.revisions) == 2:
|
elif len(args.revisions) == 2:
|
||||||
fromrev, torev = args.revisions
|
fromrev, torev = args.revisions
|
||||||
|
|
||||||
from oe.buildhistory_analysis import process_changes
|
from oe.buildhistory_analysis import init_colours, process_changes
|
||||||
|
|
||||||
import gitdb
|
import gitdb
|
||||||
|
|
||||||
|
init_colours({"yes": True, "no": False, "auto": sys.stdout.isatty()}[args.colour])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
changes = process_changes(args.buildhistory_dir, fromrev, torev,
|
changes = process_changes(args.buildhistory_dir, fromrev, torev,
|
||||||
args.report_all, args.report_ver, args.sigs,
|
args.report_all, args.report_ver, args.sigs,
|
||||||
|
|||||||
Reference in New Issue
Block a user