Blob Blame History Raw
From 971acb87d420ea2e8058f0f2cb47614dcbbd12f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= <lsedlar@redhat.com>
Date: Tue, 8 Oct 2019 10:12:37 +0200
Subject: [PATCH] Revert "Update for newer RPM"

This reverts commit 86c951c4661d3af234f8a7b7e560ab88e12a3f2b.
---
 compose_utils/changelog.py | 15 ++-------------
 tests/test_changelog.py    | 20 ++++++++++----------
 2 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/compose_utils/changelog.py b/compose_utils/changelog.py
index 958a519..0aec6c6 100644
--- a/compose_utils/changelog.py
+++ b/compose_utils/changelog.py
@@ -14,8 +14,6 @@ import json
 import re
 from distutils.version import LooseVersion
 
-import six
-
 import kobo.pkgset
 from kobo.rpmlib import parse_nvra, make_nvr, make_nvra, get_changelogs_from_header
 from kobo.threads import ThreadPool, WorkerThread
@@ -40,13 +38,6 @@ def formatsize(size):
 
 
 def to_utf8(text):
-    if six.PY3:
-        # Nothing needs to happen on Python 3, we already get correctly decoded
-        # data from kobo or rpm.
-        return text
-    if not isinstance(text, str):
-        # Text is already decoded to unicode, nothing to do...
-        return text
     encodings = ["ascii", "utf8", "latin1", "latin2"]
     for encoding in encodings:
         try:
@@ -70,7 +61,7 @@ class SimpleRpmWrapperWithChangelog(kobo.pkgset.SimpleRpmWrapper):
         ts = kwargs.pop("ts", None)
         header = kobo.rpmlib.get_rpm_header(file_path, ts=ts)
 
-        self.summary = to_utf8(kobo.rpmlib.get_header_field(header, "summary"))
+        self.summary = kobo.rpmlib.get_header_field(header, "summary").decode('utf-8')
 
         if self.sourcerpm:
             key = self.sourcerpm
@@ -384,9 +375,7 @@ class ComposeChangelog(object):
 
             data["changelog"] = []
             for i in get_changelog_diff_from_headers(old_package, new_package, max_logs):
-                data["changelog"].append(
-                    "* %s %s\n%s" % (i.ctime, to_utf8(i.name), to_utf8(i.text))
-                )
+                data["changelog"].append("* %s %s\n%s" % (i.ctime, to_utf8(i.name), to_utf8(i.text)))
 
             # TODO: comps, system release
             # if rpm.versionCompare(old_package, new_package.header) == -1:
diff --git a/tests/test_changelog.py b/tests/test_changelog.py
index 3ee3e1c..82b599a 100644
--- a/tests/test_changelog.py
+++ b/tests/test_changelog.py
@@ -212,7 +212,7 @@ class TestFormat(unittest.TestCase):
         changelog = ComposeChangelog()
         changelog._get_summary = mock.Mock(return_value=[])
         with open(get_fixture('verbose-full.txt')) as f:
-            expected = six.ensure_text(f.read(), encoding="utf-8").splitlines()
+            expected = f.read().splitlines()
         self.maxDiff = None
         self.assertEqual(
             changelog.get_verbose_log(self.data).splitlines(), expected
@@ -222,7 +222,7 @@ class TestFormat(unittest.TestCase):
         changelog = ComposeChangelog()
         changelog._get_summary = mock.Mock(return_value=[])
         with open(get_fixture('verbose-short.txt')) as f:
-            expected = six.ensure_text(f.read(), encoding="utf-8").splitlines()
+            expected = f.read().splitlines()
         self.maxDiff = None
         self.assertEqual(
             changelog.get_verbose_log(self.data, shorten=True).splitlines(), expected
@@ -231,26 +231,26 @@ class TestFormat(unittest.TestCase):
 
 class TestCompareChangelogs(unittest.TestCase):
     def test_select_new(self):
-        c1 = ChangelogEntry('John Doe <jdoe@example.com> 1.0-1', 1000000, 'change 1')
-        c2 = ChangelogEntry('John Doe <jdoe@example.com> 1.1-1', 2000000, 'change 2')
+        c1 = ChangelogEntry(b'John Doe <jdoe@example.com> 1.0-1', 1000000, 'change 1')
+        c2 = ChangelogEntry(b'John Doe <jdoe@example.com> 1.1-1', 2000000, 'change 2')
         old = mock.Mock(changelogs=[c1])
         new = mock.Mock(changelogs=[c2, c1])
         clog = get_changelog_diff_from_headers(old, new)
         self.assertEqual(clog, [c2])
 
     def test_select_with_same_date(self):
-        c1 = ChangelogEntry('John Doe <jdoe@example.com> 1.0-1', 1000000, 'change 1')
-        c2 = ChangelogEntry('John Doe <jdoe@example.com> 1.1-1', 1000000, 'change 2')
+        c1 = ChangelogEntry(b'John Doe <jdoe@example.com> 1.0-1', 1000000, 'change 1')
+        c2 = ChangelogEntry(b'John Doe <jdoe@example.com> 1.1-1', 1000000, 'change 2')
         old = mock.Mock(changelogs=[c1])
         new = mock.Mock(changelogs=[c2, c1])
         clog = get_changelog_diff_from_headers(old, new)
         self.assertEqual(clog, [c2])
 
     def test_no_subset(self):
-        c1 = ChangelogEntry('John Doe <jdoe@example.com> 0:2.0-1', 1000000, 'change 1')
-        c2 = ChangelogEntry('John Doe <jdoe@example.com> 1:1.1-1', 1000000, 'change 2')
-        c3 = ChangelogEntry('John Doe <jdoe@example.com> 1:1.2-1', 1000000, 'change 3')
-        c4 = ChangelogEntry('John Doe <jdoe@example.com> 1:1.3-1', 1000000, 'change 4')
+        c1 = ChangelogEntry(b'John Doe <jdoe@example.com> 0:2.0-1', 1000000, 'change 1')
+        c2 = ChangelogEntry(b'John Doe <jdoe@example.com> 1:1.1-1', 1000000, 'change 2')
+        c3 = ChangelogEntry(b'John Doe <jdoe@example.com> 1:1.2-1', 1000000, 'change 3')
+        c4 = ChangelogEntry(b'John Doe <jdoe@example.com> 1:1.3-1', 1000000, 'change 4')
         old = mock.Mock(changelogs=[c3, c1])
         new = mock.Mock(changelogs=[c4, c2, c1])
         clog = get_changelog_diff_from_headers(old, new)
-- 
2.21.0