comparison python/sshdiff.py @ 141:c4aaaa6d9c13

add a program for diffing over ssh
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 24 May 2011 21:50:39 -0700
parents
children
comparison
equal deleted inserted replaced
140:939ee1ab226a 141:c4aaaa6d9c13
1 #!/usr/bin/env python
2
3 """
4 diff files over ssh
5 """
6
7 import os
8 import subprocess
9 import sys
10 import tempfile
11 from optparse import OptionParser
12
13 def main(args=sys.argv[1:]):
14 usage = "%prog host file"
15 parser = OptionParser(usage=usage, description=__doc__)
16 options, args = parser.parse_args(args)
17 try:
18 host, filename = args
19 except ValueError:
20 parser.print_usage()
21 parser.exit(1)
22 process = subprocess.Popen(["ssh", host, "cat", filename], stdout=subprocess.PIPE)
23 stdout, stderr = process.communicate()
24 fd, buffer = tempfile.mkstemp()
25 os.write(fd, stdout)
26 os.close(fd)
27 subprocess.call(['diff', os.path.join(os.environ['HOME'], filename), buffer])
28 try:
29 os.remove(buffer)
30 except:
31 pass
32
33 if __name__ == '__main__':
34 main()
35