From 4f7e4dfcdc5b12efb809a2cafcfff6fbd7e569a0 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Thu, 26 Dec 2019 12:27:07 -0600 Subject: [PATCH] Add "do nothing" path_msg to centralize path conversions 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 Tested-by: Rob Browning --- cmd/bup | 3 ++- lib/bup/io.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/bup b/cmd/bup index e8462df..f696449 100755 --- a/cmd/bup +++ b/cmd/bup @@ -20,6 +20,7 @@ import errno, getopt, os, re, select, signal, subprocess, sys 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': @@ -127,7 +128,7 @@ def subpath(s): 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']: diff --git a/lib/bup/io.py b/lib/bup/io.py index 6f4cca7..571e9b9 100644 --- a/lib/bup/io.py +++ b/lib/bup/io.py @@ -10,3 +10,15 @@ if compat.py_maj > 2: 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') -- 2.39.2