Mercurial > hg > config
annotate python/sshdiff.py @ 431:72f33eb3aa23
add an attach.py script
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 08 Aug 2013 00:24:41 -0700 |
parents | c4aaaa6d9c13 |
children |
rev | line source |
---|---|
141
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 """ |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 diff files over ssh |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 """ |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 import os |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 import subprocess |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 import sys |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 import tempfile |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 from optparse import OptionParser |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 def main(args=sys.argv[1:]): |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 usage = "%prog host file" |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 parser = OptionParser(usage=usage, description=__doc__) |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 options, args = parser.parse_args(args) |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 try: |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 host, filename = args |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 except ValueError: |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 parser.print_usage() |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
21 parser.exit(1) |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
22 process = subprocess.Popen(["ssh", host, "cat", filename], stdout=subprocess.PIPE) |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
23 stdout, stderr = process.communicate() |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
24 fd, buffer = tempfile.mkstemp() |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
25 os.write(fd, stdout) |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
26 os.close(fd) |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
27 subprocess.call(['diff', os.path.join(os.environ['HOME'], filename), buffer]) |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
28 try: |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
29 os.remove(buffer) |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
30 except: |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
31 pass |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
32 |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
33 if __name__ == '__main__': |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
34 main() |
c4aaaa6d9c13
add a program for diffing over ssh
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
35 |