[elbe-devel] [PATCH 14/15] preprocess: introduce compression level

Benedikt Spranger b.spranger at linutronix.de
Thu Oct 26 15:41:12 CEST 2023


From: Bastian Germann <bage at linutronix.de>

elbe preprocess uses preprocess.xml as default file name but applies a
gzip compression unexpectedly. Introduce a parameter to explicitly set
the gzip compression level.

Closes #213.

[Benedikt Spranger: Forwarded to E.L.B.E. v14.9.2]

Signed-off-by: Bastian Germann <bage at linutronix.de>
Signed-off-by: Benedikt Spranger <b.spranger at linutronix.de>
---
 elbepack/commands/preprocess.py | 5 ++++-
 elbepack/xmlpreprocess.py       | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/elbepack/commands/preprocess.py b/elbepack/commands/preprocess.py
index 823ee8d8..f99f456e 100644
--- a/elbepack/commands/preprocess.py
+++ b/elbepack/commands/preprocess.py
@@ -17,6 +17,9 @@ def add_pass_through_options(oparser):
                        default=None,
                        help="add proxy to mirrors")
 
+    oparser.add_option("-z", "--gzip", dest="gzip", type="int",
+                       default=9,
+                       help="gzip compression level 1-9 (0: no compression)")
 
 def run_command(argv):
     oparser = OptionParser(usage="usage: %prog preprocess [options] <xmlfile>")
@@ -40,7 +43,7 @@ def run_command(argv):
         variants = opt.variant.split(',')
 
     try:
-        xmlpreprocess(args[0], opt.output, variants, opt.proxy)
+        xmlpreprocess(args[0], opt.output, variants, opt.proxy, opt.gzip)
     except XMLPreprocessError as e:
         print(e, file=sys.stderr)
         sys.exit(20)
diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index edd582ba..bbd47ba6 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -294,7 +294,7 @@ def preprocess_passwd(xml):
                         "The generated sha512crypt hash only applies 5000 rounds for "
                         "backwards compatibility reasons. This is considered insecure nowadays.")
 
-def xmlpreprocess(xml_input_file, xml_output_file, variants=None, proxy=None):
+def xmlpreprocess(xml_input_file, xml_output_file, variants=None, proxy=None, gzip=9):
     """Preprocesses the input XML data to make sure the `output`
        can be validated against the current schema.
        `xml_input_file` is either a file-like object or a path (str) to the input file.
@@ -393,7 +393,7 @@ def xmlpreprocess(xml_input_file, xml_output_file, variants=None, proxy=None):
                 xml_output_file,
                 encoding="UTF-8",
                 pretty_print=True,
-                compression=9)
+                compression=gzip)
             # the rest of the code is exception and error handling
             return
 
-- 
2.42.0



More information about the elbe-devel mailing list