[svn r38173] * Minor semantics change, now host and host: are the same (we don't

want to rsync to home dir usually)
* Make a flag rsync_flag in hostinfo which tells whether to rsync
  or no, semantics are that in case of localhost we do not rsync
  and in case of localhost: we do.

--HG--
branch : trunk
This commit is contained in:
fijal 2007-02-08 16:56:33 +01:00
parent 120dae7749
commit 27cf3997e3
2 changed files with 26 additions and 8 deletions

View File

@ -17,10 +17,14 @@ class HostInfo(object):
def __init__(self, spec):
parts = spec.split(':', 1)
self.hostname = parts.pop(0)
if parts:
if parts and parts[0]:
self.relpath = parts[0]
else:
self.relpath = "pytestcache-" + self.hostname
self.relpath = "pytestcache-" + self.hostname
if spec.find(':') == -1 and self.hostname == 'localhost':
self.rsync_flag = False
else:
self.rsync_flag = True
self.hostid = self._getuniqueid(self.hostname)
def _getuniqueid(self, hostname):
@ -90,7 +94,7 @@ class HostRSync(py.execnet.RSync):
def add_target_host(self, host, reporter=lambda x: None,
destrelpath=None, finishedcallback=None):
key = host.hostname, host.relpath
if key in self._synced:
if not host.rsync_flag or key in self._synced:
if finishedcallback:
finishedcallback()
return False
@ -139,7 +143,7 @@ class HostManager(object):
host, reporter, destrelpath, finishedcallback=
lambda host=host, root=root: donecallback(host, root))
reporter(repevent.HostRSyncing(host, root, remotepath))
rsync.send()
rsync.send_if_targets()
def setup_hosts(self, reporter):
self.init_rsync(reporter)

View File

@ -24,7 +24,7 @@ class TestHostInfo(DirSetup):
return hostinfo
def test_defaultpath(self):
x = HostInfo("localhost")
x = HostInfo("localhost:")
assert x.hostname == "localhost"
assert x.relpath == "pytestcache-" + x.hostname
@ -34,11 +34,11 @@ class TestHostInfo(DirSetup):
assert x.hostname == "localhost"
def test_hostid(self):
x = HostInfo("localhost")
y = HostInfo("localhost")
x = HostInfo("localhost:")
y = HostInfo("localhost:")
assert x.hostid != y.hostid
x = HostInfo("localhost:/tmp")
y = HostInfo("localhost")
y = HostInfo("localhost:")
assert x.hostid != y.hostid
def test_non_existing_hosts(self):
@ -192,6 +192,20 @@ class TestHostManager(DirSetup):
assert self.dest.join("dir5","file").check()
assert not self.dest.join("dir6").check()
def test_hostmanage_optimise_localhost(self):
def add_target(self, a, b, c):
assert 0, "Should not rsync here"
try:
config = py.test.config._reparse([self.source])
old_add_target = HostRSync.add_target
HostRSync.add_target = add_target
hm = HostManager(config, hosts=[HostInfo('localhost') for i in
range(3)])
events = []
hm.init_rsync(reporter=events.append)
finally:
HostRSync.add_target = old_add_target
def test_getpath_relto_home():
x = getpath_relto_home("hello")
assert x == py.path.local._gethomedir().join("hello")