There are two bugs:
1) We assume that we can obtain the tty_width() from the
sys.stderr.fileno(), but that's only true if we haven't
ourselves redirected stderr to a pipe, as we do in
run_module_cmd() if fix_stderr is true.
Fix this by adding an (optional, defaulting to stderr)
argument for the file descriptor to tty_width(), and
using that in the places where we're running under the
redirection.
2) A simple typo/oversight meant that if the line was too
long (though due to the first bug assumed 70 chars) the
'width' chars would be removed at the beginning, rather
than actually showing 'width' chars. Fix that too.
These issues manifest themselves in e.g. 'bup save' showing
only the last few characters of the progress line if it was
longer than 70 characters.
Signed-off-by: Johannes Berg <
joha...@sipsolutions.net>
---
lib/bup/main.py | 6 +++---
lib/bup/options.py | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/bup/main.py b/lib/bup/main.py
index 0c21c88f5703..226e463fd029 100755
--- a/lib/bup/main.py
+++ b/lib/bup/main.py
@@ -224,7 +224,7 @@ def print_clean_line(dest, content, width, sep=None):
assert not sep_rx.match(x)
content = b''.join(content)
if sep == b'\r' and len(content) > width:
- content = content[width:]
+ content = content[:width]
os.write(dest, content)
if len(content) < width:
os.write(dest, b' ' * (width - len(content)))
@@ -247,10 +247,10 @@ def filter_output(srcs, dests):
try:
while srcs:
ready_fds, _, _ = select.select(srcs, [], [])
- width = tty_width()
for fd in ready_fds:
buf = os.read(fd, 4096)
dest = dest_for[fd]
+ width = tty_width(dest)
if not buf:
srcs = tuple([x for x in srcs if x is not fd])
print_clean_line(dest, pending.pop(fd, []), width)
@@ -272,7 +272,7 @@ def filter_output(srcs, dests):
# Try to finish each of the streams
for fd, pending_items in compat.items(pending):
dest = dest_for[fd]
- width = tty_width()
+ width = tty_width(dest)
try:
print_clean_line(dest, pending_items, width)
except (EnvironmentError, EOFError) as ex:
diff --git a/lib/bup/options.py b/lib/bup/options.py
index 6f1f162d2b26..cfdc687b74ee 100644
--- a/lib/bup/options.py
+++ b/lib/bup/options.py
@@ -130,16 +130,16 @@ def _intify(v):
if not fcntl and termios:
- def _tty_width():
+ def _tty_width(fd=0):
return 70
else:
- def _tty_width():
+ def _tty_width(fd=sys.stderr.fileno()):
forced = os.environ.get('BUP_TTY_WIDTH', None)
if forced:
return int(forced)
s = struct.pack("HHHH", 0, 0, 0, 0)
try:
- s = fcntl.ioctl(sys.stderr.fileno(), termios.TIOCGWINSZ, s)
+ s = fcntl.ioctl(fd, termios.TIOCGWINSZ, s)
except IOError:
return 70
ysize, xsize, ypix, xpix = struct.unpack('HHHH', s)
--
2.33.1