factory-package-news.py: Port from pyzstd to zstandard

ariel has only zstandard 0.13.0, so not even the .open method exists.
This commit is contained in:
Fabian Vogt 2023-12-11 13:52:31 +01:00
parent 8516c1ad8f
commit b82749ac01
2 changed files with 10 additions and 8 deletions

View File

@ -58,7 +58,7 @@ Requires: python3-pycurl
Requires: python3-python-dateutil
Requires: python3-pyxdg
# factory-package-news.py
Requires: python3-pyzstd
Requires: python3-zstandard
Requires: python3-requests
# typing extensions are needed on SLE & Leap
%if 0%{?suse_version} <= 1500

View File

@ -9,7 +9,8 @@ import rpm
import pickle
import cmdln
import re
import pyzstd
# Can be replaced with pyzstd (for pyzstd.open) once available on ariel
import zstandard
SRPM_RE = re.compile(
r'(?P<name>.+)-(?P<version>[^-]+)-(?P<release>[^-]+)\.(?P<suffix>(?:no)?src\.rpm)$')
@ -31,11 +32,11 @@ def utf8str(content):
# Older versions wrote uncompressed files, support both for now.
def open_zstd_or_plain(path: str):
f = open(path, 'rb')
if f.read(4) == b'\x28\xb5\x2f\xfd':
f.close()
return pyzstd.open(path, 'rb')
magic = f.read(4)
f.seek(0, os.SEEK_SET)
if magic == b'\x28\xb5\x2f\xfd':
return zstandard.ZstdDecompressor().stream_reader(f, closefd=True)
return f
@ -177,8 +178,9 @@ class ChangeLogger(cmdln.Cmdln):
if not opts.snapshot:
raise Exception("missing snapshot option")
with pyzstd.open(os.path.join(opts.dir, opts.snapshot), 'wb') as f:
pickle.dump([data_version, self.readChangeLogs(dirs)], f)
with open(os.path.join(opts.dir, opts.snapshot), 'wb') as fraw:
with zstandard.ZstdCompressor().stream_writer(fraw, closefd=False) as f:
pickle.dump([data_version, self.readChangeLogs(dirs)], f)
def do_dump(self, subcmd, opts, *dirs):
"""${cmd_name}: pprint the package changelog information