From 3b3869e931ae38a8d7db596a87fa1e50e63e6e55 Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Mon, 16 May 2011 00:27:20 -0400 Subject: [PATCH] ftp/ls: columnate output attached to a tty, else don't 'bup ftp ls' and 'bup ls' currently behave in a different manner. 'bup ftp ls' always formats its output in columns regardless of whether the program's stdout is a tty or not. 'bup ls' always prints one name on each line. Make both of those commands behave the same. By using lib/bup/helpers' istty1 variable, decide to format in columns when outputting to a tty, and to output one file name per line when the output is not a tty. Signed-off-by: Gabriel Filion --- cmd/ftp-cmd.py | 10 ++++++++-- cmd/ls-cmd.py | 22 ++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/cmd/ftp-cmd.py b/cmd/ftp-cmd.py index 9e4721a..422e168 100755 --- a/cmd/ftp-cmd.py +++ b/cmd/ftp-cmd.py @@ -41,9 +41,15 @@ def do_ls(cmd_args): for sub in n: name = sub.name if opt.all or not len(name)>1 or not name.startswith('.'): - L.append(node_name(name, sub)) + if istty1: + L.append(node_name(name, sub)) + else: + print node_name(name, sub) else: - L.append(node_name(path, n)) + if istty1: + L.append(node_name(path, n)) + else: + print node_name(path, n) sys.stdout.write(columnate(L, '')) diff --git a/cmd/ls-cmd.py b/cmd/ls-cmd.py index 3854a50..2fa6126 100755 --- a/cmd/ls-cmd.py +++ b/cmd/ls-cmd.py @@ -3,16 +3,16 @@ import sys, stat from bup import options, git, vfs from bup.helpers import * -def print_node(text, n): +def node_name(text, n): prefix = '' if opt.hash: prefix += "%s " % n.hash.encode('hex') if stat.S_ISDIR(n.mode): - print '%s%s/' % (prefix, text) + return '%s%s/' % (prefix, text) elif stat.S_ISLNK(n.mode): - print '%s%s@' % (prefix, text) + return '%s%s@' % (prefix, text) else: - print '%s%s' % (prefix, text) + return '%s%s' % (prefix, text) optspec = """ @@ -32,17 +32,27 @@ if not extra: ret = 0 for d in extra: + L = [] try: n = top.lresolve(d) if stat.S_ISDIR(n.mode): for sub in n: if opt.all or not sub.name.startswith('.'): - print_node(sub.name, sub) + if istty1: + L.append(node_name(sub.name, sub)) + else: + print node_name(sub.name, sub) else: if opt.all or not n.name.startswith('.'): - print_node(d, n) + if istty1: + L.append(node_name(d, n)) + else: + print node_name(d, n) except vfs.NodeError, e: log('error: %s\n' % e) ret = 1 +if istty1: + sys.stdout.write(columnate(L, '')) + sys.exit(ret) -- 2.39.2