[svn r38196] reducing the callback-indirections for rsyncing
and improving the reporting for localhosts non-rsyncs --HG-- branch : trunk
This commit is contained in:
parent
6e293f593a
commit
4976889c53
|
@ -87,24 +87,24 @@ class HostRSync(py.execnet.RSync):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def add_target_host(self, host, reporter=lambda x: None,
|
def add_target_host(self, host, destrelpath="", reporter=lambda x: None):
|
||||||
destrelpath="", finishedcallback=None):
|
remotepath = host.gw_remotepath
|
||||||
remotepath = host.relpath
|
key = host.hostname, 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()
|
|
||||||
if destrelpath:
|
if destrelpath:
|
||||||
remotepath = os.path.join(remotepath, 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,
|
super(HostRSync, self).add_target(host.gw, remotepath,
|
||||||
finishedcallback,
|
finishedcallback=hostrsynced,
|
||||||
delete=True,
|
delete=True,
|
||||||
)
|
)
|
||||||
return remotepath
|
return remotepath
|
||||||
|
@ -129,20 +129,15 @@ class HostManager(object):
|
||||||
host.gw.host = host
|
host.gw.host = host
|
||||||
|
|
||||||
def init_rsync(self, reporter):
|
def init_rsync(self, reporter):
|
||||||
# send each rsync root
|
|
||||||
ignores = self.config.getvalue_pathlist("dist_rsync_ignore")
|
ignores = self.config.getvalue_pathlist("dist_rsync_ignore")
|
||||||
self.prepare_gateways(reporter)
|
self.prepare_gateways(reporter)
|
||||||
|
# send each rsync root
|
||||||
for root in self.roots:
|
for root in self.roots:
|
||||||
rsync = HostRSync(root, ignores=ignores,
|
rsync = HostRSync(root, ignores=ignores,
|
||||||
verbose=self.config.option.verbose)
|
verbose=self.config.option.verbose)
|
||||||
destrelpath = root.relto(self.config.topdir)
|
destrelpath = root.relto(self.config.topdir)
|
||||||
for host in self.hosts:
|
for host in self.hosts:
|
||||||
def donecallback(host, root):
|
rsync.add_target_host(host, destrelpath, reporter)
|
||||||
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.send(raises=False)
|
rsync.send(raises=False)
|
||||||
|
|
||||||
def setup_hosts(self, reporter):
|
def setup_hosts(self, reporter):
|
||||||
|
|
|
@ -74,10 +74,11 @@ class CallFinish(CallEvent):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class HostRSyncing(ReportEvent):
|
class HostRSyncing(ReportEvent):
|
||||||
def __init__(self, host, root, remotepath):
|
def __init__(self, host, root, remotepath, synced):
|
||||||
self.host = host
|
self.host = host
|
||||||
self.root = root
|
self.root = root
|
||||||
self.remotepath = remotepath
|
self.remotepath = remotepath
|
||||||
|
self.synced = synced
|
||||||
|
|
||||||
class HostGatewayReady(ReportEvent):
|
class HostGatewayReady(ReportEvent):
|
||||||
def __init__(self, host, roots):
|
def __init__(self, host, roots):
|
||||||
|
|
|
@ -58,11 +58,16 @@ class AbstractReporter(object):
|
||||||
|
|
||||||
def report_HostRSyncing(self, item):
|
def report_HostRSyncing(self, item):
|
||||||
hostrepr = self._hostrepr(item.host)
|
hostrepr = self._hostrepr(item.host)
|
||||||
if not item.remotepath:
|
if item.synced:
|
||||||
print "%15s: skip duplicate rsync of %r" % (
|
if (item.host.hostname == "localhost" and
|
||||||
hostrepr, item.root.basename)
|
item.root == item.remotepath):
|
||||||
|
print "%15s: skipping inplace rsync of %r" %(
|
||||||
|
hostrepr, item.remotepath)
|
||||||
else:
|
else:
|
||||||
print "%15s: rsync %r to remote %s" % (hostrepr,
|
print "%15s: skip duplicate rsync to %r" % (
|
||||||
|
hostrepr, str(item.root))
|
||||||
|
else:
|
||||||
|
print "%15s: rsync %r to remote %r" % (hostrepr,
|
||||||
item.root.basename,
|
item.root.basename,
|
||||||
item.remotepath)
|
item.remotepath)
|
||||||
|
|
||||||
|
|
|
@ -132,6 +132,7 @@ class TestSyncing(DirSetup):
|
||||||
rsync = HostRSync(self.source)
|
rsync = HostRSync(self.source)
|
||||||
l = []
|
l = []
|
||||||
h1.initgateway()
|
h1.initgateway()
|
||||||
|
h2.initgateway()
|
||||||
res1 = rsync.add_target_host(h1)
|
res1 = rsync.add_target_host(h1)
|
||||||
assert res1
|
assert res1
|
||||||
res2 = rsync.add_target_host(h2)
|
res2 = rsync.add_target_host(h2)
|
||||||
|
|
|
@ -53,7 +53,7 @@ class TestRestUnits(object):
|
||||||
|
|
||||||
def test_report_HostRSyncing(self):
|
def test_report_HostRSyncing(self):
|
||||||
event = repevent.HostRSyncing(HostInfo('localhost:/foo/bar'), "a",
|
event = repevent.HostRSyncing(HostInfo('localhost:/foo/bar'), "a",
|
||||||
"b")
|
"b", False)
|
||||||
reporter.report(event)
|
reporter.report(event)
|
||||||
assert stdout.getvalue() == ('::\n\n localhost: RSYNC ==> '
|
assert stdout.getvalue() == ('::\n\n localhost: RSYNC ==> '
|
||||||
'/foo/bar\n\n')
|
'/foo/bar\n\n')
|
||||||
|
|
Loading…
Reference in New Issue