Skip to content

Commit

Permalink
cmd/ftp: Hide .dotfiles by default (-a shows them)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Gabriel Filion authored and apenwarr committed Jul 27, 2010
1 parent 9a31a8c commit bfec086
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions cmd/ftp-cmd.py
Expand Up @@ -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()):
Expand Down Expand Up @@ -153,8 +175,7 @@ def completer(text, state):
#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:]:
Expand Down

0 comments on commit bfec086

Please sign in to comment.