Skip to content

Commit

Permalink
factory-package-news.py: Port from pyzstd to zstandard
Browse files Browse the repository at this point in the history
ariel has only zstandard 0.13.0, so not even the .open method exists.
  • Loading branch information
Vogtinator committed Dec 11, 2023
1 parent 8516c1a commit b82749a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/package/openSUSE-release-tools.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions factory-package-news/factory-package-news.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
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)$')
Expand All @@ -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


Expand Down Expand Up @@ -177,8 +178,9 @@ def do_save(self, subcmd, opts, *dirs):
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
Expand Down

0 comments on commit b82749a

Please sign in to comment.