[svn r38164] Move source as an rsync initialisation argument rather than
as a send parameter --HG-- branch : trunk
This commit is contained in:
parent
db4a19f473
commit
0e8510648f
|
@ -15,9 +15,10 @@ class RSync(object):
|
|||
symlinks will be just copied (regardless of existance of such
|
||||
a path on remote side).
|
||||
"""
|
||||
def __init__(self, callback=None, verbose=True, **options):
|
||||
def __init__(self, sourcedir, callback=None, verbose=True, **options):
|
||||
for name in options:
|
||||
assert name in ('delete')
|
||||
self._sourcedir = str(sourcedir)
|
||||
self._options = options
|
||||
self._verbose = verbose
|
||||
assert callback is None or callable(callback)
|
||||
|
@ -92,13 +93,12 @@ class RSync(object):
|
|||
if self._verbose:
|
||||
print '%s <= %s' % (gateway.remoteaddress, modified_rel_path)
|
||||
|
||||
def send(self, sourcedir):
|
||||
def send(self):
|
||||
""" Sends a sourcedir to all added targets.
|
||||
"""
|
||||
if not self._channels:
|
||||
raise IOError("no targets available, maybe you "
|
||||
"are trying call send() twice?")
|
||||
self._sourcedir = str(sourcedir)
|
||||
# normalize a trailing '/' away
|
||||
self._sourcedir = os.path.dirname(os.path.join(self._sourcedir, 'x'))
|
||||
# send directory structure and file timestamps/sizes
|
||||
|
|
|
@ -21,8 +21,8 @@ class DirSetup:
|
|||
|
||||
class TestRSync(DirSetup):
|
||||
def test_notargets(self):
|
||||
rsync = RSync()
|
||||
py.test.raises(IOError, "rsync.send(self.source)")
|
||||
rsync = RSync(self.source)
|
||||
py.test.raises(IOError, "rsync.send()")
|
||||
|
||||
def test_dirsync(self):
|
||||
dest = self.dest1
|
||||
|
@ -31,10 +31,10 @@ class TestRSync(DirSetup):
|
|||
|
||||
for s in ('content1', 'content2-a-bit-longer'):
|
||||
source.ensure('subdir', 'file1').write(s)
|
||||
rsync = RSync()
|
||||
rsync = RSync(self.source)
|
||||
rsync.add_target(gw, dest)
|
||||
rsync.add_target(gw2, dest2)
|
||||
rsync.send(source)
|
||||
rsync.send()
|
||||
assert dest.join('subdir').check(dir=1)
|
||||
assert dest.join('subdir', 'file1').check(file=1)
|
||||
assert dest.join('subdir', 'file1').read() == s
|
||||
|
@ -43,40 +43,40 @@ class TestRSync(DirSetup):
|
|||
assert dest2.join('subdir', 'file1').read() == s
|
||||
|
||||
source.join('subdir').remove('file1')
|
||||
rsync = RSync()
|
||||
rsync = RSync(source)
|
||||
rsync.add_target(gw2, dest2)
|
||||
rsync.add_target(gw, dest)
|
||||
rsync.send(source)
|
||||
rsync.send()
|
||||
assert dest.join('subdir', 'file1').check(file=1)
|
||||
assert dest2.join('subdir', 'file1').check(file=1)
|
||||
rsync = RSync(delete=True)
|
||||
rsync = RSync(source, delete=True)
|
||||
rsync.add_target(gw2, dest2)
|
||||
rsync.add_target(gw, dest)
|
||||
rsync.send(source)
|
||||
rsync.send()
|
||||
assert not dest.join('subdir', 'file1').check()
|
||||
assert not dest2.join('subdir', 'file1').check()
|
||||
|
||||
def test_dirsync_twice(self):
|
||||
source = self.source
|
||||
source.ensure("hello")
|
||||
rsync = RSync()
|
||||
rsync = RSync(source)
|
||||
rsync.add_target(gw, self.dest1)
|
||||
rsync.send(self.source)
|
||||
rsync.send()
|
||||
assert self.dest1.join('hello').check()
|
||||
py.test.raises(IOError, "rsync.send(self.source)")
|
||||
py.test.raises(IOError, "rsync.send()")
|
||||
rsync.add_target(gw, self.dest2)
|
||||
rsync.send(self.source)
|
||||
rsync.send()
|
||||
assert self.dest2.join('hello').check()
|
||||
py.test.raises(IOError, "rsync.send(self.source)")
|
||||
py.test.raises(IOError, "rsync.send()")
|
||||
|
||||
def test_rsync_default_reporting(self):
|
||||
source = self.source
|
||||
source.ensure("hello")
|
||||
cap = py.io.StdCapture()
|
||||
try:
|
||||
rsync = RSync()
|
||||
rsync = RSync(source)
|
||||
rsync.add_target(gw, self.dest1)
|
||||
rsync.send(self.source)
|
||||
rsync.send()
|
||||
finally:
|
||||
out, err = cap.reset()
|
||||
assert out.find("hello") != -1
|
||||
|
@ -86,9 +86,9 @@ class TestRSync(DirSetup):
|
|||
source.ensure("hello")
|
||||
cap = py.io.StdCapture()
|
||||
try:
|
||||
rsync = RSync(verbose=False)
|
||||
rsync = RSync(source, verbose=False)
|
||||
rsync.add_target(gw, self.dest1)
|
||||
rsync.send(self.source)
|
||||
rsync.send()
|
||||
finally:
|
||||
out, err = cap.reset()
|
||||
assert not out
|
||||
|
@ -103,10 +103,10 @@ class TestRSync(DirSetup):
|
|||
source.join("rellink").mksymlinkto(source.join("existant"), absolute=0)
|
||||
source.join('abslink').mksymlinkto(source.join("existant"))
|
||||
|
||||
rsync = RSync()
|
||||
rsync = RSync(source)
|
||||
rsync.add_target(gw, dest)
|
||||
rsync.send(source)
|
||||
|
||||
rsync.send()
|
||||
|
||||
assert dest.join('rellink').readlink() == dest.join("existant")
|
||||
assert dest.join('abslink').readlink() == dest.join("existant")
|
||||
|
||||
|
@ -119,10 +119,10 @@ class TestRSync(DirSetup):
|
|||
def callback(cmd, lgt, channel):
|
||||
total[(cmd, lgt)] = True
|
||||
|
||||
rsync = RSync(callback=callback)
|
||||
rsync = RSync(source, callback=callback)
|
||||
#rsync = RSync()
|
||||
rsync.add_target(gw, dest)
|
||||
rsync.send(source)
|
||||
rsync.send()
|
||||
|
||||
assert total == {("list", 110):True, ("ack", 100):True, ("ack", 10):True}
|
||||
|
||||
|
@ -140,9 +140,9 @@ class TestRSync(DirSetup):
|
|||
source.join("ex2").remove()
|
||||
return True
|
||||
|
||||
rsync = DRsync()
|
||||
rsync = DRsync(source)
|
||||
rsync.add_target(gw, dest)
|
||||
rsync.send(source)
|
||||
rsync.send()
|
||||
assert rsync.x == 1
|
||||
assert len(dest.listdir()) == 1
|
||||
assert len(source.listdir()) == 1
|
||||
|
|
|
@ -67,14 +67,14 @@ class HostInfo(object):
|
|||
class HostRSync(py.execnet.RSync):
|
||||
""" RSyncer that filters out common files
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, source, *args, **kwargs):
|
||||
self._synced = {}
|
||||
ignores= None
|
||||
if 'ignores' in kwargs:
|
||||
ignores = kwargs.pop('ignores')
|
||||
self._ignores = ignores or []
|
||||
kwargs['delete'] = True
|
||||
super(HostRSync, self).__init__(**kwargs)
|
||||
super(HostRSync, self).__init__(source, **kwargs)
|
||||
|
||||
def filter(self, path):
|
||||
path = py.path.local(path)
|
||||
|
@ -129,7 +129,7 @@ class HostManager(object):
|
|||
ignores = self.config.getvalue_pathlist("dist_rsync_ignore")
|
||||
self.prepare_gateways(reporter)
|
||||
for root in self.roots:
|
||||
rsync = HostRSync(ignores=ignores,
|
||||
rsync = HostRSync(root, ignores=ignores,
|
||||
verbose=self.config.option.verbose)
|
||||
destrelpath = root.relto(self.config.topdir)
|
||||
for host in self.hosts:
|
||||
|
@ -139,7 +139,7 @@ class HostManager(object):
|
|||
host, reporter, destrelpath, finishedcallback=
|
||||
lambda host=host, root=root: donecallback(host, root))
|
||||
reporter(repevent.HostRSyncing(host, root, remotepath))
|
||||
rsync.send(root)
|
||||
rsync.send()
|
||||
|
||||
def setup_hosts(self, reporter):
|
||||
self.init_rsync(reporter)
|
||||
|
@ -170,12 +170,12 @@ class HostManager(object):
|
|||
|
||||
def teardown_gateways(self, reporter, channels):
|
||||
for channel in channels:
|
||||
#try:
|
||||
try:
|
||||
repevent.wrapcall(reporter, channel.waitclose)
|
||||
except KeyboardInterrupt, SystemExit:
|
||||
raise
|
||||
except:
|
||||
pass
|
||||
repevent.wrapcall(reporter, channel.waitclose, 1)
|
||||
except IOError: # timeout
|
||||
# force closing
|
||||
channel.close()
|
||||
channel.gateway.exit()
|
||||
|
||||
def gethomedir():
|
||||
|
|
|
@ -106,7 +106,7 @@ class TestSyncing(DirSetup):
|
|||
self.source.ensure(".svn", "entries")
|
||||
self.source.ensure(".somedotfile", "moreentries")
|
||||
self.source.ensure("somedir", "editfile~")
|
||||
syncer = HostRSync()
|
||||
syncer = HostRSync(self.source)
|
||||
l = list(self.source.visit(rec=syncer.filter,
|
||||
fil=syncer.filter))
|
||||
assert len(l) == 3
|
||||
|
@ -118,18 +118,18 @@ class TestSyncing(DirSetup):
|
|||
def test_hrsync_one_host(self):
|
||||
h1 = self._gethostinfo()
|
||||
finished = []
|
||||
rsync = HostRSync()
|
||||
rsync = HostRSync(self.source)
|
||||
h1.initgateway()
|
||||
rsync.add_target_host(h1)
|
||||
self.source.join("hello.py").write("world")
|
||||
rsync.send(self.source)
|
||||
rsync.send()
|
||||
assert self.dest.join("hello.py").check()
|
||||
|
||||
def test_hrsync_same_host_twice(self):
|
||||
h1 = self._gethostinfo()
|
||||
h2 = self._gethostinfo()
|
||||
finished = []
|
||||
rsync = HostRSync()
|
||||
rsync = HostRSync(self.source)
|
||||
l = []
|
||||
h1.initgateway()
|
||||
res1 = rsync.add_target_host(h1)
|
||||
|
|
Loading…
Reference in New Issue