Back to index

python3.2  3.2.2
Functions
diff Namespace Reference

Functions

def main

Function Documentation

def diff.main ( void  )

Definition at line 13 of file diff.py.

00013 
00014 def main():
00015 
00016     usage = "usage: %prog [options] fromfile tofile"
00017     parser = optparse.OptionParser(usage)
00018     parser.add_option("-c", action="store_true", default=False, help='Produce a context format diff (default)')
00019     parser.add_option("-u", action="store_true", default=False, help='Produce a unified format diff')
00020     parser.add_option("-m", action="store_true", default=False, help='Produce HTML side by side diff (can use -c and -l in conjunction)')
00021     parser.add_option("-n", action="store_true", default=False, help='Produce a ndiff format diff')
00022     parser.add_option("-l", "--lines", type="int", default=3, help='Set number of context lines (default 3)')
00023     (options, args) = parser.parse_args()
00024 
00025     if len(args) == 0:
00026         parser.print_help()
00027         sys.exit(1)
00028     if len(args) != 2:
00029         parser.error("need to specify both a fromfile and tofile")
00030 
00031     n = options.lines
00032     fromfile, tofile = args
00033 
00034     fromdate = time.ctime(os.stat(fromfile).st_mtime)
00035     todate = time.ctime(os.stat(tofile).st_mtime)
00036     fromlines = open(fromfile, 'U').readlines()
00037     tolines = open(tofile, 'U').readlines()
00038 
00039     if options.u:
00040         diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n)
00041     elif options.n:
00042         diff = difflib.ndiff(fromlines, tolines)
00043     elif options.m:
00044         diff = difflib.HtmlDiff().make_file(fromlines,tolines,fromfile,tofile,context=options.c,numlines=n)
00045     else:
00046         diff = difflib.context_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n)
00047 
00048     sys.stdout.writelines(diff)

Here is the call graph for this function: