MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / main

Function main

tools/python-3.11.9-amd64/Tools/scripts/diff.py:19–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17 return t.astimezone().isoformat()
18
19def main():
20
21 parser = argparse.ArgumentParser()
22 parser.add_argument('-c', action='store_true', default=False,
23 help='Produce a context format diff (default)')
24 parser.add_argument('-u', action='store_true', default=False,
25 help='Produce a unified format diff')
26 parser.add_argument('-m', action='store_true', default=False,
27 help='Produce HTML side by side diff '
28 '(can use -c and -l in conjunction)')
29 parser.add_argument('-n', action='store_true', default=False,
30 help='Produce a ndiff format diff')
31 parser.add_argument('-l', '--lines', type=int, default=3,
32 help='Set number of context lines (default 3)')
33 parser.add_argument('fromfile')
34 parser.add_argument('tofile')
35 options = parser.parse_args()
36
37 n = options.lines
38 fromfile = options.fromfile
39 tofile = options.tofile
40
41 fromdate = file_mtime(fromfile)
42 todate = file_mtime(tofile)
43 with open(fromfile) as ff:
44 fromlines = ff.readlines()
45 with open(tofile) as tf:
46 tolines = tf.readlines()
47
48 if options.u:
49 diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n)
50 elif options.n:
51 diff = difflib.ndiff(fromlines, tolines)
52 elif options.m:
53 diff = difflib.HtmlDiff().make_file(fromlines,tolines,fromfile,tofile,context=options.c,numlines=n)
54 else:
55 diff = difflib.context_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n)
56
57 sys.stdout.writelines(diff)
58
59if __name__ == '__main__':
60 main()

Callers 1

diff.pyFile · 0.70

Calls 7

parse_argsMethod · 0.95
file_mtimeFunction · 0.85
openFunction · 0.50
add_argumentMethod · 0.45
readlinesMethod · 0.45
make_fileMethod · 0.45
writelinesMethod · 0.45

Tested by

no test coverage detected