From patchwork Wed Jan 17 17:11:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Burton X-Patchwork-Id: 124889 Delivered-To: patch@linaro.org Received: by 10.46.62.1 with SMTP id l1csp118676lja; Wed, 17 Jan 2018 09:11:42 -0800 (PST) X-Google-Smtp-Source: ACJfBotuaLIucTEtsQ7dlg65WZmJ0vslsf8nCGy2ntDXXjoNZllxFiPxlLumJ8XtysBLq+Kkyig0 X-Received: by 10.159.196.152 with SMTP id c24mr7232668plo.450.1516209102482; Wed, 17 Jan 2018 09:11:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516209102; cv=none; d=google.com; s=arc-20160816; b=fpweIBec6vQFllDgjqZqdUzkWv9E2Ka7AoYL8kQPPLV7e7feAiXYUUfYkc8U7yn6tL hCVhdG4AWM3um+Lese1CeZAJtv4y9cfKKixPPAjrMwOVHRlo3YhMSkes4wZqdqc+FHeU e4lyQDHUXqQZXBNyvd/o7ZqnjvQ5iDr/Xr6anm7xFfS6n/DVlgddQtL1OqRZI7+Y9uTI DxwT8HNE8BFfqHrxkPi6i6vzm+GCT2DifcuKdE79bHFbWhJwi8R/6du0+7Yf02n+mfq3 cZUAZwaGdRH1bya3rCsSrhjmVUGYO3IUT78El6yLJh6fnCFvC8gUcKDJkeT0PjoFOfgL wm9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=LTuFwqfPOSe/ltMC1NoDSgxzNTALGEinQEnLCtOUGPQ=; b=siBqWEtkBn6euo1f4WLGshcSyo7rlUskF+MTAxBbUDO7KOZbQZkLiZdXG7HK0aiEMC /KC6A+ha+woQCga9gydUBmjUVg6CVr9HOOO1Br5MUbFjBiZ2cyFW908Hzt4g62n+PD3s 50yS/WWQMIIwJH0AkPL4z9yJjj7H5SsEIRw0Pm0iigQwjCtU39ZdtzcVamUpXCCCTp3K +gZlktK4vpwbs6QvcvU/zWOZr429UZ1RRVauc6vwWB63xozpgq0PaMVgZD/m35LfyWgy hnjyqvr7vHsThlk6FZxfi1hPGc7/Xf04c8eydz3YnHD+p25cD546NOIg7DOa3dz49+Jd ONxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=hftL4mPU; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org Return-Path: Received: from mail.openembedded.org (mail.openembedded.org. [140.211.169.62]) by mx.google.com with ESMTP id b188si4207724pgc.452.2018.01.17.09.11.42; Wed, 17 Jan 2018 09:11:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) client-ip=140.211.169.62; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=hftL4mPU; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org Received: from layers.openembedded.org (localhost [127.0.0.1]) by mail.openembedded.org (Postfix) with ESMTP id 3E1457878C; Wed, 17 Jan 2018 17:11:39 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by mail.openembedded.org (Postfix) with ESMTP id C8C64786B9 for ; Wed, 17 Jan 2018 17:11:37 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id v123so17277750wmd.5 for ; Wed, 17 Jan 2018 09:11:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=rwS3gMBXSDSCNwNkqFa9ZYCP+zssOoWps0H18efATNo=; b=hftL4mPU8ycqGB+/ExQX7pCCtfwmT9AZV85xLIJgo+25Q7TwvVnW1w8tH/tKh6T3gX C2TDIHAkpWNCcvfan1FpS88QfGx3PU9NcPDrhPg/1FRrCD8g1BFkAtwF0GCgl3JPOyhN dDdSLGRaMq/u49f8OpVV9mhitU7SNVCRYtKaZMzW6hiOk1TcQwSIbsCCQC0ARVTrKu8X CyOp8pIt561L/CqVTI0Kog+2k7XHILScxnXKR0oiZ0iDdVo/U4uLnTyhRNkyNGbxLGSJ aGXYtMSoeqz3oKnBxsvc3JFwSofTMi0SUL5ppwZHcuY21LmqNqLPLZoxsXS9Vl7IdE3I gD+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=rwS3gMBXSDSCNwNkqFa9ZYCP+zssOoWps0H18efATNo=; b=r0oZqsKetBEdcDUk4jdFarTeocMxp/iTePqisysk0mQh2KWphLR6JLtUPs/0Ri0SAH sKZOZaz27fgL1/lSjB0ZDIxBniH4iAIAG+/h/j7O+kvU1mabmqpPjU6POB/IuacilFdn CBmIojt0hlQWVulgTmVXFEmXX9j6MsxpYq6nSIAH+O8sPL9mfdtUfh+rEFDMQX/dpzek dJSSTofM4jJ9IwJFE3iF29VYc2tVclfCfShMQR2gp5m+shoMVeMTwCA3iaOHJr0FWS+C GcjUyEe73zuyKk4K/e2ATkcqugyrE38DAZ9ZNYVmw0s9x+CIa9ikopWW5XqieQz//QIL J1sg== X-Gm-Message-State: AKwxyteXmj3evbvjb/6z/aC+nlnxVG5CNrCkjXOQEYRP5OJ9sXPfUp0e 1f/UUT+vGXBzNKzVcGdfOXWfFvlE X-Received: by 10.28.169.76 with SMTP id s73mr2460433wme.122.1516209098352; Wed, 17 Jan 2018 09:11:38 -0800 (PST) Received: from flashheart.burtonini.com (home.burtonini.com. [81.2.106.35]) by smtp.gmail.com with ESMTPSA id n69sm4599550wrb.46.2018.01.17.09.11.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 09:11:37 -0800 (PST) From: Ross Burton To: openembedded-core@lists.openembedded.org Date: Wed, 17 Jan 2018 17:11:33 +0000 Message-Id: <20180117171133.2306-1-ross.burton@intel.com> X-Mailer: git-send-email 2.11.0 Subject: [OE-core] [PATCH] buildhistory-diff: add support for colourising the output X-BeenThere: openembedded-core@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussions about the oe-core layer List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: openembedded-core-bounces@lists.openembedded.org Errors-To: openembedded-core-bounces@lists.openembedded.org 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). Signed-off-by: Ross Burton --- meta/lib/oe/buildhistory_analysis.py | 30 +++++++++++++++++++++++++----- scripts/buildhistory-diff | 9 +++++++-- 2 files changed, 32 insertions(+), 7 deletions(-) -- 2.11.0 -- _______________________________________________ Openembedded-core mailing list Openembedded-core@lists.openembedded.org http://lists.openembedded.org/mailman/listinfo/openembedded-core diff --git a/meta/lib/oe/buildhistory_analysis.py b/meta/lib/oe/buildhistory_analysis.py index 3e86a46a3f7..c05841b804c 100644 --- a/meta/lib/oe/buildhistory_analysis.py +++ b/meta/lib/oe/buildhistory_analysis.py @@ -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['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: def __init__(self, path, fieldname, oldvalue, newvalue, monitored): @@ -110,9 +130,9 @@ class ChangeRecord: lines.append('removed all items "%s"' % ' '.join(removed)) else: if removed: - lines.append('removed "%s"' % ' '.join(removed)) + lines.append('removed "{colour_remove}{value}{colour_default}"'.format(value=' '.join(removed), **colours)) if added: - lines.append('added "%s"' % ' '.join(added)) + lines.append('added "{colour_add}{value}{colour_default}"'.format(value=' '.join(added), **colours)) else: lines.append('changed order') @@ -125,9 +145,9 @@ class ChangeRecord: percentchg = ((bval - aval) / float(aval)) * 100 else: 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: - 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: out += ' - may indicate debian renaming failure' elif self.fieldname in ['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm']: @@ -163,7 +183,7 @@ class ChangeRecord: else: out = '' 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: for chg in self.related: diff --git a/scripts/buildhistory-diff b/scripts/buildhistory-diff index e79cb7ac8d3..27974072fcb 100755 --- a/scripts/buildhistory-diff +++ b/scripts/buildhistory-diff @@ -53,6 +53,10 @@ def get_args_parser(): parser.add_argument('-e', '--exclude-path', action='append', 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', default = ['build-minus-1', 'HEAD'], nargs='*', @@ -107,10 +111,11 @@ def main(): elif len(args.revisions) == 2: fromrev, torev = args.revisions - from oe.buildhistory_analysis import process_changes - + from oe.buildhistory_analysis import init_colours, process_changes import gitdb + init_colours({"yes": True, "no": False, "auto": sys.stdout.isatty()}[args.colour]) + try: changes = process_changes(args.buildhistory_dir, fromrev, torev, args.report_all, args.report_ver, args.sigs,