[svn r37990] Fix reporting (and a test for that)

--HG--
branch : trunk
This commit is contained in:
fijal 2007-02-06 00:53:29 +01:00
parent 9b6787782d
commit eb01cfa78e
2 changed files with 33 additions and 12 deletions

View File

@ -122,23 +122,31 @@ class HostManager(object):
host.initgateway(python=dist_remotepython) host.initgateway(python=dist_remotepython)
host.gw.host = host host.gw.host = host
def _send_rsync(self, root, reporter, ignores, make_callback=False):
rsync = HostRSync(ignores=ignores)
destrelpath = root.relto(self.config.topdir)
for host in self.hosts:
reporter(repevent.HostRSyncing(host))
if make_callback:
def donecallback():
reporter(repevent.HostReady(host))
else:
donecallback = None
rsync.add_target_host(host, destrelpath,
finishedcallback=donecallback)
rsync.send(root)
def init_rsync(self, reporter): def init_rsync(self, reporter):
# send each rsync root # send each rsync root
roots = self.config.getvalue_pathlist("dist_rsync_roots") roots = self.config.getvalue_pathlist("dist_rsync_roots")
ignores = self.config.getvalue_pathlist("dist_rsync_ignore") ignores = self.config.getvalue_pathlist("dist_rsync_ignore")
if roots is None: if roots is None:
roots = [self.config.topdir] roots = [self.config.topdir]
self.prepare_gateways() self.prepare_gateways()
rsync = HostRSync(ignores=ignores) for root in roots[:-1]:
for root in roots: self._send_rsync(root, reporter, ignores)
destrelpath = root.relto(self.config.topdir) self._send_rsync(roots[-1], reporter, ignores, True)
for host in self.hosts:
reporter(repevent.HostRSyncing(host))
def donecallback():
reporter(repevent.HostReady(host))
rsync.add_target_host(host, destrelpath,
finishedcallback=donecallback)
rsync.send(root)
def setup_hosts(self, reporter): def setup_hosts(self, reporter):
self.init_rsync(reporter) self.init_rsync(reporter)

View File

@ -4,7 +4,8 @@
import py import py
from py.__.test.rsession.hostmanage import HostRSync from py.__.test.rsession.hostmanage import HostRSync
from py.__.test.rsession.hostmanage import HostInfo, HostManager from py.__.test.rsession.hostmanage import HostInfo, HostManager
from py.__.test.rsession import repevent
class DirSetup: class DirSetup:
def setup_method(self, method): def setup_method(self, method):
@ -177,3 +178,15 @@ class TestHostManager(DirSetup):
assert self.dest.join("dir5","file").check() assert self.dest.join("dir5","file").check()
assert not self.dest.join("dir6").check() assert not self.dest.join("dir6").check()
def test_hostmanager_rsync_reported_once(self):
dir2 = self.source.ensure("dir1", "dir2", dir=1)
dir5 = self.source.ensure("dir5", "dir6", "bogus")
dirf = self.source.ensure("dir3", "file")
config = py.test.config._reparse([self.source])
hm = HostManager(config,
hosts=[HostInfo("localhost:" + str(self.dest))
for i in range(3)])
events = []
hm.init_rsync(reporter=events.append)
readies = [i for i in events if isinstance(i, repevent.HostReady)]
assert len(readies) == 3