#!/usr/bin/python # opendiff2.py, by Steve Nygard import getopt, os, shutil, string, sys import posixpath # When this is called from the shell script that makes sure FileMerge is running, it would pass in -s $PPID class Usage(Exception): def __init__(self, msg): self.msg = msg def usage(): print "opendiff2.py 1.1 (2006-12-19)" print "Usage: opendiff2 [-u] [-L label] [-s session_id] " print def main(argv=None): if (argv == None): argv = sys.argv session_id = "%d" % os.getppid() labels = [] filenames = [] try: opts, args = getopt.getopt(argv[1:], 'uL:s:'); except getopt.error, msg: raise Usage(msg) for opt, arg in opts: if opt == '-u': pass if opt == '-L': (filename, desc) = string.split(arg, '\t', 1) filename = os.path.basename(filename) filenames.append(filename) labels.append(" ".join([filename, desc])) if opt == '-s': session_id = arg try: os.mkdir('/tmp/opendiff2') except OSError: pass try: os.mkdir('/tmp/opendiff2/%s' % session_id) except OSError: pass source1 = posixpath.join(posixpath.abspath(os.curdir), args[0]) source2 = posixpath.join(posixpath.abspath(os.curdir), args[1]) target1 = "/tmp/opendiff2/%s/%s" % (session_id, labels[0]) target2 = "/tmp/opendiff2/%s/%s" % (session_id, labels[1]) # Subversion 1.4.2 is giving the same label on file additions: i.e. "Foo.h\t(revision 0)" if target1 == target2: target2 = target2 + "-b" # Create hard links to foil FileMerge. #print "linking", source1, "to", target1 #os.link(source1, target1) #print "linking", source2, "to", target2 #os.link(source2, target2) # Alas, this is foiled because FileMerge resolves the symbolic links and shows you the orignal, ugly, useless name. Bastards. #os.symlink(source1, target1) #os.symlink(source2, target2) #print "copying", source1, "to", target1 #print "copying", source2, "to", target2 shutil.copy(source1, target1) shutil.copy(source2, target2) os.system("Launcher") os.execv('/usr/bin/opendiff', ['opendiff', target1, target2]) if __name__ == '__main__': sys.exit(main())