MCPcopy Index your code
hub / github.com/python/cpython / main

Function main

Doc/includes/diff.py:18–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…