Skip to content

Commit

Permalink
Merge pull request #3002 from g7/factory-news-tw
Browse files Browse the repository at this point in the history
factory-package-news: support newer python3 rpm bindings
  • Loading branch information
dirkmueller committed Aug 4, 2023
2 parents 82c067d + 17f0cd5 commit 9200c9e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions factory-package-news/factory-package-news.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
changelog_max_lines = 100 # maximum number of changelog lines per package


# rpm's python bindings changed in version 4.15 [0] so that they actually return
# utf-8 strings. Leap 15 ships an older version, so this is needed to
# keep this script working there too.
#
# [0] https://github.com/rpm-software-management/rpm/commit/84920f898315d09a57a3f1067433eaeb7de5e830
def forcestr(content):
return str(content, 'utf-8') if isinstance(content, bytes) else content


class ChangeLogger(cmdln.Cmdln):
def __init__(self, *args, **kwargs):
cmdln.Cmdln.__init__(self, args, kwargs)
Expand Down Expand Up @@ -51,12 +60,12 @@ def readChangeLogs(self, args):
changelogs = dict()

def _getdata(h):
srpm = str(h['sourcerpm'], 'utf-8')
binrpm = str(h['name'], 'utf-8')
srpm = forcestr(h['sourcerpm'])
binrpm = forcestr(h['name'])

evr = dict()
for tag in ['name', 'version', 'release', 'sourcerpm']:
evr[tag] = str(h[tag], 'utf-8')
evr[tag] = forcestr(h[tag])
pkgdata[binrpm] = evr

# dirty hack to reduce kernel spam
Expand All @@ -80,7 +89,7 @@ def _getdata(h):
):
srpm = '%s-%s-%s.src.rpm' % ('kernel-source', m.group('version'), m.group('release'))
pkgdata[binrpm]['sourcerpm'] = srpm
print("%s -> %s" % (str(h['sourcerpm'], 'utf-8'), srpm))
print("%s -> %s" % (forcestr(h['sourcerpm']), srpm))

if srpm in changelogs:
changelogs[srpm]['packages'].append(binrpm)
Expand All @@ -89,7 +98,7 @@ def _getdata(h):
data['changelogtime'] = h['changelogtime']
data['changelogtext'] = h['changelogtext']
for (t, txt) in enumerate(data['changelogtext']):
data['changelogtext'][t] = str(txt, 'utf-8')
data['changelogtext'][t] = forcestr(txt)
changelogs[srpm] = data

for arg in args:
Expand Down

0 comments on commit 9200c9e

Please sign in to comment.