"""
# end of bup preamble
-from __future__ import absolute_import
+from __future__ import absolute_import, print_function
import sys, os, stat, fnmatch
from bup import options, git, shquote, ls, vfs
+from bup.io import byte_stream
from bup.helpers import chunkyreader, handle_ctrl_c, log
from bup.repo import LocalRepo
pass
-def do_ls(repo, args):
+def do_ls(repo, args, out):
try:
opt = ls.opts_from_cmdline(args, onabort=OptionError)
except OptionError as e:
log('error: %s' % e)
return
- return ls.within_repo(repo, opt)
+ return ls.within_repo(repo, opt, out)
def write_to_file(inf, outf):
try:
yield raw_input('bup> ')
except EOFError:
- print '' # Clear the line for the terminal's next prompt
+ print() # Clear the line for the terminal's next prompt
break
else:
for line in sys.stdin:
return dir, name, qtype, lastword, subs
-def find_readline_lib():
- """Return the name (and possibly the full path) of the readline library
- linked to the given readline module.
- """
- import readline
- f = open(readline.__file__, "rb")
- try:
- data = f.read()
- finally:
- f.close()
- import re
- m = re.search('\0([^\0]*libreadline[^\0]*)\0', data)
- if m:
- return m.group(1)
- return None
-
-
-def init_readline_vars():
- """Work around trailing space automatically inserted by readline.
- See http://bugs.python.org/issue5833"""
- try:
- import ctypes
- except ImportError:
- # python before 2.5 didn't have the ctypes module; but those
- # old systems probably also didn't have this readline bug, so
- # just ignore it.
- return
- lib_name = find_readline_lib()
- if lib_name is not None:
- lib = ctypes.cdll.LoadLibrary(lib_name)
- global rl_completion_suppress_append
- rl_completion_suppress_append = ctypes.c_int.in_dll(lib,
- "rl_completion_suppress_append")
-
-
-rl_completion_suppress_append = None
_last_line = None
_last_res = None
def completer(text, iteration):
global repo
global _last_line
global _last_res
- global rl_completion_suppress_append
- if rl_completion_suppress_append is not None:
- rl_completion_suppress_append.value = 1
try:
line = readline.get_line_buffer()[:readline.get_endidx()]
if _last_line != line:
git.check_repo_or_die()
+sys.stdout.flush()
+out = byte_stream(sys.stdout)
repo = LocalRepo()
pwd = vfs.resolve(repo, '/')
rv = 0
# MacOS uses a slightly incompatible clone of libreadline
readline.parse_and_bind('bind ^I rl_complete')
readline.parse_and_bind('tab: complete')
- init_readline_vars()
lines = inputiter()
for line in lines:
try:
if cmd == 'ls':
# FIXME: respect pwd (perhaps via ls accepting resolve path/parent)
- do_ls(repo, words[1:])
+ sys.stdout.flush() # FIXME: remove when we finish py3 support
+ do_ls(repo, words[1:], out)
elif cmd == 'cd':
np = pwd
for parm in words[1:]:
elif cmd == 'pwd':
if len(pwd) == 1:
sys.stdout.write('/')
- print '/'.join(name for name, item in pwd)
+ print('/'.join(name for name, item in pwd))
elif cmd == 'cat':
for parm in words[1:]:
res = vfs.resolve(repo, parm, parent=pwd)