X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=main.py;h=7f632beaa997f0a7dd6bbff8066f32f4b80dff96;hb=3f5e89ef0ed18eecbacc3671211f804b54b93c51;hp=119826564d7266815639d978c9d11400c5364ddc;hpb=00fb1f1b2a53935ca7d5ce95ea4cf56b7f9bcc3d;p=bup.git diff --git a/main.py b/main.py index 1198265..7f632be 100755 --- a/main.py +++ b/main.py @@ -5,12 +5,18 @@ exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble +from __future__ import absolute_import, print_function import errno, re, sys, os, subprocess, signal, getopt -from fcntl import F_GETFL, F_SETFL +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 fcntl, select +import select argv = sys.argv exe = os.path.realpath(argv[0]) @@ -35,7 +41,7 @@ os.environ['BUP_MAIN_EXE'] = os.path.abspath(exe) os.environ['BUP_RESOURCE_PATH'] = resourcepath -from bup import helpers +from bup import compat, helpers from bup.compat import add_ex_tb, chain_ex, wrap_main from bup.helpers import atoi, columnate, debug1, log, tty_width @@ -169,7 +175,8 @@ def print_clean_line(dest, content, width, sep=None): os.write(dest, content) if len(content) < width: os.write(dest, ' ' * (width - len(content))) - os.write(dest, sep) + if sep: + os.write(dest, sep) def filter_output(src_out, src_err, dest_out, dest_err): """Transfer data from src_out to dest_out and src_err to dest_err via @@ -186,9 +193,6 @@ def filter_output(src_out, src_err, dest_out, dest_err): pending_ex = None try: fds = tuple([x for x in (src_out, src_err) if x is not None]) - for fd in fds: - flags = fcntl.fcntl(fd, F_GETFL) - assert fcntl.fcntl(fd, F_SETFL, flags | os.O_NONBLOCK) == 0 while fds: ready_fds, _, _ = select.select(fds, [], []) width = tty_width() @@ -200,22 +204,21 @@ def filter_output(src_out, src_err, dest_out, dest_err): 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) try: # Try to finish each of the streams - for fd, pending_items in pending.iteritems(): + for fd, pending_items in compat.items(pending): dest = dest_out if fd == src_out else dest_err try: print_clean_line(dest, pending_items, width)