Exemple #1
0
def filter_output(srcs, dests):
    """Transfer data from file descriptors in srcs to the corresponding
    file descriptors in dests print_clean_line until all of the srcs
    have closed.

    """
    global sep_rx
    assert all(type(x) in int_types for x in srcs)
    assert all(type(x) in int_types for x in srcs)
    assert len(srcs) == len(dests)
    srcs = tuple(srcs)
    dest_for = dict(zip(srcs, dests))
    pending = {}
    pending_ex = None
    try:
        while srcs:
            ready_fds, _, _ = select.select(srcs, [], [])
            width = tty_width()
            for fd in ready_fds:
                buf = os.read(fd, 4096)
                dest = dest_for[fd]
                if not buf:
                    srcs = tuple([x for x in srcs if x is not fd])
                    print_clean_line(dest, pending.pop(fd, []), width)
                else:
                    split = sep_rx.split(buf)
                    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 = 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):
            dest = dest_for[fd]
            width = tty_width()
            try:
                print_clean_line(dest, pending_items, width)
            except (EnvironmentError, EOFError) as ex:
                pending_ex = add_ex_ctx(add_ex_tb(ex), pending_ex)
    except BaseException as ex:
        pending_ex = add_ex_ctx(add_ex_tb(ex), pending_ex)
    if pending_ex:
        raise pending_ex
Exemple #2
0
def usage(argspec, width=None):
    if not width:
        width = tty_width()
    usage, preamble, groups = argspec[0], argspec[1], argspec[2:]
    msg = []
    msg.append(textwrap.fill(usage, width=width, subsequent_indent='  '))
    msg.append('\n\n')
    msg.append(textwrap.fill(preamble.replace('\n', ' '), width=width))
    msg.append('\n')
    for group_name, group_args in groups:
        msg.extend(['\n', group_name, '\n'])
        msg.extend(render_opts(group_args, width=width))
    return ''.join(msg)
Exemple #3
0
Fichier : main.py Projet : bup/bup
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
    print_clean_line until src_out and src_err close."""
    global sep_rx
    assert not isinstance(src_out, bool)
    assert not isinstance(src_err, bool)
    assert not isinstance(dest_out, bool)
    assert not isinstance(dest_err, bool)
    assert src_out is not None or src_err is not None
    assert (src_out is None) == (dest_out is None)
    assert (src_err is None) == (dest_err is None)
    pending = {}
    pending_ex = None
    try:
        fds = tuple([x for x in (src_out, src_err) if x is not None])
        while fds:
            ready_fds, _, _ = select.select(fds, [], [])
            width = tty_width()
            for fd in ready_fds:
                buf = os.read(fd, 4096)
                dest = dest_out if fd == src_out else dest_err
                if not buf:
                    fds = tuple([x for x in fds if x is not fd])
                    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)
                        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 compat.items(pending):
            dest = dest_out if fd == src_out else 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)
    except BaseException as ex:
        pending_ex = chain_ex(add_ex_tb(ex), pending_ex)
    if pending_ex:
        raise pending_ex
Exemple #4
0
def render_opts(opts, width=None):
    if not width:
        width = tty_width()
    result = []
    for args, desc in opts:
        result.append(textwrap.fill(args, width=width,
                                    initial_indent=(' ' * 2),
                                    subsequent_indent=(' ' * 4)))
        result.append('\n')
        result.append(textwrap.fill(desc, width=width,
                                    initial_indent=(' ' * 6),
                                    subsequent_indent=(' ' * 6)))
        result.append('\n')
    return result
Exemple #5
0
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
    print_clean_line until src_out and src_err close."""
    global sep_rx
    assert not isinstance(src_out, bool)
    assert not isinstance(src_err, bool)
    assert not isinstance(dest_out, bool)
    assert not isinstance(dest_err, bool)
    assert src_out is not None or src_err is not None
    assert (src_out is None) == (dest_out is None)
    assert (src_err is None) == (dest_err is None)
    pending = {}
    pending_ex = None
    try:
        fds = tuple([x for x in (src_out, src_err) if x is not None])
        while fds:
            ready_fds, _, _ = select.select(fds, [], [])
            width = tty_width()
            for fd in ready_fds:
                buf = os.read(fd, 4096)
                dest = dest_out if fd == src_out else dest_err
                if not buf:
                    fds = tuple([x for x in fds if x is not fd])
                    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)
                        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 compat.items(pending):
            dest = dest_out if fd == src_out else 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)
    except BaseException as ex:
        pending_ex = chain_ex(add_ex_tb(ex), pending_ex)
    if pending_ex:
        raise pending_ex
Exemple #6
0
else:
    # running from the src directory without being installed first
    cmdpath = os.path.join(exepath, 'cmd')
    libpath = os.path.join(exepath, 'lib')
    resourcepath = libpath
sys.path[:0] = [libpath]
os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '')
os.environ['BUP_MAIN_EXE'] = os.path.abspath(exe)
os.environ['BUP_RESOURCE_PATH'] = resourcepath

from bup import helpers
from bup.compat import wrap_main
from bup.helpers import atoi, columnate, debug1, log, tty_width

# after running 'bup newliner', the tty_width() ioctl won't work anymore
os.environ['WIDTH'] = str(tty_width())


def usage(msg=""):
    log('Usage: bup [-?|--help] [-d BUP_DIR] [--debug] [--profile] '
        '<command> [options...]\n\n')
    common = dict(
        ftp='Browse backup sets using an ftp-like client',
        fsck='Check backup sets for damage and add redundancy information',
        fuse='Mount your backup sets as a filesystem',
        help='Print detailed help for the given command',
        index='Create or display the index of files to back up',
        on='Backup a remote machine to the local one',
        restore='Extract files from a backup set',
        save='Save files into a backup set (note: run "bup index" first)',
        tag='Tag commits for easier access',
Exemple #7
0
    # running from the src directory without being installed first
    cmdpath = os.path.join(exepath, 'cmd')
    libpath = os.path.join(exepath, 'lib')
    resourcepath = libpath
sys.path[:0] = [libpath]
os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '')
os.environ['BUP_MAIN_EXE'] = os.path.abspath(exe)
os.environ['BUP_RESOURCE_PATH'] = resourcepath


from bup import helpers
from bup.helpers import atoi, columnate, debug1, log, tty_width


# after running 'bup newliner', the tty_width() ioctl won't work anymore
os.environ['WIDTH'] = str(tty_width())

def usage(msg=""):
    log('Usage: bup [-?|--help] [-d BUP_DIR] [--debug] [--profile] '
        '<command> [options...]\n\n')
    common = dict(
        ftp = 'Browse backup sets using an ftp-like client',
        fsck = 'Check backup sets for damage and add redundancy information',
        fuse = 'Mount your backup sets as a filesystem',
        help = 'Print detailed help for the given command',
        index = 'Create or display the index of files to back up',
        on = 'Backup a remote machine to the local one',
        restore = 'Extract files from a backup set',
        save = 'Save files into a backup set (note: run "bup index" first)',
        tag = 'Tag commits for easier access',
        web = 'Launch a web server to examine backup sets',