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 AC1D21381F3 for ; Thu, 25 Apr 2013 16:44:36 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B464EE0BA7; Thu, 25 Apr 2013 16:44:32 +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 29683E0BA3 for ; Thu, 25 Apr 2013 16:44:22 +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 EE33733DF5C for ; Thu, 25 Apr 2013 16:44:20 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id C62ACE4410 for ; Thu, 25 Apr 2013 16:44:18 +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: <1366678573.311ac182bba51393153f1c4de4b2580461023608.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/argutil.py roverlay/main.py X-VCS-Directories: roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 311ac182bba51393153f1c4de4b2580461023608 X-VCS-Branch: master Date: Thu, 25 Apr 2013 16:44:18 +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: a4ae5924-b889-4d21-824b-ec3ea949c0ca X-Archives-Hash: a0803a2d72c1c5299f5b1af3e820f2fc commit: 311ac182bba51393153f1c4de4b2580461023608 Author: André Erdmann mailerd de> AuthorDate: Tue Apr 23 00:56:13 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Tue Apr 23 00:56:13 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=311ac182 roverlay/main: apply_rules command This command applies the package rules to all packages and prints the result (package filtered out, package modifed: evar...) to stdout (or to --dump-file). --- roverlay/argutil.py | 26 ++++++++++++++ roverlay/main.py | 92 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 100 insertions(+), 18 deletions(-) diff --git a/roverlay/argutil.py b/roverlay/argutil.py index 23804b6..7237eba 100644 --- a/roverlay/argutil.py +++ b/roverlay/argutil.py @@ -29,6 +29,19 @@ def get_parser ( command_map, default_config_file, default_command='create' ): ) return f + def couldbe_fs_file ( value ): + if value: + f = os.path.abspath ( value ) + if not os.path.exists ( f ) or os.path.isfile ( f ): + return f + + raise argparse.ArgumentTypeError ( + "{!r} is not a file.".format ( value ) + ) + + def couldbe_stdout_or_file ( value ): + return value if value == "-" else couldbe_fs_file ( value ) + def is_fs_dir ( value ): d = os.path.abspath ( value ) if not os.path.isdir ( d ): @@ -283,6 +296,18 @@ def get_parser ( command_map, default_config_file, default_command='create' ): action='store_false', ) + arg ( + '--dump-file', + help=''' + standard file or stdout target for dumping information + (defaults to '-'). Used by the 'apply_rules' action. + ''', + dest="dump_file", + default="-", + metavar="", + type=couldbe_stdout_or_file, + ) + # # TODO # arg ( # '--debug', @@ -339,6 +364,7 @@ def parse_argv ( command_map, **kw ): skip_manifest = p.no_manifest, incremental = p.incremental, immediate_ebuild_writes = p.immediate_ebuild_writes, + dump_file = p.dump_file, ) if given ( 'overlay' ): diff --git a/roverlay/main.py b/roverlay/main.py index b525ffe..7090689 100644 --- a/roverlay/main.py +++ b/roverlay/main.py @@ -119,6 +119,56 @@ def main ( raise # --- end of run_sync() --- + def run_apply_package_rules(): + if "apply_rules" in actions_done: return + + dump_file = OPTION ( "dump_file" ) + FH = None + + prules = PackageRules.get_configured() + + # track package rules + prules.add_trace_actions() + + + BEGIN_RECEIVE_PACKAGE = ( 8 * '-' ) + " {header} " + ( 8 * '-' ) + '\n' + END_RECEIVE_PACKAGE = ( 31 * '-' ) + '\n\n' + + get_header = lambda p : BEGIN_RECEIVE_PACKAGE.format ( + header = ( p ['name'] + ' ' + p ['ebuild_verstr'] ) + ) + + def receive_package ( P ): + if prules.apply_actions ( P ): + if hasattr ( P, 'modified_by_package_rules' ): + # ^ that check is sufficient here + #if P.modified_by_package_rules + + FH.write ( get_header ( P ) ) + + evars = P.get_evars() + if evars: + FH.write ( "evars applied:\n" ) + for evar in evars: + FH.write ( "* {}\n".format ( evar ) ) + + FH.write ( END_RECEIVE_PACKAGE ) + else: + FH.write ( get_header ( P ) ) + FH.write ( "filtered out!\n" ) + FH.write ( END_RECEIVE_PACKAGE ) + + # --- 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 ) + + # --- end of run_apply_package_rules (...) --- + def run_overlay_create(): if "create" in actions_done: return #run_sync() @@ -182,6 +232,7 @@ def main ( 'run an interactive depres console (highly experimental)', 'depres' : 'this is an alias to \'depres_console\'', 'nop' : 'does nothing', + 'apply_rules' : 'apply package rules verbosely and exit afterwards', } @@ -217,6 +268,8 @@ def main ( # imports roverlay.remote, roverlay.overlay.creator actions = set ( filter ( lambda x : x != 'nop', commands ) ) + actions_done = set() + set_action_done = actions_done.add if 'sync' in actions and OPTION ( 'nosync' ): die ( "sync command blocked by --nosync opt.", DIE.ARG ) @@ -282,11 +335,13 @@ def main ( import roverlay.packagerules.rules + package_rules = ( + roverlay.packagerules.rules.PackageRules.get_configured() + ) + HLINE = "".rjust ( 79, '-' ) print ( HLINE ) - print ( - str ( roverlay.packagerules.rules.PackageRules.get_configured() ) - ) + print ( str ( package_rules ) ) print ( HLINE ) EXIT_AFTER_CONFIG = True @@ -294,8 +349,7 @@ def main ( # -- end of EXIT_AFTER_CONFIG entries if 'EXIT_AFTER_CONFIG' in locals() and EXIT_AFTER_CONFIG: - pass - #sys.exit ( os.EX_OK ) + sys.exit ( os.EX_OK ) # switch to depres console elif 'depres_console' in actions or 'depres' in actions: @@ -306,7 +360,7 @@ def main ( from roverlay.depres.simpledeprule.console import DepResConsole con = DepResConsole() con.run() - sys.exit ( os.EX_OK ) + set_action_done ( "depres_console" ) except ImportError: if HIDE_EXCEPTIONS: die ( "Cannot import depres console!", DIE.IMPORT ) @@ -332,25 +386,27 @@ def main ( raise # -- run methods (and some vars) - # imports: nothing + # imports: package rules #repo_list = None #overlay_creator = None - actions_done = set() - set_action_done = actions_done.add - # -- run - # always run sync 'cause commands = {create,sync} - # and create implies (no)sync + # always run sync 'cause commands = {create,sync,apply_rules} + # and create,apply_rules implies (no)sync run_sync() - if 'create' in actions: run_overlay_create() + if "apply_rules" in actions: + from roverlay.packagerules.rules import PackageRules + run_apply_package_rules() + elif 'create' in actions: + run_overlay_create() - if len ( actions ) > len ( actions_done ): - die ( - "Some actions (out of {!r}) could not be performed!".format ( - actions ), DIE.CMD_LEFTOVER - ) + + if len ( actions ) > len ( actions_done ): + die ( + "Some actions (out of {!r}) could not be performed!".format ( + actions ), DIE.CMD_LEFTOVER + ) # --- end of main (...) ---