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
fix_stdout = not already_fixed and os.isatty(1)
fix_stderr = not already_fixed and os.isatty(2)
-def force_tty():
- if fix_stdout or fix_stderr:
- amt = (fix_stdout and 1 or 0) + (fix_stderr and 2 or 0)
- os.environ['BUP_FORCE_TTY'] = str(amt)
+if fix_stdout or fix_stderr:
+ tty_env = merge_dict(os.environ,
+ {'BUP_FORCE_TTY': str((fix_stdout and 1 or 0)
+ + (fix_stderr and 2 or 0))})
+else:
+ tty_env = os.environ
sep_rx = re.compile(br'([\r\n])')
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
p = subprocess.Popen(c,
stdout=PIPE if fix_stdout else sys.stdout,
stderr=PIPE if fix_stderr else sys.stderr,
- preexec_fn=force_tty,
- bufsize=4096,
- close_fds=True)
+ env=tty_env, bufsize=4096, close_fds=True)
# Assume p will receive these signals and quit, which will
# then cause us to quit.
for sig in (signal.SIGINT, signal.SIGTERM, signal.SIGQUIT):
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))