| Message ID | 20251205081343.1541426-1-ernestas.k@iconn-networks.com |
|---|---|
| State | Changes Requested |
| Headers | show |
| Series | [swugenerator,1/2] generator: Implement xz support | expand |
Hi Ernestas, On Fri, Dec 5, 2025 at 9:14 AM 'Ernestas Kulik' via swupdate <swupdate@googlegroups.com> wrote: > > --- > swugenerator/generator.py | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/swugenerator/generator.py b/swugenerator/generator.py > index 4a4ce8e..eb3a8f8 100644 > --- a/swugenerator/generator.py > +++ b/swugenerator/generator.py > @@ -83,17 +83,27 @@ class SWUGenerator: > > new.newfilename = entry["filename"] > > if "compressed" in entry and not self.nocompress: > cmp = entry["compressed"] > - if cmp not in ("zlib", "zstd"): > + if cmp not in ("xz", "zlib", "zstd"): > logging.critical("Wrong compression algorithm: %s", cmp) > sys.exit(1) > > new_path = os.path.join(self.temp.name, new.newfilename) + "." + cmp > new.newfilename = new.newfilename + "." + cmp > - if cmp == "zlib": > + if cmp == "xz": > + cmd = [ > + "xz", > + "-f", > + "-k", > + "-c", > + new.fullfilename, > + ">", > + new_path, > + ] > + elif cmp == "zlib": > cmd = [ > "gzip", > "-f", > "-9", > "-n", > @@ -101,11 +111,11 @@ class SWUGenerator: > "--rsyncable", > new.fullfilename, > ">", > new_path, > ] > - else: > + elif cmp == "zstd": > cmd = [ > "zstd", > "-z", > "-k", > "-T0", > -- I think we could improve the robustness and maintainability a little by moving the critical error that cmp does not match a supported compression into the else. Then, we do not need to maintain two lists with the supported compression. if cmp == "xz": ... elif cmp == "zlib": ... elif cmp == "zstd": ... else logging.critical("Wrong compression algorithm: %s", cmp) sys.exit(1) IMHO an even better and more pythonic (?) approach (attention, untested code!) could be: compress_cmd_args = { "xz": ["xz", "-f", "-k", "-c"], "zlib": ["gzip", "-f", "-9", "-n", "-c", "--rsyncable"], "zstd": ["zstd", "-z", "-k", "-T0", "-f", "-c"], } if cmp not in compress_cmd_args: logging.critical("Wrong compression algorithm: %s", cmp) sys.exit(1) cmd = compress_cmd_args[cmp] + [new.fullfilename, ">", new_path] Cheers, Mark
On Sun, 2025-12-07 at 10:17 +0100, Mark Jonas wrote: > Hi Ernestas, Hi, Mark, > I think we could improve the robustness and maintainability a little > by moving the critical error that cmp does not match a supported > compression into the else. Then, we do not need to maintain two lists > with the supported compression. > > if cmp == "xz": > ... > elif cmp == "zlib": > ... > elif cmp == "zstd": > ... > else > logging.critical("Wrong compression algorithm: %s", cmp) > sys.exit(1) > > IMHO an even better and more pythonic (?) approach (attention, > untested code!) could be: > > compress_cmd_args = { > "xz": ["xz", "-f", "-k", "-c"], > "zlib": ["gzip", "-f", "-9", "-n", "-c", "--rsyncable"], > "zstd": ["zstd", "-z", "-k", "-T0", "-f", "-c"], > } > > if cmp not in compress_cmd_args: > logging.critical("Wrong compression algorithm: %s", cmp) > sys.exit(1) > > cmd = compress_cmd_args[cmp] + [new.fullfilename, ">", new_path] I’ll see what can be arranged, thanks for taking a look. :)
diff --git a/swugenerator/generator.py b/swugenerator/generator.py index 4a4ce8e..eb3a8f8 100644 --- a/swugenerator/generator.py +++ b/swugenerator/generator.py @@ -83,17 +83,27 @@ class SWUGenerator: new.newfilename = entry["filename"] if "compressed" in entry and not self.nocompress: cmp = entry["compressed"] - if cmp not in ("zlib", "zstd"): + if cmp not in ("xz", "zlib", "zstd"): logging.critical("Wrong compression algorithm: %s", cmp) sys.exit(1) new_path = os.path.join(self.temp.name, new.newfilename) + "." + cmp new.newfilename = new.newfilename + "." + cmp - if cmp == "zlib": + if cmp == "xz": + cmd = [ + "xz", + "-f", + "-k", + "-c", + new.fullfilename, + ">", + new_path, + ] + elif cmp == "zlib": cmd = [ "gzip", "-f", "-9", "-n", @@ -101,11 +111,11 @@ class SWUGenerator: "--rsyncable", new.fullfilename, ">", new_path, ] - else: + elif cmp == "zstd": cmd = [ "zstd", "-z", "-k", "-T0",