blob: 4b6511c30ddab02133a71e80fe7cc27460e90930 [file] [log] [blame]
S.Çağlar Onur3e92b4d2015-02-09 13:34:11 -05001#! /usr/bin/env python
Scott Baker4646bf62014-09-26 12:23:27 -07002
3import base64
4import os
5import sys
6import subprocess
7import StringIO
8
9if len(sys.argv)<3:
10 print >> sys.stderr, "syntax: diff-opencloud <localfn> <remotehost:remotefn>"
11 sys.exit(-1)
12
13srcfn = sys.argv[1]
14dest = sys.argv[2]
15
16if not ":" in dest:
17 print >> sys.stderr, "malformed desthost:destfn"
18 sys.exit(-1)
19
20(hostname,destfn) = dest.split(":",1)
21
22if destfn.endswith("/"):
23 destfn = destfn + os.path.basename(srcfn)
24
25script = 'echo START; base64 %s' % destfn
26
27file("/tmp/script","w").write(script)
28
Scott Bakere4226cf2014-09-26 12:36:39 -070029p = subprocess.Popen(["ssh", "-A", hostname], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
30(enctext,stderr) = p.communicate(input=script)
31
32if stderr:
33 print >> sys.stderr, stderr
34
35if "No such file" in stderr:
36 sys.exit(-1)
Scott Baker4646bf62014-09-26 12:23:27 -070037
38enctext = enctext.split("START")[1]
39
40text = base64.b64decode(enctext)
41
42file("/tmp/diff-src","w").write(text)
43os.system("diff /tmp/diff-src %s" % srcfn)
44
45"""
46SRCPATHNAME=$1
47DESTHOSTNAME=$2
48DESTPATHNAME=$3
49echo "base64 -d -i > $DESTPATHNAME <<EOF" > /tmp/ssh-up
50base64 $SRCPATHNAME >> /tmp/ssh-up
51echo "EOF" >> /tmp/ssh-up
52ssh -A $DESTHOSTNAME < /tmp/ssh-up
53"""