示例#1
0
from bup import options
from bup import _helpers  # fixes up sys.argv on import

optspec = """
bup newliner
"""
o = options.Options(optspec)
(opt, flags, extra) = o.parse(sys.argv[1:])

if extra:
    o.fatal("no arguments expected")

r = re.compile(r'([\r\n])')
lastlen = 0
all = ''
width = options._tty_width() or 78
while 1:
    l = r.split(all, 1)
    if len(l) <= 1:
        if len(all) >= 160:
            sys.stdout.write('%s\n' % all[:78])
            sys.stdout.flush()
            all = all[78:]
        try:
            b = os.read(sys.stdin.fileno(), 4096)
        except KeyboardInterrupt:
            break
        if not b:
            break
        all += b
    else:
示例#2
0
文件: main.py 项目: jmberg/bup
    subcmd[0] = os.path.join(cmdpath, b'bup-' + subcmd_name)
    if not os.path.exists(subcmd[0]):
        usage('error: unknown command "%s"' % path_msg(subcmd_name))

already_fixed = int(environ.get(b'BUP_FORCE_TTY', 0))
if subcmd_name in [b'mux', b'ftp', b'help']:
    already_fixed = True
fix_stdout = not already_fixed and os.isatty(1)
fix_stderr = not already_fixed and os.isatty(2)

if fix_stdout or fix_stderr:
    tty_env = merge_dict(environ,
                         {b'BUP_FORCE_TTY': (b'%d'
                                             % ((fix_stdout and 1 or 0)
                                                + (fix_stderr and 2 or 0))),
                          b'BUP_TTY_WIDTH': b'%d' % _tty_width(), })
else:
    tty_env = environ


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
    padding the content with enough spaces to fill the current
    terminal width or truncating it to the terminal width if sep is a
    carriage return."""
    global sep_rx
    assert sep in (b'\r', b'\n', None)
    if not content:
        if sep:
示例#3
0
文件: newliner-cmd.py 项目: 0xkag/bup
from bup import options
from bup import _helpers   # fixes up sys.argv on import

optspec = """
bup newliner
"""
o = options.Options(optspec)
(opt, flags, extra) = o.parse(sys.argv[1:])

if extra:
    o.fatal("no arguments expected")

r = re.compile(r'([\r\n])')
lastlen = 0
all = ''
width = options._tty_width() or 78
while 1:
    l = r.split(all, 1)
    if len(l) <= 1:
        if len(all) >= 160:
            sys.stdout.write('%s\n' % all[:78])
            sys.stdout.flush()
            all = all[78:]
        try:
            b = os.read(sys.stdin.fileno(), 4096)
        except KeyboardInterrupt:
            break
        if not b:
            break
        all += b
    else:
示例#4
0
文件: main.py 项目: gdt/bup
    if not os.path.exists(subcmd[0]):
        usage('error: unknown command "%s"' % path_msg(subcmd_name))

already_fixed = int(environ.get(b'BUP_FORCE_TTY', 0))
if subcmd_name in [b'mux', b'ftp', b'help']:
    already_fixed = True
fix_stdout = not already_fixed and os.isatty(1)
fix_stderr = not already_fixed and os.isatty(2)

if fix_stdout or fix_stderr:
    tty_env = merge_dict(
        environ, {
            b'BUP_FORCE_TTY':
            (b'%d' % ((fix_stdout and 1 or 0) + (fix_stderr and 2 or 0))),
            b'BUP_TTY_WIDTH':
            b'%d' % _tty_width(),
        })
else:
    tty_env = environ

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
    padding the content with enough spaces to fill the current
    terminal width or truncating it to the terminal width if sep is a
    carriage return."""
    global sep_rx
    assert sep in (b'\r', b'\n', None)
    if not content:
示例#5
0
    subcmd[0] = os.path.join(cmdpath, b'bup-' + subcmd_name)
    if not os.path.exists(subcmd[0]):
        usage('error: unknown command "%s"' % path_msg(subcmd_name))

already_fixed = int(environ.get(b'BUP_FORCE_TTY', 0))
if subcmd_name in [b'mux', b'ftp', b'help']:
    fix_stdout = False
    fix_stderr = False
else:
    fix_stdout = not (already_fixed & 1) and os.isatty(1)
    fix_stderr = not (already_fixed & 2) and os.isatty(2)

if fix_stdout or fix_stderr:
    _ttymask = (fix_stdout and 1 or 0) + (fix_stderr and 2 or 0)
    environ[b'BUP_FORCE_TTY'] = b'%d' % _ttymask
    environ[b'BUP_TTY_WIDTH'] = b'%d' % _tty_width()

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
    padding the content with enough spaces to fill the current
    terminal width or truncating it to the terminal width if sep is a
    carriage return."""
    global sep_rx
    assert sep in (b'\r', b'\n', None)
    if not content:
        if sep:
            os.write(dest, sep)
        return