[svn r38028] make rsync configurable regarding its output

(verbose option and overridable method)

--HG--
branch : trunk
This commit is contained in:
hpk 2007-02-06 20:32:21 +01:00
parent ef43218016
commit 4369d430c8
2 changed files with 32 additions and 4 deletions

View File

@ -15,10 +15,11 @@ class RSync(object):
symlinks will be just copied (regardless of existance of such
a path on remote side).
"""
def __init__(self, callback=None, **options):
def __init__(self, callback=None, verbose=True, **options):
for name in options:
assert name in ('delete')
self._options = options
self._verbose = verbose
assert callback is None or callable(callback)
self._callback = callback
self._channels = {}
@ -84,11 +85,13 @@ class RSync(object):
# ! there is a reason for the interning:
# sharing multiple copies of the file's data
data = intern(data)
print '%s <= %s' % (
channel.gateway.remoteaddress,
modified_rel_path)
self._report_send_file(channel.gateway, modified_rel_path)
channel.send(data)
def _report_send_file(self, gateway, modified_rel_path):
if self._verbose:
print '%s <= %s' % (gateway.remoteaddress, modified_rel_path)
def send(self, sourcedir):
""" Sends a sourcedir to all added targets.
"""

View File

@ -69,6 +69,31 @@ class TestRSync(DirSetup):
assert self.dest2.join('hello').check()
py.test.raises(IOError, "rsync.send(self.source)")
def test_rsync_default_reporting(self):
source = self.source
source.ensure("hello")
cap = py.io.StdCapture()
try:
rsync = RSync()
rsync.add_target(gw, self.dest1)
rsync.send(self.source)
finally:
out, err = cap.reset()
assert out.find("hello") != -1
def test_rsync_non_verbose(self):
source = self.source
source.ensure("hello")
cap = py.io.StdCapture()
try:
rsync = RSync(verbose=False)
rsync.add_target(gw, self.dest1)
rsync.send(self.source)
finally:
out, err = cap.reset()
assert not out
assert not err
def test_symlink_rsync(self):
if py.std.sys.platform == 'win32':
py.test.skip("symlinks are unsupported on Windows.")