Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[reporting] html_report skips plugins that collected file with nonASCII character in their name #835

Closed
pmoravec opened this issue Jun 11, 2016 · 2 comments

Comments

@pmoravec
Copy link
Contributor

Trivial reproducer:

  1. comment out plain report exception due to [reporting] deal with UTF-8 characters #722 by having sos/reporting.py:150 :
    return "\n" #.join(buf)
  1. have a file with non-ASCII chars collected by some plugin:
touch /etc/network_přílišžluťoučkýkůňpělódy
sosreport -o networking --batch
cat $(tar xvJf $(ls -tr /var/tmp/sosreport-*xz | tail -n1) | grep sos_reports/sos.html)

(sos.html is almost empty, no networking plugin section there)

  1. Remove /etc/network_přílišžluťoučkýkůňpělódy, run sosreport again and compare sos.html
@pmoravec pmoravec changed the title [reporting] html_report skips plugins that collected file with nonASCII character [reporting] html_report skips plugins that collected file with nonASCII character in their name Jun 11, 2016
@pmoravec
Copy link
Contributor Author

I already tried to fix this by:

diff -rup a/sos/plugins/__init__.py b/sos/plugins/__init__.py
--- a/sos/plugins/__init__.py       2016-06-03 18:02:25.000000000 +0200
+++ b/sos/plugins/__init__.py       2016-06-11 12:45:25.551135501 +0200
@@ -304,8 +304,8 @@ class Plugin(object):
             self._log_debug("link '%s' points to itself, skipping target..."
                             % linkdest)

-        self.copied_files.append({'srcpath': srcpath,
-                                  'dstpath': dstpath,
+        self.copied_files.append({'srcpath': srcpath.decode('utf-8'),
+                                  'dstpath': dstpath.decode('utf-8'),
                                   'symlink': "yes",
                                   'pointsto': linkdest})

@@ -390,8 +390,8 @@ class Plugin(object):
             self.archive.add_file(srcpath, dest)

         self.copied_files.append({
-            'srcpath': srcpath,
-            'dstpath': dest,
+            'srcpath': srcpath.decode('utf-8'),
+            'dstpath': dest.decode('utf-8'),
             'symlink': "no"
         })

that fixed some str->unicode issues, but now I get:

./sosreport -o networking --batch --debug
..
Traceback (most recent call last):
  File "./sosreport", line 25, in <module>
    main(sys.argv[1:])
  File "/root/sos/sos-master-new/sos/sosreport.py", line 1636, in main
    sos.execute()
UnicodeEncodeError: 'ascii' codec can't encode characters in position 122-123: ordinal not in range(128)

> /root/sos/sos-master-new/sos/sosreport.py(1437)_html_report()
-> rfd.write(html)

But rfd is regular file and writing unicode after str should work well:

>>> fd, fname = tempfile.mkstemp(dir='/tmp')
>>> fobj = open(fname, 'w')
>>> fobj.write("aaa")
>>> fobj.write("ř")
>>> fobj.close()

(no exception raised)

@pmoravec
Copy link
Contributor Author

Trivial enhancement:

rfd.write(html.encode('utf-8'))

that breaks tests :(

pmoravec added a commit to pmoravec/sos that referenced this issue Jun 19, 2016
[reporting] html_report skips plugins that collected file with
nonASCII character in their name

Converting all html report strings to unicode with utf-8 encoding.

Does not work ideally on py2 where the report does not skip a plugin
but breaks encoding of most nonASCII characters.

Resolves: sosreport#835

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
TurboTurtle pushed a commit to TurboTurtle/sos that referenced this issue Jul 13, 2016
[reporting] html_report skips plugins that collected file with
nonASCII character in their name

Converting all html report strings to unicode with utf-8 encoding.

Does not work ideally on py2 where the report does not skip a plugin
but breaks encoding of most nonASCII characters.

Resolves: sosreport#835

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
TurboTurtle pushed a commit to TurboTurtle/sos that referenced this issue Jul 13, 2016
[reporting] html_report skips plugins that collected file with
nonASCII character in their name

Converting all html report strings to unicode with utf-8 encoding.

Does not work ideally on py2 where the report does not skip a plugin
but breaks encoding of most nonASCII characters.

Resolves: sosreport#835

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
poornimakshirsagar pushed a commit to poornimakshirsagar/sos that referenced this issue Jan 5, 2017
[reporting] html_report skips plugins that collected file with
nonASCII character in their name

Converting all html report strings to unicode with utf-8 encoding.

Does not work ideally on py2 where the report does not skip a plugin
but breaks encoding of most nonASCII characters.

Resolves: sosreport#835

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
karibou pushed a commit to karibou/sosreport that referenced this issue Nov 16, 2017
[reporting] html_report skips plugins that collected file with
nonASCII character in their name

Converting all html report strings to unicode with utf-8 encoding.

Does not work ideally on py2 where the report does not skip a plugin
but breaks encoding of most nonASCII characters.

Resolves: sosreport#835

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant