]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/cmd/ftp.py
pylint: enable inconsistent-return-statements
[bup.git] / lib / bup / cmd / ftp.py
index bed1b9af21159da0ba968685f122d83edf3eb15a..99121f0dc76d539fac313d085362b508a2dc22f1 100755 (executable)
@@ -8,23 +8,26 @@ from __future__ import absolute_import, print_function
 import os, fnmatch, stat, sys
 
 from bup import _helpers, options, git, shquote, ls, vfs
-from bup.compat import argv_bytes, fsdecode
-from bup.helpers import chunkyreader, handle_ctrl_c, log
+from bup.compat import argv_bytes
+from bup.helpers import chunkyreader, log
 from bup.io import byte_stream, path_msg
 from bup.repo import LocalRepo
 
 
+repo = None
+
 class OptionError(Exception):
     pass
 
 
-def do_ls(repo, args, out):
+def do_ls(repo, pwd, args, out):
+    pwd_str = b'/'.join(name for name, item in pwd) or b'/'
     try:
-        opt = ls.opts_from_cmdline(args, onabort=OptionError)
+        opt = ls.opts_from_cmdline(args, onabort=OptionError, pwd=pwd_str)
     except OptionError as e:
         log('error: %s' % e)
-        return
-    return ls.within_repo(repo, opt, out)
+        return None
+    return ls.within_repo(repo, opt, out, pwd_str)
 
 
 def write_to_file(inf, outf):
@@ -32,28 +35,6 @@ def write_to_file(inf, outf):
         outf.write(blob)
 
 
-def inputiter(f):
-    if os.isatty(f.fileno()):
-        while 1:
-            if hasattr(_helpers, 'readline'):
-                try:
-                    yield _helpers.readline(b'bup> ')
-                except EOFError:
-                    print()  # Clear the line for the terminal's next prompt
-                    break
-            else:
-                out.write(b'bup> ')
-                out.flush()
-                read_line = f.readline()
-                if not read_line:
-                    print('')
-                    break
-                yield read_line
-    else:
-        for line in f:
-            yield line
-
-
 def _completer_get_subs(repo, line):
     (qtype, lastword) = shquote.unfinished_word(line)
     dir, name = os.path.split(lastword)
@@ -74,7 +55,6 @@ def attempt_completion(text, start, end):
     global _attempt_start, _attempt_end
     _attempt_start = start
     _attempt_end = end
-    return None
 
 _last_line = None
 _last_res = None
@@ -110,6 +90,7 @@ def enter_completion(text, iteration):
         except Exception as e2:
             log('Error printing traceback: %s\n' % e2)
         log('\nError in completion: %s\n' % e)
+    return None
 
 
 optspec = """
@@ -122,6 +103,8 @@ def main(argv):
 
     git.check_repo_or_die()
 
+    global repo
+
     sys.stdout.flush()
     out = byte_stream(sys.stdout)
     stdin = byte_stream(sys.stdin)
@@ -129,6 +112,29 @@ def main(argv):
     pwd = vfs.resolve(repo, b'/')
     rv = 0
 
+    def inputiter(f):
+        if os.isatty(f.fileno()):
+            while 1:
+                prompt = b'bup %s> ' % (b'/'.join(name for name, item in pwd) or b'/', )
+                if hasattr(_helpers, 'readline'):
+                    try:
+                        yield _helpers.readline(prompt)
+                    except EOFError:
+                        print()  # Clear the line for the terminal's next prompt
+                        break
+                else:
+                    out.write(prompt)
+                    out.flush()
+                    read_line = f.readline()
+                    if not read_line:
+                        print('')
+                        break
+                    yield read_line
+        else:
+            for line in f:
+                yield line
+
+
     if extra:
         lines = (argv_bytes(arg) for arg in extra)
     else:
@@ -150,8 +156,7 @@ def main(argv):
         #log('execute: %r %r\n' % (cmd, parm))
         try:
             if cmd == b'ls':
-                # FIXME: respect pwd (perhaps via ls accepting resolve path/parent)
-                do_ls(repo, words[1:], out)
+                do_ls(repo, pwd, words[1:], out)
                 out.flush()
             elif cmd == b'cd':
                 np = pwd
@@ -222,7 +227,7 @@ def main(argv):
                                 with open(name, 'wb') as destfile:
                                     log('Saving %s\n' % path_msg(name))
                                     write_to_file(srcfile, destfile)
-            elif cmd == b'help' or cmd == b'?':
+            elif cmd in (b'help', b'?'):
                 out.write(b'Commands: ls cd pwd cat get mget help quit\n')
                 out.flush()
             elif cmd in (b'quit', b'exit', b'bye'):