From 7ba2fb47d05b608f3863fda9271894e38b43937a Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Wed, 29 Mar 2017 12:29:46 +0100 Subject: [jars] fix maven_id dictionary encoding The dictionary must contain string types, not byte arrays. Causes an exception when packing strings with Python3: [sos.sosreport:setup] executing 'sosreport -vvv --batch --debug -o jars' Setting up plugins ... Traceback (most recent call last): File "./sosreport", line 25, in main(sys.argv[1:]) File "/home/breeves/src/git/sos/sos/sosreport.py", line 1632, in main sos.execute() TypeError: key b'version' is not a string Resolves: #984. Signed-off-by: Bryn M. Reeves --- sos/plugins/__init__.py | 12 ++++++++++-- sos/plugins/jars.py | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 46f9cb83..5286e4b5 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -671,7 +671,11 @@ class Plugin(object): def add_string_as_file(self, content, filename): """Add a string to the archive as a file named `filename`""" self.copy_strings.append((content, filename)) - content = "..." + (content.splitlines()[0]).decode('utf8', 'ignore') + if isinstance(content, six.string_types): + content = "..." + content.splitlines()[0] + else: + content = ("..." + + (content.splitlines()[0]).decode('utf8', 'ignore')) self._log_debug("added string '%s' as '%s'" % (content, filename)) def get_cmd_output_now(self, exe, suggest_filename=None, @@ -824,7 +828,11 @@ class Plugin(object): def _collect_strings(self): for string, file_name in self.copy_strings: content = "..." - content += (string.splitlines()[0]).decode('utf8', 'ignore') + if isinstance(string, six.string_types): + content = "..." + content.splitlines()[0] + else: + content = ("..." + + (content.splitlines()[0]).decode('utf8', 'ignore')) self._log_info("collecting string '%s' as '%s'" % (content, file_name)) try: diff --git a/sos/plugins/jars.py b/sos/plugins/jars.py index fd879139..6c15eff3 100644 --- a/sos/plugins/jars.py +++ b/sos/plugins/jars.py @@ -113,7 +113,9 @@ class Jars(Plugin, RedHatPlugin): if not line.startswith(b"#"): try: (key, value) = line.split(b"=") - props[key.strip()] = value.strip() + key = key.decode('utf8').strip() + value = value.decode('utf8').strip() + props[key] = value except ValueError: return None except IOError: -- cgit