Skip to content

Commit

Permalink
Merge pull request openSUSE#3040 from openSUSE/revert-3039-zstdnews
Browse files Browse the repository at this point in the history
Revert "factory-package-news.py: Compress data files with zstd"
  • Loading branch information
Vogtinator committed Dec 13, 2023
2 parents 8e4cdc3 + 47bf1c2 commit 02b3886
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
2 changes: 0 additions & 2 deletions dist/package/openSUSE-release-tools.spec
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ Requires: python3-lxml
Requires: python3-pycurl
Requires: python3-python-dateutil
Requires: python3-pyxdg
# factory-package-news.py
Requires: python3-zstandard
Requires: python3-requests
# typing extensions are needed on SLE & Leap
%if 0%{?suse_version} <= 1500
Expand Down
36 changes: 11 additions & 25 deletions factory-package-news/factory-package-news.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import pickle
import cmdln
import re
# 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 @@ -29,17 +27,6 @@ def utf8str(content):
return str(content, 'utf-8') if isinstance(content, bytes) else content


# Older versions wrote uncompressed files, support both for now.
def open_zstd_or_plain(path: str):
f = 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


class ChangeLogger(cmdln.Cmdln):
def __init__(self, *args, **kwargs):
cmdln.Cmdln.__init__(self, args, kwargs)
Expand Down Expand Up @@ -178,9 +165,8 @@ def do_save(self, subcmd, opts, *dirs):
if not opts.snapshot:
raise Exception("missing snapshot option")

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)
f = open(os.path.join(opts.dir, opts.snapshot), 'wb')
pickle.dump([data_version, self.readChangeLogs(dirs)], f)

def do_dump(self, subcmd, opts, *dirs):
"""${cmd_name}: pprint the package changelog information
Expand All @@ -196,9 +182,9 @@ def do_inspect(self, subcmd, opts, filename, package):
${cmd_usage}
${cmd_option_list}
"""
with open_zstd_or_plain(filename) as f:
(v, (pkgs, changelogs)) = pickle.load(
f, encoding='utf-8', errors='backslashreplace')
f = open(filename, 'rb')
(v, (pkgs, changelogs)) = pickle.load(
f, encoding='utf-8', errors='backslashreplace')
pprint(pkgs[package])
pprint(changelogs[pkgs[package]['sourcerpm']])

Expand All @@ -223,14 +209,14 @@ def do_diff(self, subcmd, opts, version1, version2):
if not os.path.isdir(opts.dir):
raise Exception("%s must be a directory" % opts.dir)

with open_zstd_or_plain(os.path.join(opts.dir, version1)) as f:
(v, (v1pkgs, v1changelogs)) = pickle.load(f,
encoding='utf-8', errors='backslashreplace')
f = open(os.path.join(opts.dir, version1), 'rb')
(v, (v1pkgs, v1changelogs)) = pickle.load(f,
encoding='utf-8', errors='backslashreplace')
if v != data_version:
raise Exception("not matching version %s in %s" % (v, version1))
with open_zstd_or_plain(os.path.join(opts.dir, version2)) as f:
(v, (v2pkgs, v2changelogs)) = pickle.load(f,
encoding='utf-8', errors='backslashreplace')
f = open(os.path.join(opts.dir, version2), 'rb')
(v, (v2pkgs, v2changelogs)) = pickle.load(f,
encoding='utf-8', errors='backslashreplace')
if v != data_version:
raise Exception("not matching version %s in %s" % (v, version2))

Expand Down

0 comments on commit 02b3886

Please sign in to comment.