]> arthur.barton.de Git - bup.git/commitdiff
ftp: implement ls -s (show hashes)
authorGabriel Filion <lelutin@gmail.com>
Mon, 16 May 2011 04:27:21 +0000 (00:27 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 29 May 2011 22:59:14 +0000 (18:59 -0400)
'bup ls' has a -s flag that can be used to show file hashes on the left
of each file name. 'bup ftp ls' doesn't have that feature.

Implement the feature by copying code from 'bup ls'. This is the last
feature difference between 'bup ls' and 'bup ftp ls' and bringing them
to the same level will make it possible to unify the code that is used
by both.

Signed-off-by: Gabriel Filion <lelutin@gmail.com>
cmd/ftp-cmd.py

index 422e168181749cbc247890bc7834c6a085a3b45b..a81f01a089d702f4355db43ad9a555bcb2acbbb1 100755 (executable)
@@ -6,13 +6,16 @@ from bup.helpers import *
 handle_ctrl_c()
 
 
-def node_name(text, n):
+def node_name(opt, text, n):
+    prefix = ''
+    if opt.hash:
+        prefix += "%s " % n.hash.encode('hex')
     if stat.S_ISDIR(n.mode):
-        return '%s/' % text
+        return '%s%s/' % (prefix, text)
     elif stat.S_ISLNK(n.mode):
-        return '%s@' % text
+        return '%s%s@' % (prefix, text)
     else:
-        return '%s' % text
+        return '%s%s' % (prefix, text)
 
 
 class OptionError(Exception):
@@ -22,6 +25,7 @@ class OptionError(Exception):
 ls_optspec = """
 ls [-a] [path...]
 --
+s,hash   show hash for each file
 a,all   include hidden files in the listing
 """
 ls_opt = options.Options(ls_optspec, onabort=OptionError)
@@ -42,14 +46,14 @@ def do_ls(cmd_args):
                 name = sub.name
                 if opt.all or not len(name)>1 or not name.startswith('.'):
                     if istty1:
-                        L.append(node_name(name, sub))
+                        L.append(node_name(opt, name, sub))
                     else:
-                        print node_name(name, sub)
+                        print node_name(opt, name, sub)
         else:
             if istty1:
-                L.append(node_name(path, n))
+                L.append(node_name(opt, path, n))
             else:
-                print node_name(path, n)
+                print node_name(opt, path, n)
         sys.stdout.write(columnate(L, ''))