X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=main.py;h=78da11de049689c7b81736a179d0e4c1a63463f3;hb=6385aa493eff14c7b59aa964ea5cce6f6c3b79a7;hp=f955321d97afd80845d05be5d9d73c0c1caff023;hpb=f1b53cb8b21aac5b11f0fec4b7c31f71412ce075;p=bup.git diff --git a/main.py b/main.py index f955321..78da11d 100755 --- a/main.py +++ b/main.py @@ -42,7 +42,7 @@ os.environ['BUP_RESOURCE_PATH'] = resourcepath 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 @@ -148,10 +148,12 @@ if subcmd_name in ['mux', 'ftp', 'help']: 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])') @@ -215,7 +217,7 @@ def filter_output(src_out, src_err, dest_out, dest_err): 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): @@ -223,9 +225,9 @@ def filter_output(src_out, src_err, dest_out, dest_err): 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 @@ -240,9 +242,7 @@ def run_subcmd(subcmd): 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): @@ -260,7 +260,7 @@ def run_subcmd(subcmd): 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))