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):
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)
global _attempt_start, _attempt_end
_attempt_start = start
_attempt_end = end
- return None
_last_line = None
_last_res = None
except Exception as e2:
log('Error printing traceback: %s\n' % e2)
log('\nError in completion: %s\n' % e)
+ return None
optspec = """
git.check_repo_or_die()
+ global repo
+
sys.stdout.flush()
out = byte_stream(sys.stdout)
stdin = byte_stream(sys.stdin)
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:
#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
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'):