]> arthur.barton.de Git - bup.git/commitdiff
cmd/ftp: Hide .dotfiles by default (-a shows them)
authorGabriel Filion <lelutin@gmail.com>
Tue, 27 Jul 2010 03:52:34 +0000 (23:52 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Tue, 27 Jul 2010 07:49:37 +0000 (03:49 -0400)
Normally in FTP sites, files beginning with a dot are hidden from a list
(ls) command by default. Also, using the argument '-a' makes the list
show hidden files.

The current 'bup ftp' implementation does not behave so. Make it hide
hidden files by default, as expected, and show hidden files when '-a' or
'--all' is specified to the 'ls' command.

All unknown switches will make bup ftp show the ls command usage.

Users can also give 'ls --help' to obtain the usage string.

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

index 6c9a9992ab7ea8e224b555298cf3136330b364cc..253b7acffc20c553f1e9ddb24e77481b87295810 100755 (executable)
@@ -12,20 +12,42 @@ def node_name(text, n):
         return '%s' % text
 
 
-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
+
+
+ls_optspec = """
+ls [-a] [path...]
+--
+a,all   include hidden files in the listing
+"""
+ls_opt = options.Options('ls', ls_optspec, onabort=OptionError)
+
+def do_ls(cmd_args):
+    try:
+        (opt, flags, extra) = ls_opt.parse(cmd_args)
+    except OptionError, 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):
         outf.write(blob)
-    
+
 
 def inputiter():
     if os.isatty(sys.stdin.fileno()):
@@ -153,8 +175,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:]: