[svn r38196] reducing the callback-indirections for rsyncing

and improving the reporting for localhosts non-rsyncs

--HG--
branch : trunk
This commit is contained in:
hpk 2007-02-08 20:02:28 +01:00
parent 6e293f593a
commit 4976889c53
5 changed files with 30 additions and 28 deletions

View File

@ -87,24 +87,24 @@ class HostRSync(py.execnet.RSync):
else:
return True
def add_target_host(self, host, reporter=lambda x: None,
destrelpath="", finishedcallback=None):
remotepath = host.relpath
key = host.hostname, remotepath
if host.hostname == "localhost" and not remotepath:
p = py.path.local(host.gw_remotepath)
assert p.join(destrelpath) == self._sourcedir
self._synced[key] = True
if key in self._synced:
if finishedcallback:
finishedcallback()
return False
self._synced[key] = True
# the follow attributes are set from host.initgateway()
def add_target_host(self, host, destrelpath="", reporter=lambda x: None):
remotepath = host.gw_remotepath
key = host.hostname, host.relpath
if destrelpath:
remotepath = os.path.join(remotepath, destrelpath)
if host.hostname == "localhost" and remotepath == self._sourcedir:
self._synced[key] = True
synced = key in self._synced
reporter(repevent.HostRSyncing(host, self._sourcedir,
remotepath, synced))
def hostrsynced(host=host):
reporter(repevent.HostRSyncRootReady(host, self._sourcedir))
if key in self._synced:
hostrsynced()
return
self._synced[key] = True
super(HostRSync, self).add_target(host.gw, remotepath,
finishedcallback,
finishedcallback=hostrsynced,
delete=True,
)
return remotepath
@ -129,20 +129,15 @@ class HostManager(object):
host.gw.host = host
def init_rsync(self, reporter):
# send each rsync root
ignores = self.config.getvalue_pathlist("dist_rsync_ignore")
self.prepare_gateways(reporter)
# send each rsync root
for root in self.roots:
rsync = HostRSync(root, ignores=ignores,
verbose=self.config.option.verbose)
destrelpath = root.relto(self.config.topdir)
for host in self.hosts:
def donecallback(host, root):
reporter(repevent.HostRSyncRootReady(host, root))
remotepath = rsync.add_target_host(
host, reporter, destrelpath, finishedcallback=
lambda host=host, root=root: donecallback(host, root))
reporter(repevent.HostRSyncing(host, root, remotepath))
rsync.add_target_host(host, destrelpath, reporter)
rsync.send(raises=False)
def setup_hosts(self, reporter):

View File

@ -74,10 +74,11 @@ class CallFinish(CallEvent):
pass
class HostRSyncing(ReportEvent):
def __init__(self, host, root, remotepath):
def __init__(self, host, root, remotepath, synced):
self.host = host
self.root = root
self.remotepath = remotepath
self.synced = synced
class HostGatewayReady(ReportEvent):
def __init__(self, host, roots):

View File

@ -58,11 +58,16 @@ class AbstractReporter(object):
def report_HostRSyncing(self, item):
hostrepr = self._hostrepr(item.host)
if not item.remotepath:
print "%15s: skip duplicate rsync of %r" % (
hostrepr, item.root.basename)
if item.synced:
if (item.host.hostname == "localhost" and
item.root == item.remotepath):
print "%15s: skipping inplace rsync of %r" %(
hostrepr, item.remotepath)
else:
print "%15s: skip duplicate rsync to %r" % (
hostrepr, str(item.root))
else:
print "%15s: rsync %r to remote %s" % (hostrepr,
print "%15s: rsync %r to remote %r" % (hostrepr,
item.root.basename,
item.remotepath)

View File

@ -132,6 +132,7 @@ class TestSyncing(DirSetup):
rsync = HostRSync(self.source)
l = []
h1.initgateway()
h2.initgateway()
res1 = rsync.add_target_host(h1)
assert res1
res2 = rsync.add_target_host(h2)

View File

@ -53,7 +53,7 @@ class TestRestUnits(object):
def test_report_HostRSyncing(self):
event = repevent.HostRSyncing(HostInfo('localhost:/foo/bar'), "a",
"b")
"b", False)
reporter.report(event)
assert stdout.getvalue() == ('::\n\n localhost: RSYNC ==> '
'/foo/bar\n\n')