Add path_msg(p) and use it in cmd/bup (as a start). The intent is to
centralize the encoding of all path values that are to be included in
strings intended for "display" (e.g. stderr, which appears to have to
be a text stream in python 3).
For now, the function will do nothing -- i.e. given the currently
enforced iso-8859-1 encoding we'll just continue to produce the
original path bytes on stderr, but we may well want to make this
configurable at some point (perhaps git's quotePath algorithm might
provide a likely option), and if nothing else, using path_msg()
everywhere makes it much easier to identify and adapt the relevant
code, whatever we decide.
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
from subprocess import PIPE
from bup.compat import environ, restore_lc_env
+from bup.io import path_msg
if sys.version_info[0] != 2 \
and not environ.get(b'BUP_ALLOW_UNEXPECTED_PYTHON_VERSION') == b'true':
subcmd[0] = subpath(subcmd_name)
if not os.path.exists(subcmd[0]):
- usage('error: unknown command "%s"' % subcmd_name)
+ usage('error: unknown command "%s"' % path_msg(subcmd_name))
already_fixed = atoi(os.environ.get('BUP_FORCE_TTY'))
if subcmd_name in ['mux', 'ftp', 'help']:
else:
def byte_stream(file):
return file
+
+
+def path_msg(x):
+ """Return a string representation of a path.
+
+ For now, assume that the destination encoding is going to be
+ ISO-8859-1, which it should be, for the primary current
+ destination, stderr, given the current bup-python.
+
+ """
+ # FIXME: configurability (might git-config quotePath be involved?)
+ return x.decode(encoding='iso-8859-1')