Replace invlid output before logging it
This commit is contained in:
parent
7f3fc3be79
commit
d293404cd0
|
@ -9,6 +9,8 @@
|
||||||
Closes: GH bug #28
|
Closes: GH bug #28
|
||||||
* Updated PyPI trove classifiers to include Python 3
|
* Updated PyPI trove classifiers to include Python 3
|
||||||
Closes: GH bug #25
|
Closes: GH bug #25
|
||||||
|
* Escape output messages before logging them.
|
||||||
|
Closes: GH bug #29
|
||||||
|
|
||||||
|
|
||||||
1.8 (released 19.7.2015)
|
1.8 (released 19.7.2015)
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import codecs
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
@ -492,6 +493,14 @@ def get_single_outfile (directory, archive, extension=""):
|
||||||
return outfile + extension
|
return outfile + extension
|
||||||
|
|
||||||
|
|
||||||
|
def init_log():
|
||||||
|
"""Wrap sys.stdout and sys.stderr in encoding-aware stream writers."""
|
||||||
|
encoding = locale.getpreferredencoding()
|
||||||
|
errors = 'backslashreplace'
|
||||||
|
sys.stdout = codecs.getwriter(encoding)(sys.stdout, errors)
|
||||||
|
sys.stderr = codecs.getwriter(encoding)(sys.stderr, errors)
|
||||||
|
|
||||||
|
|
||||||
def log_error (msg, out=sys.stderr):
|
def log_error (msg, out=sys.stderr):
|
||||||
"""Print error message to stderr (or any other given output)."""
|
"""Print error message to stderr (or any other given output)."""
|
||||||
print("patool error:", msg, file=out)
|
print("patool error:", msg, file=out)
|
||||||
|
@ -686,4 +695,5 @@ def chdir(directory):
|
||||||
return olddir
|
return olddir
|
||||||
|
|
||||||
|
|
||||||
|
init_log()
|
||||||
init_mimedb()
|
init_mimedb()
|
||||||
|
|
Loading…
Reference in New Issue