from bup import options, git, shquote, vfs
from bup.helpers import *
-def print_node(text, n):
+def node_name(text, n):
if stat.S_ISDIR(n.mode):
- print '%s/' % text
+ return '%s/' % text
elif stat.S_ISLNK(n.mode):
- print '%s@' % text
+ return '%s@' % text
else:
- print '%s' % text
+ return '%s' % text
def do_ls(path, n):
+ l = []
if stat.S_ISDIR(n.mode):
for sub in n:
- print_node(sub.name, sub)
+ l.append(node_name(sub.name, sub))
else:
- print_node(path, n)
-
+ l.append(node_name(path, n))
+ print columnate(l, '')
+
def write_to_file(inf, outf):
for blob in chunkyreader(inf):
sys.excepthook = newhook
+def columnate(l, prefix):
+ l = l[:]
+ clen = max(len(s) for s in l)
+ ncols = (78 - len(prefix)) / (clen + 2)
+ if ncols <= 1:
+ ncols = 1
+ clen = 0
+ cols = []
+ while len(l) % ncols:
+ l.append('')
+ rows = len(l)/ncols
+ for s in range(0, len(l), rows):
+ cols.append(l[s:s+rows])
+ out = ''
+ for row in zip(*cols):
+ out += prefix + ''.join(('%-*s' % (clen+2, s)) for s in row) + '\n'
+ return out
+
+
# hashlib is only available in python 2.5 or higher, but the 'sha' module
# produces a DeprecationWarning in python 2.6 or higher. We want to support
# python 2.4 and above without any stupid warnings, so let's try using hashlib
from bup.helpers import *
-def columnate(l, prefix):
- l = l[:]
- clen = max(len(s) for s in l)
- ncols = (78 - len(prefix)) / (clen + 2)
- if ncols <= 1:
- ncols = 1
- clen = 0
- cols = []
- while len(l) % ncols:
- l.append('')
- rows = len(l)/ncols
- for s in range(0, len(l), rows):
- cols.append(l[s:s+rows])
- out = ''
- for row in zip(*cols):
- out += prefix + ''.join(('%-*s' % (clen+2, s)) for s in row) + '\n'
- return out
-
-
def usage():
log('Usage: bup [-?|--help] [-d=BUP_DIR|--bup-dir=BUP_DIR] COMMAND [ARGS]'
+ '\n\n')