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 D14931381F3 for ; Fri, 6 Sep 2013 17:27:47 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3BE22E0FB6; Fri, 6 Sep 2013 17:27:47 +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 B46CDE0FB0 for ; Fri, 6 Sep 2013 17:27:46 +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 9BB4C33EBA1 for ; Fri, 6 Sep 2013 17:27:45 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 3DB3CE5465 for ; Fri, 6 Sep 2013 17:27:43 +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: <1378488116.e89719a69f61008ac51bd8c7b3a3e24b905ea4f3.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/argparser.py roverlay/argutil.py X-VCS-Directories: roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: e89719a69f61008ac51bd8c7b3a3e24b905ea4f3 X-VCS-Branch: master Date: Fri, 6 Sep 2013 17:27:43 +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: 22a28bd8-ad8d-4fe3-b732-3e1fe8f0d696 X-Archives-Hash: 3d5a9a3778e9ce618a63d1595d06eda7 commit: e89719a69f61008ac51bd8c7b3a3e24b905ea4f3 Author: André Erdmann mailerd de> AuthorDate: Fri Sep 6 17:21:56 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Fri Sep 6 17:21:56 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=e89719a6 argparser: support >=1 command(s) + get_options(), get_commands() functions for getting options/commands --- roverlay/argparser.py | 14 ++++++++++++-- roverlay/argutil.py | 11 +++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/roverlay/argparser.py b/roverlay/argparser.py index 98b09a1..c7be8f6 100644 --- a/roverlay/argparser.py +++ b/roverlay/argparser.py @@ -73,7 +73,7 @@ class RoverlayArgumentParserBase ( roverlay.argutil.ArgumentParserProxy ): # '* - ' '* {cmd} - {desc}'.format ( cmd=cmd.ljust ( 15 ), desc=desc - ) for cmd, desc in command_map.items() + ) for cmd, desc in command_map.items() if cmd is not None ) ) # --- end of format_command_map (...) --- @@ -537,6 +537,7 @@ class RoverlayArgumentParserBase ( roverlay.argutil.ArgumentParserProxy ): class RoverlayArgumentParser ( RoverlayArgumentParserBase ): + MULTIPLE_COMMANDS = False COMMAND_DESCRIPTION = None DEFAULT_COMMAND = None @@ -551,6 +552,13 @@ class RoverlayArgumentParser ( RoverlayArgumentParserBase ): assert self.default_command in self.COMMAND_DESCRIPTION # --- end of __init__ (...) --- + def get_commands ( self ): + if self.MULTIPLE_COMMANDS: + return self.command + else: + return ( self.command, ) + # --- end of get_commands (...) --- + def setup_actions ( self ): arg = self.add_argument_group ( "actions", title="actions", @@ -559,7 +567,8 @@ class RoverlayArgumentParser ( RoverlayArgumentParserBase ): arg ( 'command', default=self.default_command, metavar='', - nargs="?", choices=self.COMMAND_DESCRIPTION.keys(), + nargs=( "*" if self.MULTIPLE_COMMANDS else "?" ), + choices=self.COMMAND_DESCRIPTION.keys(), flags=self.ARG_HELP_DEFAULT, help="action to perform" ) @@ -573,6 +582,7 @@ class RoverlayArgumentParser ( RoverlayArgumentParserBase ): # --- end of RoverlayArgumentParser --- + class RoverlayStatusArgumentParser ( RoverlayArgumentParser ): DESCRIPTION_TEMPLATE = "roverlay status tool {version}\n{license}" diff --git a/roverlay/argutil.py b/roverlay/argutil.py index 73e88b6..d6ba97e 100644 --- a/roverlay/argutil.py +++ b/roverlay/argutil.py @@ -9,6 +9,9 @@ import argparse import pwd import grp + +from roverlay.config.entryutil import deref_entry_safe + def get_uid ( user ): try: return int ( user ) @@ -193,6 +196,14 @@ class ArgumentParserProxy ( object ): self.parsed = None # --- end of __init__ (...) --- + def get_options ( self ): + return self.parsed + # --- end of get_options (...) --- + + def get_commands ( self ): + return () + # --- end of get_commands (...) --- + def get_default ( self, key, *args ): return self.defaults.get ( key, *args ) # --- end of get_default (...) ---