[svn r38164] Move source as an rsync initialisation argument rather than

as a send parameter

--HG--
branch : trunk
This commit is contained in:
fijal 2007-02-08 16:31:38 +01:00
parent db4a19f473
commit 0e8510648f
4 changed files with 40 additions and 40 deletions

View File

@ -15,9 +15,10 @@ class RSync(object):
symlinks will be just copied (regardless of existance of such symlinks will be just copied (regardless of existance of such
a path on remote side). 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: for name in options:
assert name in ('delete') assert name in ('delete')
self._sourcedir = str(sourcedir)
self._options = options self._options = options
self._verbose = verbose self._verbose = verbose
assert callback is None or callable(callback) assert callback is None or callable(callback)
@ -92,13 +93,12 @@ class RSync(object):
if self._verbose: if self._verbose:
print '%s <= %s' % (gateway.remoteaddress, modified_rel_path) print '%s <= %s' % (gateway.remoteaddress, modified_rel_path)
def send(self, sourcedir): def send(self):
""" Sends a sourcedir to all added targets. """ Sends a sourcedir to all added targets.
""" """
if not self._channels: if not self._channels:
raise IOError("no targets available, maybe you " raise IOError("no targets available, maybe you "
"are trying call send() twice?") "are trying call send() twice?")
self._sourcedir = str(sourcedir)
# normalize a trailing '/' away # normalize a trailing '/' away
self._sourcedir = os.path.dirname(os.path.join(self._sourcedir, 'x')) self._sourcedir = os.path.dirname(os.path.join(self._sourcedir, 'x'))
# send directory structure and file timestamps/sizes # send directory structure and file timestamps/sizes

View File

@ -21,8 +21,8 @@ class DirSetup:
class TestRSync(DirSetup): class TestRSync(DirSetup):
def test_notargets(self): def test_notargets(self):
rsync = RSync() rsync = RSync(self.source)
py.test.raises(IOError, "rsync.send(self.source)") py.test.raises(IOError, "rsync.send()")
def test_dirsync(self): def test_dirsync(self):
dest = self.dest1 dest = self.dest1
@ -31,10 +31,10 @@ class TestRSync(DirSetup):
for s in ('content1', 'content2-a-bit-longer'): for s in ('content1', 'content2-a-bit-longer'):
source.ensure('subdir', 'file1').write(s) source.ensure('subdir', 'file1').write(s)
rsync = RSync() rsync = RSync(self.source)
rsync.add_target(gw, dest) rsync.add_target(gw, dest)
rsync.add_target(gw2, dest2) rsync.add_target(gw2, dest2)
rsync.send(source) rsync.send()
assert dest.join('subdir').check(dir=1) assert dest.join('subdir').check(dir=1)
assert dest.join('subdir', 'file1').check(file=1) assert dest.join('subdir', 'file1').check(file=1)
assert dest.join('subdir', 'file1').read() == s assert dest.join('subdir', 'file1').read() == s
@ -43,40 +43,40 @@ class TestRSync(DirSetup):
assert dest2.join('subdir', 'file1').read() == s assert dest2.join('subdir', 'file1').read() == s
source.join('subdir').remove('file1') source.join('subdir').remove('file1')
rsync = RSync() rsync = RSync(source)
rsync.add_target(gw2, dest2) rsync.add_target(gw2, dest2)
rsync.add_target(gw, dest) rsync.add_target(gw, dest)
rsync.send(source) rsync.send()
assert dest.join('subdir', 'file1').check(file=1) assert dest.join('subdir', 'file1').check(file=1)
assert dest2.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(gw2, dest2)
rsync.add_target(gw, dest) rsync.add_target(gw, dest)
rsync.send(source) rsync.send()
assert not dest.join('subdir', 'file1').check() assert not dest.join('subdir', 'file1').check()
assert not dest2.join('subdir', 'file1').check() assert not dest2.join('subdir', 'file1').check()
def test_dirsync_twice(self): def test_dirsync_twice(self):
source = self.source source = self.source
source.ensure("hello") source.ensure("hello")
rsync = RSync() rsync = RSync(source)
rsync.add_target(gw, self.dest1) rsync.add_target(gw, self.dest1)
rsync.send(self.source) rsync.send()
assert self.dest1.join('hello').check() 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.add_target(gw, self.dest2)
rsync.send(self.source) rsync.send()
assert self.dest2.join('hello').check() 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): def test_rsync_default_reporting(self):
source = self.source source = self.source
source.ensure("hello") source.ensure("hello")
cap = py.io.StdCapture() cap = py.io.StdCapture()
try: try:
rsync = RSync() rsync = RSync(source)
rsync.add_target(gw, self.dest1) rsync.add_target(gw, self.dest1)
rsync.send(self.source) rsync.send()
finally: finally:
out, err = cap.reset() out, err = cap.reset()
assert out.find("hello") != -1 assert out.find("hello") != -1
@ -86,9 +86,9 @@ class TestRSync(DirSetup):
source.ensure("hello") source.ensure("hello")
cap = py.io.StdCapture() cap = py.io.StdCapture()
try: try:
rsync = RSync(verbose=False) rsync = RSync(source, verbose=False)
rsync.add_target(gw, self.dest1) rsync.add_target(gw, self.dest1)
rsync.send(self.source) rsync.send()
finally: finally:
out, err = cap.reset() out, err = cap.reset()
assert not out assert not out
@ -103,10 +103,10 @@ class TestRSync(DirSetup):
source.join("rellink").mksymlinkto(source.join("existant"), absolute=0) source.join("rellink").mksymlinkto(source.join("existant"), absolute=0)
source.join('abslink').mksymlinkto(source.join("existant")) source.join('abslink').mksymlinkto(source.join("existant"))
rsync = RSync() rsync = RSync(source)
rsync.add_target(gw, dest) rsync.add_target(gw, dest)
rsync.send(source) rsync.send()
assert dest.join('rellink').readlink() == dest.join("existant") assert dest.join('rellink').readlink() == dest.join("existant")
assert dest.join('abslink').readlink() == dest.join("existant") assert dest.join('abslink').readlink() == dest.join("existant")
@ -119,10 +119,10 @@ class TestRSync(DirSetup):
def callback(cmd, lgt, channel): def callback(cmd, lgt, channel):
total[(cmd, lgt)] = True total[(cmd, lgt)] = True
rsync = RSync(callback=callback) rsync = RSync(source, callback=callback)
#rsync = RSync() #rsync = RSync()
rsync.add_target(gw, dest) rsync.add_target(gw, dest)
rsync.send(source) rsync.send()
assert total == {("list", 110):True, ("ack", 100):True, ("ack", 10):True} assert total == {("list", 110):True, ("ack", 100):True, ("ack", 10):True}
@ -140,9 +140,9 @@ class TestRSync(DirSetup):
source.join("ex2").remove() source.join("ex2").remove()
return True return True
rsync = DRsync() rsync = DRsync(source)
rsync.add_target(gw, dest) rsync.add_target(gw, dest)
rsync.send(source) rsync.send()
assert rsync.x == 1 assert rsync.x == 1
assert len(dest.listdir()) == 1 assert len(dest.listdir()) == 1
assert len(source.listdir()) == 1 assert len(source.listdir()) == 1

