[svn r38176] make delete a per-host option (internally it is anyway)

--HG--
branch : trunk
This commit is contained in:
hpk 2007-02-08 17:04:58 +01:00
parent c18ab8fd7e
commit 7fccd77b8a
3 changed files with 14 additions and 17 deletions

View File

@ -3,23 +3,16 @@ from Queue import Queue
class RSync(object): class RSync(object):
""" This class allows to synchronise files and directories """ This class allows to send a directory structure (recursively)
with one or multiple remote filesystems. to one or multiple remote filesystems.
An RSync instance allows to dynamically add remote targets
and then synchronizes the remote filesystems with
any provided source directory.
There is limited support for symlinks, which means that symlinks There is limited support for symlinks, which means that symlinks
pointing to the sourcetree will be send "as is" while external pointing to the sourcetree will be send "as is" while external
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, sourcedir, callback=None, verbose=True, **options): def __init__(self, sourcedir, callback=None, verbose=True):
for name in options:
assert name in ('delete')
self._sourcedir = str(sourcedir) self._sourcedir = str(sourcedir)
self._options = options
self._verbose = verbose self._verbose = verbose
assert callback is None or callable(callback) assert callback is None or callable(callback)
self._callback = callback self._callback = callback
@ -135,16 +128,19 @@ class RSync(object):
else: else:
assert "Unknown command %s" % command assert "Unknown command %s" % command
def add_target(self, gateway, destdir, finishedcallback=None): def add_target(self, gateway, destdir,
finishedcallback=None, **options):
""" Adds a remote target specified via a 'gateway' """ Adds a remote target specified via a 'gateway'
and a remote destination directory. and a remote destination directory.
""" """
assert finishedcallback is None or callable(finishedcallback) assert finishedcallback is None or callable(finishedcallback)
for name in options:
assert name in ('delete',)
def itemcallback(req): def itemcallback(req):
self._receivequeue.put((channel, req)) self._receivequeue.put((channel, req))
channel = gateway.remote_exec(REMOTE_SOURCE) channel = gateway.remote_exec(REMOTE_SOURCE)
channel.setcallback(itemcallback, endmarker = None) channel.setcallback(itemcallback, endmarker = None)
channel.send((str(destdir), self._options)) channel.send((str(destdir), options))
self._channels[channel] = finishedcallback self._channels[channel] = finishedcallback
def _broadcast(self, msg): def _broadcast(self, msg):

View File

@ -50,12 +50,12 @@ class TestRSync(DirSetup):
rsync.send() 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(source, delete=True) rsync = RSync(source)
rsync.add_target(gw, dest, delete=True)
rsync.add_target(gw2, dest2) rsync.add_target(gw2, dest2)
rsync.add_target(gw, dest)
rsync.send() rsync.send()
assert not dest.join('subdir', 'file1').check() assert not dest.join('subdir', 'file1').check()
assert not dest2.join('subdir', 'file1').check() assert dest2.join('subdir', 'file1').check()
def test_dirsync_twice(self): def test_dirsync_twice(self):
source = self.source source = self.source

View File

@ -77,7 +77,6 @@ class HostRSync(py.execnet.RSync):
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
super(HostRSync, self).__init__(source, **kwargs) super(HostRSync, self).__init__(source, **kwargs)
def filter(self, path): def filter(self, path):
@ -106,7 +105,9 @@ class HostRSync(py.execnet.RSync):
remotepath = os.path.join(remotepath, destrelpath) remotepath = os.path.join(remotepath, destrelpath)
super(HostRSync, self).add_target(gw, super(HostRSync, self).add_target(gw,
remotepath, remotepath,
finishedcallback) finishedcallback,
delete=True,
)
return remotepath return remotepath
class HostManager(object): class HostManager(object):