-#!/usr/bin/env python
+#!/bin/sh
+"""": # -*-python-*-
+bup_python="$(dirname "$0")/bup-python" || exit $?
+exec "$bup_python" "$0" ${1+"$@"}
+"""
+# end of bup preamble
+
import sys, os, stat, fnmatch
-from bup import options, git, shquote, vfs
-from bup.helpers import *
-handle_ctrl_c()
+from bup import options, git, shquote, vfs, ls
+from bup.helpers import chunkyreader, handle_ctrl_c, log
-def node_name(text, n):
- if stat.S_ISDIR(n.mode):
- return '%s/' % text
- elif stat.S_ISLNK(n.mode):
- return '%s@' % text
- else:
- return '%s' % text
+handle_ctrl_c()
class OptionError(Exception):
pass
-ls_optspec = """
-ls [-a] [path...]
---
-a,all include hidden files in the listing
-"""
-ls_opt = options.Options(ls_optspec, onabort=OptionError)
-
+# Check out lib/bup/ls.py for the opt spec
def do_ls(cmd_args):
try:
- (opt, flags, extra) = ls_opt.parse(cmd_args)
- except OptionError, e:
+ ls.do_ls(cmd_args, pwd, onabort=OptionError)
+ except OptionError as e:
return
- L = []
-
- for path in (extra or ['.']):
- n = pwd.try_resolve(path)
-
- if stat.S_ISDIR(n.mode):
- 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))
- else:
- L.append(node_name(path, n))
- sys.stdout.write(columnate(L, ''))
-
def write_to_file(inf, outf):
for blob in chunkyreader(inf):
n = pwd.resolve(dir)
subs = list(filter(lambda x: x.name.startswith(name),
n.subs()))
- except vfs.NoSuchFile, e:
+ except vfs.NoSuchFile as e:
subs = []
return (dir, name, qtype, lastword, subs)
ret = shquote.what_to_add(qtype, lastword, fullname,
terminate=True) + ' '
return text + ret
- except Exception, e:
+ except Exception as e:
log('\n')
try:
import traceback
traceback.print_tb(sys.exc_traceback)
- except Exception, e2:
+ except Exception as e2:
log('Error printing traceback: %s\n' % e2)
log('\nError in completion: %s\n' % e)
if readline:
readline.set_completer_delims(' \t\n\r/')
readline.set_completer(completer)
- readline.parse_and_bind("tab: complete")
+ if sys.platform.startswith('darwin'):
+ # MacOS uses a slighly incompatible clone of libreadline
+ readline.parse_and_bind('bind ^I rl_complete')
+ readline.parse_and_bind('tab: complete')
init_readline_vars()
lines = inputiter()
outf = open(n.name, 'wb')
write_to_file(inf, outf)
outf.close()
- except Exception, e:
+ except Exception as e:
rv = 1
log(' error: %s\n' % e)
elif cmd == 'help' or cmd == '?':
else:
rv = 1
raise Exception('no such command %r' % cmd)
- except Exception, e:
+ except Exception as e:
rv = 1
log('error: %s\n' % e)
#raise