[swugenerator] [PATCH v3 0/2] Compressed entry changes

39 views
Skip to first unread message

Ernestas Kulik

unread,
Dec 8, 2025, 4:12:52 AM12/8/25
to swup...@googlegroups.com, toe...@gmail.com, Ernestas Kulik
v3: Sign-off commits
v2: Implement Mark Jonas’ suggestion

Ernestas Kulik (2):
generator: Implement xz support
generator: Fix decompressed-size setting

swugenerator/generator.py | 77 ++++++++++++++++-----------------------
1 file changed, 31 insertions(+), 46 deletions(-)

--
2.47.3

Ernestas Kulik

unread,
Dec 8, 2025, 4:13:00 AM12/8/25
to swup...@googlegroups.com, toe...@gmail.com, Ernestas Kulik
While swupdate is capable of decompressing XZ archives, swugenerator
currently does not allow its use in compression. This commit adds
support for it and refactors the compressed entry processing for
maintainability.

Signed-off-by: Ernestas Kulik <ernes...@iconn-networks.com>
---
swugenerator/generator.py | 78 ++++++++++++++++-----------------------
1 file changed, 32 insertions(+), 46 deletions(-)

diff --git a/swugenerator/generator.py b/swugenerator/generator.py
index 4a4ce8e..706b850 100644
--- a/swugenerator/generator.py
+++ b/swugenerator/generator.py
@@ -64,10 +64,40 @@ class SWUGenerator:
def close(self):
self.temp.cleanup()
self.cpiofile.add_trailer()
self.out.close()

+ def process_compressed_entry(self, entry, cmp, new):
+ cmds = {
+ "xz": ["xz", "-f", "-k", "-c"],
+ "zlib": ["gzip", "-f", "-9", "-n", "-c", "--rsyncable"],
+ "zstd": ["zstd", "-z", "-k", "-T0", "-f", "-c"],
+ }
+ cmd = cmds.get(cmp)
+ if not cmd:
+ 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
+
+ cmd.extend([new.fullfilename, ">", new_path])
+
+ try:
+ subprocess.run(" ".join(cmd), shell=True, check=True, text=True)
+ except subprocess.CalledProcessError:
+ logging.critical(
+ "Cannot compress %s with %s", entry["filename"], cmd
+ )
+ sys.exit(1)
+
+ new.fullfilename = new_path
+
+ if entry.get("type") == "ubivol":
+ entry.setdefault("properties", {}) \
+ .update({ "decompressed-size": str(new.getsize()) })
+
def process_entry(self, entry):
if "filename" not in entry:
return
new = None
for image in self.artifacts:
@@ -81,56 +111,12 @@ class SWUGenerator:
logging.critical("Artifact %s not found", entry["filename"])
sys.exit(22)

new.newfilename = entry["filename"]

- if "compressed" in entry and not self.nocompress:
- cmp = entry["compressed"]
- if cmp not in ("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":
- cmd = [
- "gzip",
- "-f",
- "-9",
- "-n",
- "-c",
- "--rsyncable",
- new.fullfilename,
- ">",
- new_path,
- ]
- else:
- cmd = [
- "zstd",
- "-z",
- "-k",
- "-T0",
- "-f",
- "-c",
- new.fullfilename,
- ">",
- new_path,
- ]
-
- try:
- subprocess.run(" ".join(cmd), shell=True, check=True, text=True)
- except subprocess.CalledProcessError:
- logging.critical(
- "Cannot compress %s with %s", entry["filename"], cmd
- )
- sys.exit(1)
-
- new.fullfilename = new_path
-
- if entry.get("type") == "ubivol":
- entry.setdefault("properties", {}) \
- .update({ "decompressed-size": str(new.getsize()) })
+ if not self.nocompress and (cmp := entry.get("compressed")):
+ self.process_compressed_entry(entry, cmp, new)
# compression cannot be used with delta, because it has own compressor
elif ("type" in entry) and entry["type"] == "delta":
cmd = [
"zck",
"-u",
--
2.47.3

Mark Jonas

unread,
Dec 9, 2025, 12:30:49 PM12/9/25
to Ernestas Kulik, swup...@googlegroups.com
Reviewed-by: Mark Jonas <toe...@gmail.com>

Ernestas Kulik

unread,
Feb 17, 2026, 5:44:08 AMFeb 17
to swupdate
Hi, Stefano, mind taking a look at these? Been running these changes for a while with no trouble.

Stefano Babic

unread,
Mar 8, 2026, 7:09:37 AM (6 days ago) Mar 8
to Ernestas Kulik, swupdate
On 2/17/26 11:44, 'Ernestas Kulik' via swupdate wrote:
> Hi, Stefano, mind taking a look at these? Been running these changes for
> a while with no trouble.
>

Sorry, I saw this, I recognized to take care of it, put at the end of
TODO list (and then forgotten again..).

Applied now, sorry for delay.

Best regards,
Stefano Babic

> On Monday, December 8, 2025 at 11:12:52 AM UTC+2 Ernestas Kulik wrote:
>
> v3: Sign-off commits
> v2: Implement Mark Jonas’ suggestion
>
> Ernestas Kulik (2):
> generator: Implement xz support
> generator: Fix decompressed-size setting
>
> swugenerator/generator.py | 77 ++++++++++++++++-----------------------
> 1 file changed, 31 insertions(+), 46 deletions(-)
>
> --
> 2.47.3
>
> --
> You received this message because you are subscribed to the Google
> Groups "swupdate" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swupdate+u...@googlegroups.com
> <mailto:swupdate+u...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/
> swupdate/664de0bf-a5f6-45e0-bcff-05f3879cf6een%40googlegroups.com
> <https://groups.google.com/d/msgid/swupdate/664de0bf-a5f6-45e0-
> bcff-05f3879cf6een%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
_______________________________________________________________________
Nabla Software Engineering GmbH
Hirschstr. 111A | 86156 Augsburg | Tel: +49 821 45592596
Geschäftsführer : Stefano Babic | HRB 40522 Augsburg
E-Mail: sba...@nabladev.com

Reply all
Reply to author
Forward
0 new messages