"""
# end of bup preamble
-from __future__ import absolute_import
+from __future__ import absolute_import, print_function
import errno, re, sys, os, subprocess, signal, getopt
+if sys.version_info[0] != 2 \
+ and not os.environ.get('BUP_ALLOW_UNEXPECTED_PYTHON_VERSION') == 'true':
+ print('error: bup may crash with python versions other than 2, or eat your data',
+ file=sys.stderr)
+ sys.exit(2)
+
from subprocess import PIPE
from sys import stderr, stdout
import select
from bup import compat, helpers
-from bup.compat import add_ex_tb, chain_ex, wrap_main
+from bup.compat import add_ex_tb, add_ex_ctx, wrap_main
from bup.helpers import atoi, columnate, debug1, log, tty_width
os.environ['BUP_FORCE_TTY'] = str(amt)
-sep_rx = re.compile(r'([\r\n])')
+sep_rx = re.compile(br'([\r\n])')
def print_clean_line(dest, content, width, sep=None):
"""Write some or all of content, followed by sep, to the dest fd after
terminal width or truncating it to the terminal width if sep is a
carriage return."""
global sep_rx
- assert sep in ('\r', '\n', None)
+ assert sep in (b'\r', b'\n', None)
if not content:
if sep:
os.write(dest, sep)
return
for x in content:
assert not sep_rx.match(x)
- content = ''.join(content)
- if sep == '\r' and len(content) > width:
+ content = b''.join(content)
+ if sep == b'\r' and len(content) > width:
content = content[width:]
os.write(dest, content)
if len(content) < width:
- os.write(dest, ' ' * (width - len(content)))
+ os.write(dest, b' ' * (width - len(content)))
if sep:
os.write(dest, sep)
print_clean_line(dest, pending.pop(fd, []), width)
else:
split = sep_rx.split(buf)
- if len(split) > 2:
- while len(split) > 1:
- content, sep = split[:2]
- split = split[2:]
- print_clean_line(dest,
- pending.pop(fd, []) + [content],
- width,
- sep)
- else:
- assert(len(split) == 1)
+ while len(split) > 1:
+ content, sep = split[:2]
+ split = split[2:]
+ print_clean_line(dest,
+ pending.pop(fd, []) + [content],
+ width,
+ sep)
+ assert(len(split) == 1)
+ if split[0]:
pending.setdefault(fd, []).extend(split)
except BaseException as ex:
- pending_ex = chain_ex(add_ex_tb(ex), pending_ex)
+ pending_ex = add_ex_ctx(add_ex_tb(ex), pending_ex)
try:
# Try to finish each of the streams
for fd, pending_items in compat.items(pending):
try:
print_clean_line(dest, pending_items, width)
except (EnvironmentError, EOFError) as ex:
- pending_ex = chain_ex(add_ex_tb(ex), pending_ex)
+ pending_ex = add_ex_ctx(add_ex_tb(ex), pending_ex)
except BaseException as ex:
- pending_ex = chain_ex(add_ex_tb(ex), pending_ex)
+ pending_ex = add_ex_ctx(add_ex_tb(ex), pending_ex)
if pending_ex:
raise pending_ex
os.kill(p.pid, signal.SIGTERM)
p.wait()
except BaseException as kill_ex:
- raise chain_ex(add_ex_tb(kill_ex), ex)
+ raise add_ex_ctx(add_ex_tb(kill_ex), ex)
raise ex
wrap_main(lambda : run_subcmd(subcmd))