File: gendiff

package info (click to toggle)
pyqwt3d 0.1.8-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 984 kB
  • sloc: python: 3,932; cpp: 328; makefile: 115; sh: 7
file content (39 lines) | stat: -rwxr-xr-x 997 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python

import difflib
import os
import sys
import time

def usage():
    print "gendiff tree .suffix"
    sys.exit(1)

# usage()

def main(args):
    if len(args) != 3:
        usage()
    tree = args[1]
    suffix = args[2]
    for root, _, files in os.walk(tree):
        for name in files:
            fromfile = os.path.join(root, name)
            tofile = os.path.join(root, os.path.splitext(name)[0])
            if os.path.splitext(name)[-1] == suffix and os.path.exists(tofile):
                fromdate = time.ctime(os.stat(fromfile).st_mtime)
                todate = time.ctime(os.stat(tofile).st_mtime)
                fromlines = open(fromfile, 'U').readlines()
                tolines = open(tofile, 'U').readlines()
                sys.stdout.writelines(difflib.unified_diff(
                    fromlines, tolines, fromfile, tofile, fromdate, todate))

# main()

if __name__ == '__main__':
    main(sys.argv)


# Local Variables: ***
# mode: python ***
# End: ***