1 """Compare local and remote dictionaries and transfer differing files -- like rdist."""
11 s
= raw_input("chdir [%s] " % pwd
)
15 host
= ask("host", 'voorn.cwi.nl')
20 Mode should be a string of characters, indicating what to do with differences.
21 r - read different files to local file system
22 w - write different files to remote file system
23 c - create new files, either remote or local
24 d - delete disappearing files, either remote or local
26 s
= raw_input("mode [%s] " % mode
)
28 address
= (host
, port
)
30 local
= FSProxy
.FSProxyLocal()
31 remote
= FSProxy
.FSProxyClient(address
, verbose
)
32 compare(local
, remote
, mode
)
37 mins
, secs
= divmod(dt
, 60)
38 print mins
, "minutes and", round(secs
), "seconds"
39 raw_input("[Return to exit] ")
41 def ask(prompt
, default
):
42 s
= raw_input("%s [%s] " % (prompt
, default
))
45 def askint(prompt
, default
):
46 s
= raw_input("%s [%s] " % (prompt
, str(default
)))
47 if s
: return string
.atoi(s
)
50 def compare(local
, remote
, mode
):
52 print "PWD =", `os
.getcwd()`
53 sums_id
= remote
._send
('sumlist')
54 subdirs_id
= remote
._send
('listsubdirs')
56 print "calculating local sums ..."
58 for name
, info
in local
.sumlist():
60 print "getting remote sums ..."
61 sums
= remote
._recv
(sums_id
)
62 print "got", len(sums
)
64 for name
, rsum
in sums
:
66 if not lsumdict
.has_key(name
):
67 print `name`
, "only remote"
68 if 'r' in mode
and 'c' in mode
:
69 recvfile(local
, remote
, name
)
74 rmtime
= remote
.mtime(name
)
75 lmtime
= local
.mtime(name
)
79 recvfile(local
, remote
, name
)
83 sendfile(local
, remote
, name
)
85 print "same mtime but different sum?!?!",
87 for name
in lsumdict
.keys():
88 if not rsumdict
.keys():
89 print `name`
, "only locally",
91 if 'w' in mode
and 'c' in mode
:
92 sendfile(local
, remote
, name
)
93 elif 'r' in mode
and 'd' in mode
:
97 print "gettin subdirs ..."
98 subdirs
= remote
._recv
(subdirs_id
)
101 if local
.isdir(name
):
102 print "Common subdirectory", repr(name
)
105 print "Remote subdirectory", repr(name
), "not found locally"
106 if 'r' in mode
and 'c' in mode
:
107 pr
= "Create local subdirectory %s? [y] " % \
113 if ok
[:1] in ('y', 'Y'):
115 print "Subdirectory %s made" % \
118 lsubdirs
= local
.listsubdirs()
119 for name
in lsubdirs
:
120 if name
not in subdirs
:
121 print "Local subdirectory", repr(name
), "not found remotely"
123 print "Entering subdirectory", repr(name
)
126 compare(local
, remote
, mode
)
130 def sendfile(local
, remote
, name
):
133 except (IOError, os
.error
), msg
:
134 print "cannot create:", msg
140 data
= open(name
).read()
144 remote
._send
_noreply
('write', name
, data
)
150 print len(data
), "bytes in", round(dt
), "seconds",
152 print "i.e.", round(len(data
)/dt
), "bytes/sec",
155 def recvfile(local
, remote
, name
):
158 rv
= recvfile_real(local
, remote
, name
)
163 print "*** recvfile of %s failed, deleting" % `name`
166 def recvfile_real(local
, remote
, name
):
169 except (IOError, os
.error
), msg
:
170 print "cannot create:", msg
173 print "receiving ...",
181 id = remote
._send
('read', name
, offset
, length
)
184 newoffset
= offset
+ length
185 newid
= remote
._send
('read', name
, newoffset
, length
)
186 data
= remote
._recv
(id)
198 print size
, "bytes in", round(dt
), "seconds",
200 print "i.e.", int(size
/dt
), "bytes/sec",
202 remote
._recv
(id) # ignored
207 if __name__
== '__main__':