Esempio n. 1
0
def show_diff(filepath1, filepath2):
    graph1 = DelphiGraph.from_file(filepath1)
    graph2 = DelphiGraph.from_file(filepath2)

    color_title = ansicolor.magenta
    color1 = ansicolor.cyan
    color2 = ansicolor.yellow

    keyw_def, fstw_def, sndw_def = 10, 30, 30
    
    diffs = DelphiGraph.diff_graphs(graph1, graph2)

    exit = 0
    if diffs:
        exit = 1
        io.output('Showing diff between:\n')
        io.output(' - %s\n' % color1(filepath1))
        io.output(' - %s\n' % color2(filepath2))

        for diff in diffs:
            io.output(color_title('>>> File: %s\n' % diff.name))

            keyw = get_len(diff.keys(), keyw_def)

            for att, val in diff.iteritems():
                fst, snd = val

                fsts = fmt_obj(fst, fstw_def)
                snds = fmt_obj(snd, sndw_def)

                fstw = get_len(fsts, fstw_def)
                sndw = get_len(snds, sndw_def)

                if fstw <= fstw_def and sndw <= sndw_def:
                    s = show_sidebyside(att, fsts, snds, (keyw,fstw,sndw),
                                        (color1,color2))
                else:
                    s = show_oneafterother(att, fsts, snds, (keyw,fstw,sndw),
                                           (color1,color2))
                io.output(s)

    return exit