public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/setupscript/, roverlay/
Date: Tue, 17 Sep 2013 16:40:55 +0000 (UTC)	[thread overview]
Message-ID: <1379427003.5dd5292462c176a1d1e7458ecd69fd4467ed9440.dywi@gentoo> (raw)

commit:     5dd5292462c176a1d1e7458ecd69fd4467ed9440
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Sep 17 14:10:03 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Sep 17 14:10:03 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=5dd52924

ArgumentParserProxy: use existing parser

@classmethod create_new_parser(...) can be used to get the old behavior
(ArgumentParserProxy creates the parser).

---
 roverlay/argparser.py           | 31 ++++++++++++++++++-------------
 roverlay/argutil.py             | 17 +++++++++++++----
 roverlay/runtime.py             |  4 +++-
 roverlay/setupscript/runtime.py |  6 +++---
 roverlay/status.py              |  4 +++-
 5 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/roverlay/argparser.py b/roverlay/argparser.py
index 154fdce..5b28d0f 100644
--- a/roverlay/argparser.py
+++ b/roverlay/argparser.py
@@ -37,42 +37,45 @@ class RoverlayArgumentParserBase ( roverlay.argutil.ArgumentParserProxy ):
 
    DESCRIPTION_TEMPLATE = None
 
-   def __init__ (
-      self, defaults=None, description=True, formatter_class=True,
-      format_description=False, **kwargs
+   @classmethod
+   def create_new_parser ( cls,
+      defaults=None, description=True, formatter_class=True,
+      format_description=True, **kwargs
    ):
       if description is True:
-         if self.DESCRIPTION_TEMPLATE is None:
+         if cls.DESCRIPTION_TEMPLATE is None:
             desc = (
                roverlay.core.description_str + '\n'
                + roverlay.core.license_str
             )
          else:
-            desc = self.format_description()
+            desc = cls.format_description()
       elif description:
          if format_description:
-            desc = self.format_description ( description )
+            desc = cls.format_description ( description )
          else:
             desc = description
       else:
          desc = None
 
-      super ( RoverlayArgumentParserBase, self ).__init__ (
+      return super ( RoverlayArgumentParserBase, cls ).create_new_parser (
          defaults        = defaults,
          description     = desc,
          formatter_class = (
             argparse.RawDescriptionHelpFormatter
             if formatter_class is True else formatter_class
          ),
-         **kwargs
       )
+   # --- end of create_new_parser (...) ---
 
-
+   def __init__ ( self, *args, **kwargs ):
+      super ( RoverlayArgumentParserBase, self ).__init__ ( *args, **kwargs )
       self.extra_conf = None
    # --- end of __init__ (...) ---
 
-   def format_description ( self, desc=None ):
-      return ( self.DESCRIPTION_TEMPLATE if desc is None else desc ).format (
+   @classmethod
+   def format_description ( cls, desc=None ):
+      return ( cls.DESCRIPTION_TEMPLATE if desc is None else desc ).format (
          version=roverlay.core.version,
          license=roverlay.core.license_str,
       )
@@ -566,8 +569,10 @@ class RoverlayArgumentParser ( RoverlayArgumentParserBase ):
    COMMAND_DESCRIPTION = None
    DEFAULT_COMMAND     = None
 
-   def __init__ ( self, default_command=None, **kwargs ):
-      super ( RoverlayArgumentParser, self ).__init__ ( **kwargs )
+   def __init__ ( self, parser, default_command=None, defaults=None ):
+      super ( RoverlayArgumentParser, self ).__init__ (
+         parser, defaults=defaults
+      )
       self.default_command = (
          self.DEFAULT_COMMAND if default_command is None else default_command
       )

diff --git a/roverlay/argutil.py b/roverlay/argutil.py
index 90444a3..c3981e5 100644
--- a/roverlay/argutil.py
+++ b/roverlay/argutil.py
@@ -184,11 +184,20 @@ class ArgumentParserProxy ( object ):
    STR_SUPPRESS = 'keep'
 
 
-
-
-   def __init__ ( self, defaults=None, **kwargs ):
+   @classmethod
+   def create_new_parser ( cls, defaults=None, **kwargs ):
+      parser = argparse.ArgumentParser ( **kwargs )
+      return cls ( parser, defaults=defaults )
+   # --- end of create_new_parser (...) ---
+
+   @classmethod
+   def wrap ( cls, parser, defaults=None ):
+      return cls ( parser, defaults=defaults )
+   # --- end of wrap (...) ---
+
+   def __init__ ( self, parser, defaults=None ):
       super ( ArgumentParserProxy, self ).__init__()
-      self.parser = argparse.ArgumentParser (**kwargs )
+      self.parser = parser
 
       if defaults is None:
          self.defaults = dict()

diff --git a/roverlay/runtime.py b/roverlay/runtime.py
index 2c12334..43140b2 100644
--- a/roverlay/runtime.py
+++ b/roverlay/runtime.py
@@ -150,7 +150,9 @@ class RuntimeEnvironmentBase ( MinimalRuntimeEnvironment ):
 
 class RuntimeEnvironment ( RuntimeEnvironmentBase ):
 
-   ARG_PARSER_CLS = roverlay.argparser.RoverlayMainArgumentParser
+   ARG_PARSER_CLS = (
+      roverlay.argparser.RoverlayMainArgumentParser.create_new_parser
+   )
 
    def __init__ ( self, installed, *args, **kw ):
       super ( RuntimeEnvironment, self ).__init__ ( installed, *args, **kw )

diff --git a/roverlay/setupscript/runtime.py b/roverlay/setupscript/runtime.py
index 8b51973..75bfff6 100644
--- a/roverlay/setupscript/runtime.py
+++ b/roverlay/setupscript/runtime.py
@@ -47,7 +47,7 @@ def arg_stdout_or_fs ( value ):
 # --- end of arg_stdout_or_fs (...) ---
 
 
-class SetupArgParser ( roverlay.argparser.RoverlayArgumentParser ):
+class SetupArgumentParser ( roverlay.argparser.RoverlayArgumentParser ):
    MULTIPLE_COMMANDS = False
    COMMAND_DESCRIPTION = {
       'init'     : 'initialize roverlay\'s config and filesystem layout',
@@ -262,7 +262,7 @@ class SetupArgParser ( roverlay.argparser.RoverlayArgumentParser ):
       return arg
    # --- end of setup_hooks (...) ---
 
-# --- end of SetupArgParser ---
+# --- end of SetupArgumentParser ---
 
 
 class SetupEnvironment ( roverlay.runtime.IndependentRuntimeEnvironment ):
@@ -326,7 +326,7 @@ class SetupEnvironment ( roverlay.runtime.IndependentRuntimeEnvironment ):
    # --- end of get_parser_defaults (...) ---
 
    def create_argparser ( self ):
-      return SetupArgParser (
+      return SetupArgumentParser.create_new_parser (
          description = 'roverlay setup script',
          defaults    = self.get_parser_defaults(),
          epilog      = (

diff --git a/roverlay/status.py b/roverlay/status.py
index 50372b8..cb25edb 100644
--- a/roverlay/status.py
+++ b/roverlay/status.py
@@ -118,7 +118,9 @@ class SelfReferencingDict ( ReferenceableDict ):
 
 
 class StatusRuntimeEnvironment ( roverlay.runtime.RuntimeEnvironmentBase ):
-   ARG_PARSER_CLS = roverlay.argparser.RoverlayStatusArgumentParser
+   ARG_PARSER_CLS = (
+      roverlay.argparser.RoverlayStatusArgumentParser.create_new_parser
+   )
 
    TEMPLATE_ENCODING = 'utf-8'
 


             reply	other threads:[~2013-09-17 16:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-17 16:40 André Erdmann [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-02-22 14:56 [gentoo-commits] proj/R_overlay:master commit in: roverlay/setupscript/, roverlay/ André Erdmann
2013-09-16 13:43 André Erdmann
2013-09-11 11:14 André Erdmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1379427003.5dd5292462c176a1d1e7458ecd69fd4467ed9440.dywi@gentoo \
    --to=dywi@mailerd.de \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox