]> arthur.barton.de Git - bup.git/blobdiff - cmd/ftp-cmd.py
Restore any metadata during "bup restore"; add "bup meta --edit".
[bup.git] / cmd / ftp-cmd.py
index 0635f0769804b522a6210be744204f9defc41d1e..6c40dc37bc3bc87e52449d8fb21dcbfa74bf933d 100755 (executable)
@@ -1,31 +1,27 @@
 #!/usr/bin/env python
-import sys, os, re, stat, fnmatch
-from bup import options, git, shquote, vfs
+import sys, os, stat, fnmatch
+from bup import options, git, shquote, vfs, ls
 from bup.helpers import *
 
-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()
 
 
-def do_ls(path, n):
-    l = []
-    if stat.S_ISDIR(n.mode):
-        for sub in n:
-            l.append(node_name(sub.name, sub))
-    else:
-        l.append(node_name(path, n))
-    print columnate(l, '')
-    
+class OptionError(Exception):
+    pass
+
+
+# Check out lib/bup/ls.py for the opt spec
+def do_ls(cmd_args):
+    try:
+        ls.do_ls(cmd_args, pwd, onabort=OptionError)
+    except OptionError, e:
+        return
+
 
 def write_to_file(inf, outf):
     for blob in chunkyreader(inf):
         outf.write(blob)
-    
+
 
 def inputiter():
     if os.isatty(sys.stdin.fileno()):
@@ -33,6 +29,7 @@ def inputiter():
             try:
                 yield raw_input('bup> ')
             except EOFError:
+                print ''  # Clear the line for the terminal's next prompt
                 break
     else:
         for line in sys.stdin:
@@ -43,9 +40,12 @@ def _completer_get_subs(line):
     (qtype, lastword) = shquote.unfinished_word(line)
     (dir,name) = os.path.split(lastword)
     #log('\ncompleter: %r %r %r\n' % (qtype, lastword, text))
-    n = pwd.resolve(dir)
-    subs = list(filter(lambda x: x.name.startswith(name),
-                       n.subs()))
+    try:
+        n = pwd.resolve(dir)
+        subs = list(filter(lambda x: x.name.startswith(name),
+                           n.subs()))
+    except vfs.NoSuchFile, e:
+        subs = []
     return (dir, name, qtype, lastword, subs)
 
 
@@ -69,7 +69,13 @@ def find_readline_lib():
 def init_readline_vars():
     """Work around trailing space automatically inserted by readline.
     See http://bugs.python.org/issue5833"""
-    import ctypes
+    try:
+        import ctypes
+    except ImportError:
+        # python before 2.5 didn't have the ctypes module; but those
+        # old systems probably also didn't have this readline bug, so
+        # just ignore it.
+        return
     lib_name = find_readline_lib()
     if lib_name is not None:
         lib = ctypes.cdll.LoadLibrary(lib_name)
@@ -105,20 +111,19 @@ def completer(text, state):
                                           terminate=True) + ' '
             return text + ret
     except Exception, e:
-        if 0:
-            log('\n')
-            try:
-                import traceback
-                traceback.print_tb(sys.exc_traceback)
-            except Exception, e2:
-                log('Error printing traceback: %s\n' % e2)
+        log('\n')
+        try:
+            import traceback
+            traceback.print_tb(sys.exc_traceback)
+        except Exception, e2:
+            log('Error printing traceback: %s\n' % e2)
         log('\nError in completion: %s\n' % e)
 
 
 optspec = """
 bup ftp [commands...]
 """
-o = options.Options('bup ftp', optspec)
+o = options.Options(optspec)
 (opt, flags, extra) = o.parse(sys.argv[1:])
 
 git.check_repo_or_die()
@@ -139,7 +144,10 @@ else:
     if readline:
         readline.set_completer_delims(' \t\n\r/')
         readline.set_completer(completer)
-        readline.parse_and_bind("tab: complete")
+        if platform.system() == '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()
 
@@ -151,8 +159,7 @@ for line in lines:
     #log('execute: %r %r\n' % (cmd, parm))
     try:
         if cmd == 'ls':
-            for parm in (words[1:] or ['.']):
-                do_ls(parm, pwd.try_resolve(parm))
+            do_ls(words[1:])
         elif cmd == 'cd':
             np = pwd
             for parm in words[1:]: