Example #1
0
def logcmd(cmd):
    s = helpers.shstr(cmd)
    if isinstance(cmd, str):
        print(s, file=sys.stderr)
    else:
        # bytes - for now just escape it
        print(s.decode(errors='backslashreplace'), file=sys.stderr)
Example #2
0
def logcmd(cmd):
    s = helpers.shstr(cmd)
    if isinstance(cmd, str_type):
        print(s, file=sys.stderr)
    else:
        # bytes - for now just continue to pass it through given
        # bup-python wrapper
        print(s.decode('iso-8859-1'), file=sys.stderr)
Example #3
0
def logcmd(cmd):
    log(shstr(cmd).decode(errors='backslashreplace') + '\n')
Example #4
0
def parse_args(args):
    Spec = namedtuple('Spec', ['argopt', 'argval', 'src', 'dest', 'method'])

    class GetOpts:
        pass

    opt = GetOpts()
    opt.help = False
    opt.verbose = 0
    opt.quiet = False
    opt.print_commits = opt.print_trees = opt.print_tags = False
    opt.bwlimit = None
    opt.compress = 1
    opt.source = opt.remote = None
    opt.target_specs = []

    remaining = args[1:]  # Skip argv[0]
    while remaining:
        arg = remaining[0]
        if arg in ('-h', '--help'):
            sys.stdout.write(usage(argspec))
            sys.exit(0)
        elif arg in ('-v', '--verbose'):
            opt.verbose += 1
            remaining = remaining[1:]
        elif arg in ('--ff', '--append', '--pick', '--force-pick', '--new-tag',
                     '--replace', '--unnamed'):
            (ref, ), remaining = require_n_args_or_die(1, remaining)
            opt.target_specs.append(
                Spec(argopt=arg,
                     argval=shstr((ref, )),
                     src=ref,
                     dest=None,
                     method=arg[2:]))
        elif arg in ('--ff:', '--append:', '--pick:', '--force-pick:',
                     '--new-tag:', '--replace:'):
            (ref, dest), remaining = require_n_args_or_die(2, remaining)
            opt.target_specs.append(
                Spec(argopt=arg,
                     argval=shstr((ref, dest)),
                     src=ref,
                     dest=dest,
                     method=arg[2:-1]))
        elif arg in ('-s', '--source'):
            (opt.source, ), remaining = require_n_args_or_die(1, remaining)
        elif arg in ('-r', '--remote'):
            (opt.remote, ), remaining = require_n_args_or_die(1, remaining)
        elif arg in ('-c', '--print-commits'):
            opt.print_commits, remaining = True, remaining[1:]
        elif arg in ('-t', '--print-trees'):
            opt.print_trees, remaining = True, remaining[1:]
        elif arg == '--print-tags':
            opt.print_tags, remaining = True, remaining[1:]
        elif arg in ('-0', '-1', '-2', '-3', '-4', '-5', '-6', '-7', '-8',
                     '-9'):
            opt.compress = int(arg[1:])
            remaining = remaining[1:]
        elif arg == '--compress':
            (opt.compress, ), remaining = require_n_args_or_die(1, remaining)
            opt.compress = int(opt.compress)
        elif arg == '--bwlimit':
            (opt.bwlimit, ), remaining = require_n_args_or_die(1, remaining)
            opt.bwlimit = long(opt.bwlimit)
        elif arg.startswith('-') and len(arg) > 2 and arg[1] != '-':
            # Try to interpret this as -xyz, i.e. "-xyz -> -x -y -z".
            # We do this last so that --foo -bar is valid if --foo
            # requires a value.
            remaining[0:1] = ('-' + c for c in arg[1:])
            # FIXME
            continue
        else:
            misuse()
    return opt
Example #5
0
def test_shstr():
    # Do nothing for strings and bytes
    WVPASSEQ(shstr(b''), b'')
    WVPASSEQ(shstr(b'1'), b'1')
    WVPASSEQ(shstr(b'1 2'), b'1 2')
    WVPASSEQ(shstr(b"1'2"), b"1'2")
    WVPASSEQ(shstr(''), '')
    WVPASSEQ(shstr('1'), '1')
    WVPASSEQ(shstr('1 2'), '1 2')
    WVPASSEQ(shstr("1'2"), "1'2")

    # Escape parts of sequences
    WVPASSEQ(shstr((b'1 2', b'3')), b"'1 2' 3")
    WVPASSEQ(shstr((b"1'2", b'3')), b"'1'\"'\"'2' 3")
    WVPASSEQ(shstr((b"'1", b'3')), b"''\"'\"'1' 3")
    WVPASSEQ(shstr(('1 2', '3')), "'1 2' 3")
    WVPASSEQ(shstr(("1'2", '3')), "'1'\"'\"'2' 3")
    WVPASSEQ(shstr(("'1", '3')), "''\"'\"'1' 3")
Example #6
0
def _git_wait(cmd, p):
    rv = p.wait()
    if rv != 0:
        raise GitError('%s returned %d' % (shstr(cmd), rv))
Example #7
0
def ex(cmd, **kwargs):
    print(shstr(cmd), file=stderr)
    return exc(cmd, **kwargs)
Example #8
0
def logcmd(cmd):
    log(shstr(cmd).decode('iso-8859-1', errors='replace') + '\n')
Example #9
0
 def test_quote(arg):
     assume(b'\x00' not in arg)
     p = subprocess.Popen(
         [b'bash', _echopath, shstr(arg)], stdout=subprocess.PIPE)
     WVPASSEQ(arg, p.communicate()[0][:-1])  # strip one \0