source: vendor/python/2.5/Tools/scripts/diff.py

Last change on this file was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 2.0 KB
Line 
1""" Command line interface to difflib.py providing diffs in four formats:
2
3* ndiff: lists every line and highlights interline changes.
4* context: highlights clusters of changes in a before/after format.
5* unified: highlights clusters of changes in an inline format.
6* html: generates side by side comparison with change highlights.
7
8"""
9
10import sys, os, time, difflib, optparse
11
12def main():
13
14 usage = "usage: %prog [options] fromfile tofile"
15 parser = optparse.OptionParser(usage)
16 parser.add_option("-c", action="store_true", default=False, help='Produce a context format diff (default)')
17 parser.add_option("-u", action="store_true", default=False, help='Produce a unified format diff')
18 parser.add_option("-m", action="store_true", default=False, help='Produce HTML side by side diff (can use -c and -l in conjunction)')
19 parser.add_option("-n", action="store_true", default=False, help='Produce a ndiff format diff')
20 parser.add_option("-l", "--lines", type="int", default=3, help='Set number of context lines (default 3)')
21 (options, args) = parser.parse_args()
22
23 if len(args) == 0:
24 parser.print_help()
25 sys.exit(1)
26 if len(args) != 2:
27 parser.error("need to specify both a fromfile and tofile")
28
29 n = options.lines
30 fromfile, tofile = args
31
32 fromdate = time.ctime(os.stat(fromfile).st_mtime)
33 todate = time.ctime(os.stat(tofile).st_mtime)
34 fromlines = open(fromfile, 'U').readlines()