From 87e4675f6dc105039af181d203106879ee17a15f Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sat, 16 Jun 2012 14:24:40 +0200 Subject: Compare ebuilds ourselves rather than invoking sed and cmp This solves the issue with "sed: [..]: Broken pipe" and saves a few process forkes --- overlint/cli.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/overlint/cli.py b/overlint/cli.py index 83e2311..049e826 100644 --- a/overlint/cli.py +++ b/overlint/cli.py @@ -19,6 +19,7 @@ except ImportError: _revision_matcher = re.compile('-r([0-9]+)$') +_ignore_matcher = re.compile('(?:^# (?:\\$Header|Copyright)|KEYWORDS=)') portdir = portage.settings["PORTDIR"] @@ -91,6 +92,19 @@ def find_lagging_behind_gentoo(gentoo_versions, overlay_versions): return lagging_behind_gentoo +def _iter_important_lines(ebuild_f): + return (line_br for line_br in ebuild_f if _ignore_matcher.search(line_br) is None) + + +def ebuilds_are_equivalent(filename_a, filename_b): + fa = open(filename_a, 'r') + fb = open(filename_b, 'r') + for (la, lb) in zip(_iter_important_lines(fa), _iter_important_lines(fb)): + if la != lb: + return False + return True + + def find_ebuild_changes(category_package, overlay_path, gentoo_versions, overlay_versions): ebuild_changes = list() intersection = set(gentoo_versions) & set(overlay_versions) @@ -99,14 +113,11 @@ def find_ebuild_changes(category_package, overlay_path, gentoo_versions, overlay category, package = category_package.split('/') for version in intersection: ebuild_name = '%s-%s.ebuild' % (package, version) - command = """bash -c 'FILTER() { sed -e "/# $Header/d" -e "/# Copyright/d" -e "/KEYWORDS=/d" "$@"; }; """ \ - """cmp --quiet <(FILTER %s/%s/%s) <(FILTER %s/%s/%s) ; """ \ - """exit $?'""" \ - % (portdir, category_package, ebuild_name, overlay_path, category_package, ebuild_name) - ret = os.system(command) - if not ret: + filename_a = os.path.join(portdir, category_package, ebuild_name) + filename_b = os.path.join(overlay_path, category_package, ebuild_name) + if ebuilds_are_equivalent(filename_a, filename_b): continue - # print("meld '/usr/portage/%s/%s' '%s/%s/%s'" % (category_package, ebuild_name, conf.overlay_path, category_package, ebuild_name)) + # print("meld '%s' '%s'" % (filename_a, filename_b)) ebuild_changes.append(version) return ebuild_changes -- cgit v1.2.3-65-gdbad