summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@intel.com>2018-01-17 17:11:33 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-01-18 12:50:37 +0000
commit1c88db7a1c071fa00bcbba14c89e1c54b21c1948 (patch)
tree1c5e8be698d5b643df59e22a101fdc965beb99e3 /meta/lib
parentc1058ac4f2441e017098a1a4f27bbecb407bb3a8 (diff)
downloadpoky-1c88db7a1c071fa00bcbba14c89e1c54b21c1948.tar.gz
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>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/buildhistory_analysis.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/meta/lib/oe/buildhistory_analysis.py b/meta/lib/oe/buildhistory_analysis.py
index 3e86a46a3f..c05841b804 100644
--- a/meta/lib/oe/buildhistory_analysis.py
+++ b/meta/lib/oe/buildhistory_analysis.py
@@ -40,6 +40,26 @@ related_fields['PKGSIZE'] = ['FILELIST']
40related_fields['files-in-image.txt'] = ['installed-package-names.txt', 'USER_CLASSES', 'IMAGE_CLASSES', 'ROOTFS_POSTPROCESS_COMMAND', 'IMAGE_POSTPROCESS_COMMAND'] 40related_fields['files-in-image.txt'] = ['installed-package-names.txt', 'USER_CLASSES', 'IMAGE_CLASSES', 'ROOTFS_POSTPROCESS_COMMAND', 'IMAGE_POSTPROCESS_COMMAND']
41related_fields['installed-package-names.txt'] = ['IMAGE_FEATURES', 'IMAGE_LINGUAS', 'IMAGE_INSTALL', 'BAD_RECOMMENDATIONS', 'NO_RECOMMENDATIONS', 'PACKAGE_EXCLUDE'] 41related_fields['installed-package-names.txt'] = ['IMAGE_FEATURES', 'IMAGE_LINGUAS', 'IMAGE_INSTALL', 'BAD_RECOMMENDATIONS', 'NO_RECOMMENDATIONS', 'PACKAGE_EXCLUDE']
42 42
43colours = {
44 'colour_default': '',
45 'colour_add': '',
46 'colour_remove': '',
47}
48
49def init_colours(use_colours):
50 global colours
51 if use_colours:
52 colours = {
53 'colour_default': '\033[0m',
54 'colour_add': '\033[1;32m',
55 'colour_remove': '\033[1;31m',
56 }
57 else:
58 colours = {
59 'colour_default': '',
60 'colour_add': '',
61 'colour_remove': '',
62 }
43 63
44class ChangeRecord: 64class ChangeRecord:
45 def __init__(self, path, fieldname, oldvalue, newvalue, monitored): 65 def __init__(self, path, fieldname, oldvalue, newvalue, monitored):
@@ -110,9 +130,9 @@ class ChangeRecord:
110 lines.append('removed all items "%s"' % ' '.join(removed)) 130 lines.append('removed all items "%s"' % ' '.join(removed))
111 else: 131 else:
112 if removed: 132 if removed:
113 lines.append('removed "%s"' % ' '.join(removed)) 133 lines.append('removed "{colour_remove}{value}{colour_default}"'.format(value=' '.join(removed), **colours))
114 if added: 134 if added:
115 lines.append('added "%s"' % ' '.join(added)) 135 lines.append('added "{colour_add}{value}{colour_default}"'.format(value=' '.join(added), **colours))
116 else: 136 else:
117 lines.append('changed order') 137 lines.append('changed order')
118 138
@@ -125,9 +145,9 @@ class ChangeRecord:
125 percentchg = ((bval - aval) / float(aval)) * 100 145 percentchg = ((bval - aval) / float(aval)) * 100
126 else: 146 else:
127 percentchg = 100 147 percentchg = 100
128 out = '%s changed from %s to %s (%s%d%%)' % (self.fieldname, self.oldvalue or "''", self.newvalue or "''", '+' if percentchg > 0 else '', percentchg) 148 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)
129 elif self.fieldname in defaultval_map: 149 elif self.fieldname in defaultval_map:
130 out = '%s changed from %s to %s' % (self.fieldname, self.oldvalue, self.newvalue) 150 out = '{} changed from {colour_remove}{}{colour_default} to {colour_add}{}{colour_default}'.format(self.fieldname, self.oldvalue, self.newvalue, **colours)
131 if self.fieldname == 'PKG' and '[default]' in self.newvalue: 151 if self.fieldname == 'PKG' and '[default]' in self.newvalue:
132 out += ' - may indicate debian renaming failure' 152 out += ' - may indicate debian renaming failure'
133 elif self.fieldname in ['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm']: 153 elif self.fieldname in ['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm']:
@@ -163,7 +183,7 @@ class ChangeRecord:
163 else: 183 else:
164 out = '' 184 out = ''
165 else: 185 else:
166 out = '%s changed from "%s" to "%s"' % (self.fieldname, self.oldvalue, self.newvalue) 186 out = '{} changed from "{colour_remove}{}{colour_default}" to "{colour_add}{}{colour_default}"'.format(self.fieldname, self.oldvalue, self.newvalue, **colours)
167 187
168 if self.related: 188 if self.related:
169 for chg in self.related: 189 for chg in self.related: