Пример #1
0
def colorize(text):
    ctext = ''
    hunk_cre = re.compile(r'^(@@ -[0-9]+(,[0-9]+)? +[0-9]+(,[0-9]+)? @@)([ \t]*)(.*\n?)')
    for line in text.splitlines(True):
        if line.startswith(('Index: ', '--- ', '+++ ', '*** ')):
            ctext += colour.wrap(line, 'diff_hdr')
        elif line.startswith('+'):
            ctext += colour.wrap(line, 'diff_add')
        elif line.startswith('-'):
            ctext += colour.wrap(line, 'diff_rem')
        elif line.startswith('!'):
            ctext += colour.wrap(line, 'diff_mod')
        elif line.startswith('*' * 15):
            ctext += colour.wrap(line, 'diff_cctx')
        else:
            match = hunk_cre.match(line)
            if match:
                ctext += wrap(match.group(1), 'diff_hunk')
                if match.group(4) is not None:
                    ctext += match.group(4)
                if match.group(5) is not None:
                    ctext += wrap(match.group(5), 'diff_ctx')
            else:
                ctext += line
    return ctext
Пример #2
0
def scan_unapplied(category, prefix, file_paths, patches):
    for patch in patches:
        strip = patchfns.patch_strip_level(patch)
        pfn = patchfns.patch_file_name(patch)
        patch_files = putils.get_patch_files(pfn, strip_level=strip)
        for file_path in file_paths:
            if file_path in patch_files:
                output.write(colour.wrap('%s%s\n' % (prefix, patchfns.print_patch(patch)), category))
Пример #3
0
def colorize(text):
    ret = ''
    for line in text.splitlines(True):
        if _FAIL_CRE.search(line):
            ret += colours.wrap(line, 'patch_fail')
        elif line.endswith('already applied'):
            ret += colour.wrap(line, 'patch_fuzz')
        elif line.startswith('Hunk'):
            match = _FUZZ_CRE.match(line)
            if match:
                line = _FUZZ_CRE.sub(colour.wrap(match.group(1), 'patch_fuzz'), line)
            match = _OFFSET_CRE.search(line)
            if match:
                line = _OFFSET_CRE.sub(colour.wrap(match.group(1), 'patch_offs'), line)
            ret += line
        else:
            ret += line
    return ret
Пример #4
0
def run_series(args):
    patchfns.chdir_to_base_dir()
    output.start_pager()
    do_colorize = args.opt_color == 'always' or (args.opt_color == 'auto' and sys.stderr.isatty())
    if do_colorize:
        colour.set_up()
    if do_colorize or args.opt_verbose:
        top = patchfns.top_patch()
        for patch in patchfns.patches_before(top):
            string = '+ %s\n' % patchfns.print_patch(patch)
            output.write(colour.wrap(string, 'series_app') if do_colorize else string)
        if top:
            string = '= %s\n' % patchfns.print_patch(top)
            output.write(colour.wrap(string, 'series_top') if do_colorize else string)
        for patch in patchfns.patches_after(top):
            string = '  %s\n' % patchfns.print_patch(patch)
            output.write(colour.wrap(string, 'series_una') if do_colorize else string)
    else:
        for patch in patchfns.cat_series():
            output.write('%s\n' % patchfns.print_patch(patch))
    output.wait_for_pager()
    return cmd_result.OK
Пример #5
0
def scan_applied(category, prefix, file_paths, patches):
    for patch in patches:
        for file_path in file_paths:
            if os.path.isfile(patchfns.backup_file_name(patch, file_path)):
                output.write(colour.wrap('%s%s\n' % (prefix, patchfns.print_patch(patch)), category))