[elbe-devel] [PATCH 1/5] elbepack: preprocess: remove option parsing from PreprocessWrapper

Thomas Weißschuh thomas.weissschuh at linutronix.de
Wed Jul 3 11:10:55 CEST 2024


The class PreprocessWrapper has no business parsing commandline options
for random commandline utilities.
Move that loginc into elbepack.commands.preprocess where the meat of the
logic resides anyways.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/commands/initvm.py     |  4 ++--
 elbepack/commands/pbuilder.py   |  4 ++--
 elbepack/commands/preprocess.py | 15 ++++++++++++---
 elbepack/xmlpreprocess.py       | 13 -------------
 4 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/elbepack/commands/initvm.py b/elbepack/commands/initvm.py
index a42b2f78a93d..3bfe6ab32944 100644
--- a/elbepack/commands/initvm.py
+++ b/elbepack/commands/initvm.py
@@ -7,8 +7,8 @@ import sys
 from optparse import OptionParser, SUPPRESS_HELP
 
 from elbepack.commands import add_deprecated_optparse_option
+from elbepack.commands.preprocess import add_xmlpreprocess_passthrough_options
 from elbepack.initvmaction import InitVMAction, InitVMError
-from elbepack.xmlpreprocess import PreprocessWrapper
 
 
 def run_command(argv):
@@ -66,7 +66,7 @@ def run_command(argv):
                        dest='fail_on_warning', default=False,
                        help=SUPPRESS_HELP)
 
-    PreprocessWrapper.add_options(oparser)
+    add_xmlpreprocess_passthrough_options(oparser)
 
     (opt, args) = oparser.parse_args(argv)
 
diff --git a/elbepack/commands/pbuilder.py b/elbepack/commands/pbuilder.py
index f38485d6130b..f91e466cd781 100644
--- a/elbepack/commands/pbuilder.py
+++ b/elbepack/commands/pbuilder.py
@@ -5,8 +5,8 @@
 import sys
 from optparse import OptionParser
 
+from elbepack.commands.preprocess import add_xmlpreprocess_passthrough_options
 from elbepack.pbuilderaction import PBuilderAction, PBuilderError
-from elbepack.xmlpreprocess import PreprocessWrapper
 
 
 def run_command(argv):
@@ -61,7 +61,7 @@ def run_command(argv):
                             '(should be a number followed by an optional '
                             'suffix: k, M, G, T. Use 0 for no limit.)')
 
-    PreprocessWrapper.add_options(oparser)
+    add_xmlpreprocess_passthrough_options(oparser)
 
     (opt, args) = oparser.parse_args(argv)
 
diff --git a/elbepack/commands/preprocess.py b/elbepack/commands/preprocess.py
index 65f58a87d3a4..5d7d2b62f05d 100644
--- a/elbepack/commands/preprocess.py
+++ b/elbepack/commands/preprocess.py
@@ -4,12 +4,12 @@
 
 import os
 import sys
-from optparse import OptionParser
+from optparse import OptionGroup, OptionParser
 
 from elbepack.xmlpreprocess import XMLPreprocessError, xmlpreprocess
 
 
-def add_pass_through_options(oparser):
+def _add_options(oparser):
     oparser.add_option('-v', '--variants', dest='variant',
                        default=None,
                        help='enable only tags with empty or given variant')
@@ -23,12 +23,21 @@ def add_pass_through_options(oparser):
                        help='gzip compression level 1-9 (0: no compression)')
 
 
+def add_xmlpreprocess_passthrough_options(oparser):
+    group = OptionGroup(oparser,
+                        'Elbe preprocess options',
+                        'Options passed through to invocation of '
+                        '"elbe preprocess"')
+    _add_options(group)
+    oparser.add_option_group(group)
+
+
 def run_command(argv):
     oparser = OptionParser(usage='usage: %prog preprocess [options] <xmlfile>')
     oparser.add_option('-o', '--output', dest='output',
                        default='preprocess.xml',
                        help='preprocessed output file', metavar='<xmlfile>')
-    add_pass_through_options(oparser)
+    _add_options(oparser)
     (opt, args) = oparser.parse_args(argv)
 
     if len(args) != 1:
diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index 099cf82c22d1..dab9dcbd426c 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -11,7 +11,6 @@ import sys
 import tempfile
 import time
 import warnings
-from optparse import OptionGroup
 from urllib.error import HTTPError, URLError
 from urllib.request import urlopen
 
@@ -466,18 +465,6 @@ class PreprocessWrapper:
     def __exit__(self, _typ, _value, _traceback):
         os.remove(self.outxml)
 
-    @staticmethod
-    def add_options(oparser):
-        # import it here because of cyclic imports
-        from elbepack.commands.preprocess import add_pass_through_options
-
-        group = OptionGroup(oparser,
-                            'Elbe preprocess options',
-                            'Options passed through to invocation of '
-                            '"elbe preprocess"')
-        add_pass_through_options(group)
-        oparser.add_option_group(group)
-
     @property
     def preproc(self):
         return self.outxml

-- 
2.45.2



More information about the elbe-devel mailing list