View File

@ -67,14 +67,14 @@ class HostInfo(object):
class HostRSync(py.execnet.RSync): class HostRSync(py.execnet.RSync):
""" RSyncer that filters out common files """ RSyncer that filters out common files
""" """
def __init__(self, *args, **kwargs): def __init__(self, source, *args, **kwargs):
self._synced = {} self._synced = {}
ignores= None ignores= None
if 'ignores' in kwargs: if 'ignores' in kwargs:
ignores = kwargs.pop('ignores') ignores = kwargs.pop('ignores')
self._ignores = ignores or [] self._ignores = ignores or []
kwargs['delete'] = True kwargs['delete'] = True
super(HostRSync, self).__init__(**kwargs) super(HostRSync, self).__init__(source, **kwargs)
def filter(self, path): def filter(self, path):
path = py.path.local(path) path = py.path.local(path)
@ -129,7 +129,7 @@ class HostManager(object):
ignores = self.config.getvalue_pathlist("dist_rsync_ignore") ignores = self.config.getvalue_pathlist("dist_rsync_ignore")
self.prepare_gateways(reporter) self.prepare_gateways(reporter)
for root in self.roots: for root in self.roots:
rsync = HostRSync(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:
@ -139,7 +139,7 @@ class HostManager(object):
host, reporter, destrelpath, finishedcallback= host, reporter, destrelpath, finishedcallback=
lambda host=host, root=root: donecallback(host, root)) lambda host=host, root=root: donecallback(host, root))
reporter(repevent.HostRSyncing(host, root, remotepath)) reporter(repevent.HostRSyncing(host, root, remotepath))
rsync.send(root) rsync.send()
def setup_hosts(self, reporter): def setup_hosts(self, reporter):
self.init_rsync(reporter) self.init_rsync(reporter)
@ -170,12 +170,12 @@ class HostManager(object):
def teardown_gateways(self, reporter, channels): def teardown_gateways(self, reporter, channels):
for channel in channels: for channel in channels:
#try:
try: try:
repevent.wrapcall(reporter, channel.waitclose) repevent.wrapcall(reporter, channel.waitclose, 1)
except KeyboardInterrupt, SystemExit: except IOError: # timeout
raise # force closing
except: channel.close()
pass
channel.gateway.exit() channel.gateway.exit()
def gethomedir(): def gethomedir():

View File

@ -106,7 +106,7 @@ class TestSyncing(DirSetup):
self.source.ensure(".svn", "entries") self.source.ensure(".svn", "entries")
self.source.ensure(".somedotfile", "moreentries") self.source.ensure(".somedotfile", "moreentries")
self.source.ensure("somedir", "editfile~") self.source.ensure("somedir", "editfile~")
syncer = HostRSync() syncer = HostRSync(self.source)
l = list(self.source.visit(rec=syncer.filter, l = list(self.source.visit(rec=syncer.filter,
fil=syncer.filter)) fil=syncer.filter))
assert len(l) == 3 assert len(l) == 3
@ -118,18 +118,18 @@ class TestSyncing(DirSetup):
def test_hrsync_one_host(self): def test_hrsync_one_host(self):
h1 = self._gethostinfo() h1 = self._gethostinfo()
finished = [] finished = []
rsync = HostRSync() rsync = HostRSync(self.source)
h1.initgateway() h1.initgateway()
rsync.add_target_host(h1) rsync.add_target_host(h1)
self.source.join("hello.py").write("world") self.source.join("hello.py").write("world")
rsync.send(self.source) rsync.send()
assert self.dest.join("hello.py").check() assert self.dest.join("hello.py").check()
def test_hrsync_same_host_twice(self): def test_hrsync_same_host_twice(self):
h1 = self._gethostinfo() h1 = self._gethostinfo()
h2 = self._gethostinfo() h2 = self._gethostinfo()
finished = [] finished = []
rsync = HostRSync() rsync = HostRSync(self.source)
l = [] l = []
h1.initgateway() h1.initgateway()
res1 = rsync.add_target_host(h1) res1 = rsync.add_target_host(h1)