From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 9F2691381F3 for ; Tue, 4 Jun 2013 21:07:03 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4E78AE08A1; Tue, 4 Jun 2013 21:06:59 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A0FFAE086F for ; Tue, 4 Jun 2013 21:06:58 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 4A99D33E2F6 for ; Tue, 4 Jun 2013 21:06:57 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id D09C2E468F for ; Tue, 4 Jun 2013 21:06:55 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1368470908.a3647944a790117bd668c48f578b3d3fcfe2d5d3.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/main.py X-VCS-Directories: roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: a3647944a790117bd668c48f578b3d3fcfe2d5d3 X-VCS-Branch: master Date: Tue, 4 Jun 2013 21:06:55 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 0d05f5a2-fa72-48ea-9ce1-46ea0918833e X-Archives-Hash: 3a7a7c455f859ed780acf1b41a05009f commit: a3647944a790117bd668c48f578b3d3fcfe2d5d3 Author: André Erdmann mailerd de> AuthorDate: Mon May 13 18:48:28 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Mon May 13 18:48:28 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=a3647944 'apply_rules' command: count modified packages --- roverlay/main.py | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/roverlay/main.py b/roverlay/main.py index 7090689..c3f919b 100644 --- a/roverlay/main.py +++ b/roverlay/main.py @@ -130,6 +130,8 @@ def main ( # track package rules prules.add_trace_actions() + NUM_MODIFIED = 0 + BEGIN_RECEIVE_PACKAGE = ( 8 * '-' ) + " {header} " + ( 8 * '-' ) + '\n' END_RECEIVE_PACKAGE = ( 31 * '-' ) + '\n\n' @@ -138,6 +140,28 @@ def main ( header = ( p ['name'] + ' ' + p ['ebuild_verstr'] ) ) + def bool_counter ( f ): + """Wrapper that returns a 2-tuple (result_list, function f'). + f' which increases result_list first or second element depending + on the return value of function f. + + arguments: + * f -- function to wrap + """ + result_list = [ 0, 0 ] + + def wrapped ( *args, **kwargs ): + result = f ( *args, **kwargs ) + if result: + result_list [0] += 1 + else: + result_list [1] += 1 + return result + # --- end of wrapped (...) --- + + return result_list, wrapped + # --- end of bool_counter (...) --- + def receive_package ( P ): if prules.apply_actions ( P ): if hasattr ( P, 'modified_by_package_rules' ): @@ -152,20 +176,58 @@ def main ( for evar in evars: FH.write ( "* {}\n".format ( evar ) ) + + if P.modified_by_package_rules is not True: + # ^ check needs to be changed when adding more trace actions + FH.write ( "trace marks:\n" ) + for s in P.modified_by_package_rules: + if s is not True: + FH.write ( "* {}\n".format ( s ) ) + FH.write ( END_RECEIVE_PACKAGE ) + else: + # not modified + return False else: FH.write ( get_header ( P ) ) FH.write ( "filtered out!\n" ) FH.write ( END_RECEIVE_PACKAGE ) + # modifed + return True # --- end of receive_package (...) --- - if dump_file == "-": - FH = sys.stdout - repo_list.add_packages ( receive_package ) - else: - with open ( dump_file, 'wt' ) as FH: - repo_list.add_packages ( receive_package ) + modify_counter, receive_package_counting = bool_counter ( receive_package ) + + try: + if dump_file == "-": + FH_SHARED = True + FH = sys.stdout + else: + FH_SHARED = False + FH = open ( dump_file, 'wt' ) + + time_start = time.time() + repo_list.add_packages ( receive_package_counting ) + time_add_packages = time.time() - time_start + + if modify_counter [0] > 0: + FH.write ( "\n" ) + + #FH.write ( + sys.stdout.write ( + 'done after {t} seconds\n' + '{p} packages processed in total, out of which ' + '{m} have been modified or filtered out\n'.format ( + t = round ( time_add_packages, 1 ), + p = ( modify_counter [0] + modify_counter [1] ), + m = modify_counter [0] + ) + ) + + finally: + if 'FH' in locals() and not FH_SHARED: + FH.close() # --- end of run_apply_package_rules (...) ---