]> arthur.barton.de Git - bup.git/blobdiff - cmd/ftp-cmd.py
rev_list: support custom formats
[bup.git] / cmd / ftp-cmd.py
index d63a7106f55a8a8b75ecdcda869c27e0e9eef91b..44fe68ca58142a5b1abadbd9880527334f796353 100755 (executable)
@@ -1,51 +1,30 @@
-#!/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))
-        print columnate(L, '')
-
 
 def write_to_file(inf, outf):
     for blob in chunkyreader(inf):
@@ -58,6 +37,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:
@@ -72,7 +52,7 @@ def _completer_get_subs(line):
         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)
 
@@ -138,12 +118,12 @@ def completer(text, state):
                 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)
 
@@ -172,7 +152,10 @@ else:
     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()
 
@@ -218,7 +201,7 @@ for line in lines:
                             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 == '?':
@@ -228,7 +211,7 @@ for line in lines:
         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