1 """Common code for listing files from a bup repository."""
3 from bup import options, vfs
7 def node_name(text, n, show_hash):
8 """Add symbols to a node's name to differentiate file types."""
11 prefix += "%s " % n.hash.encode('hex')
12 if stat.S_ISDIR(n.mode):
13 return '%s%s/' % (prefix, text)
14 elif stat.S_ISLNK(n.mode):
15 return '%s%s@' % (prefix, text)
17 return '%s%s' % (prefix, text)
23 s,hash show hash for each file
24 a,all show hidden files
27 def do_ls(args, pwd, default='.', onabort=None, spec_prefix=''):
28 """Output a listing of a file or directory in the bup repository.
30 When stdout is attached to a tty, the output is formatted in columns. When
31 not attached to tty (for example when the output is piped to another
32 command), one file is listed per line.
35 o = options.Options(optspec % spec_prefix, onabort=onabort)
37 o = options.Options(optspec % spec_prefix)
38 (opt, flags, extra) = o.parse(args)
43 for path in (extra or [default]):
45 n = pwd.try_resolve(path)
47 if stat.S_ISDIR(n.mode):
50 if opt.all or not len(name)>1 or not name.startswith('.'):
52 L.append(node_name(name, sub, opt.hash))
54 print node_name(name, sub, opt.hash)
57 L.append(node_name(path, n, opt.hash))
59 print node_name(path, n, opt.hash)
60 except vfs.NodeError, e:
61 log('error: %s\n' % e)
65 sys.stdout.write(columnate(L, ''))