diff --git a/py/execnet/rsync.py b/py/execnet/rsync.py index aa0741966..665f5e5fb 100644 --- a/py/execnet/rsync.py +++ b/py/execnet/rsync.py @@ -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. """ diff --git a/py/execnet/testing/test_rsync.py b/py/execnet/testing/test_rsync.py index 1a35ba5ba..a982cd458 100644 --- a/py/execnet/testing/test_rsync.py +++ b/py/execnet/testing/test_rsync.py @@ -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.")