2007-01-24 22:24:01 +08:00
|
|
|
import py
|
2007-01-25 00:46:46 +08:00
|
|
|
from py.execnet import RSync
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
def setup_module(mod):
|
|
|
|
mod.gw = py.execnet.PopenGateway()
|
|
|
|
mod.gw2 = py.execnet.PopenGateway()
|
|
|
|
|
|
|
|
def teardown_module(mod):
|
|
|
|
mod.gw.exit()
|
|
|
|
mod.gw2.exit()
|
|
|
|
|
|
|
|
|
2007-02-05 20:55:31 +08:00
|
|
|
class DirSetup:
|
|
|
|
def setup_method(self, method):
|
|
|
|
name = "%s.%s" %(self.__class__.__name__, method.func_name)
|
|
|
|
self.tmpdir = t = py.test.ensuretemp(name)
|
|
|
|
self.source = t.join("source")
|
|
|
|
self.dest1 = t.join("dest1")
|
|
|
|
self.dest2 = t.join("dest2")
|
|
|
|
|
|
|
|
class TestRSync(DirSetup):
|
|
|
|
def test_notargets(self):
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync = RSync(self.source)
|
|
|
|
py.test.raises(IOError, "rsync.send()")
|
2007-02-09 00:01:51 +08:00
|
|
|
assert rsync.send(raises=False) is None
|
2007-02-05 20:55:31 +08:00
|
|
|
|
|
|
|
def test_dirsync(self):
|
|
|
|
dest = self.dest1
|
|
|
|
dest2 = self.dest2
|
|
|
|
source = self.source
|
|
|
|
|
2009-03-04 01:42:32 +08:00
|
|
|
for s in ('content1', 'content2', 'content2-a-bit-longer'):
|
2007-02-05 20:55:31 +08:00
|
|
|
source.ensure('subdir', 'file1').write(s)
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync = RSync(self.source)
|
2007-02-05 20:55:31 +08:00
|
|
|
rsync.add_target(gw, dest)
|
|
|
|
rsync.add_target(gw2, dest2)
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync.send()
|
2007-02-05 20:55:31 +08:00
|
|
|
assert dest.join('subdir').check(dir=1)
|
|
|
|
assert dest.join('subdir', 'file1').check(file=1)
|
|
|
|
assert dest.join('subdir', 'file1').read() == s
|
|
|
|
assert dest2.join('subdir').check(dir=1)
|
|
|
|
assert dest2.join('subdir', 'file1').check(file=1)
|
|
|
|
assert dest2.join('subdir', 'file1').read() == s
|
2009-03-04 01:42:32 +08:00
|
|
|
for x in dest, dest2:
|
|
|
|
fn = x.join("subdir", "file1")
|
|
|
|
fn.setmtime(0)
|
2007-02-05 20:55:31 +08:00
|
|
|
|
|
|
|
source.join('subdir').remove('file1')
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync = RSync(source)
|
2007-01-24 22:24:01 +08:00
|
|
|
rsync.add_target(gw2, dest2)
|
2007-02-05 20:55:31 +08:00
|
|
|
rsync.add_target(gw, dest)
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync.send()
|
2007-01-24 22:24:01 +08:00
|
|
|
assert dest.join('subdir', 'file1').check(file=1)
|
|
|
|
assert dest2.join('subdir', 'file1').check(file=1)
|
2007-02-09 00:04:58 +08:00
|
|
|
rsync = RSync(source)
|
|
|
|
rsync.add_target(gw, dest, delete=True)
|
2007-02-05 20:55:31 +08:00
|
|
|
rsync.add_target(gw2, dest2)
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync.send()
|
2007-02-05 20:55:31 +08:00
|
|
|
assert not dest.join('subdir', 'file1').check()
|
2007-02-09 00:04:58 +08:00
|
|
|
assert dest2.join('subdir', 'file1').check()
|
2007-02-05 20:55:31 +08:00
|
|
|
|
|
|
|
def test_dirsync_twice(self):
|
|
|
|
source = self.source
|
|
|
|
source.ensure("hello")
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync = RSync(source)
|
2007-02-05 20:55:31 +08:00
|
|
|
rsync.add_target(gw, self.dest1)
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync.send()
|
2007-02-05 20:55:31 +08:00
|
|
|
assert self.dest1.join('hello').check()
|
2007-02-08 23:31:38 +08:00
|
|
|
py.test.raises(IOError, "rsync.send()")
|
2007-02-09 00:01:51 +08:00
|
|
|
assert rsync.send(raises=False) is None
|
2007-02-05 20:55:31 +08:00
|
|
|
rsync.add_target(gw, self.dest2)
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync.send()
|
2007-02-05 20:55:31 +08:00
|
|
|
assert self.dest2.join('hello').check()
|
2007-02-08 23:31:38 +08:00
|
|
|
py.test.raises(IOError, "rsync.send()")
|
2007-02-09 00:01:51 +08:00
|
|
|
assert rsync.send(raises=False) is None
|
2007-02-05 20:55:31 +08:00
|
|
|
|
2007-02-07 03:32:21 +08:00
|
|
|
def test_rsync_default_reporting(self):
|
|
|
|
source = self.source
|
|
|
|
source.ensure("hello")
|
|
|
|
cap = py.io.StdCapture()
|
|
|
|
try:
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync = RSync(source)
|
2007-02-07 03:32:21 +08:00
|
|
|
rsync.add_target(gw, self.dest1)
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync.send()
|
2007-02-07 03:32:21 +08:00
|
|
|
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:
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync = RSync(source, verbose=False)
|
2007-02-07 03:32:21 +08:00
|
|
|
rsync.add_target(gw, self.dest1)
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync.send()
|
2007-02-07 03:32:21 +08:00
|
|
|
finally:
|
|
|
|
out, err = cap.reset()
|
|
|
|
assert not out
|
|
|
|
assert not err
|
|
|
|
|
2007-02-05 20:55:31 +08:00
|
|
|
def test_symlink_rsync(self):
|
|
|
|
if py.std.sys.platform == 'win32':
|
|
|
|
py.test.skip("symlinks are unsupported on Windows.")
|
|
|
|
source = self.source
|
|
|
|
dest = self.dest1
|
|
|
|
self.source.ensure("existant")
|
|
|
|
source.join("rellink").mksymlinkto(source.join("existant"), absolute=0)
|
|
|
|
source.join('abslink').mksymlinkto(source.join("existant"))
|
|
|
|
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync = RSync(source)
|
2007-02-05 20:55:31 +08:00
|
|
|
rsync.add_target(gw, dest)
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync.send()
|
|
|
|
|
2007-02-05 20:55:31 +08:00
|
|
|
assert dest.join('rellink').readlink() == dest.join("existant")
|
|
|
|
assert dest.join('abslink').readlink() == dest.join("existant")
|
|
|
|
|
|
|
|
def test_callback(self):
|
|
|
|
dest = self.dest1
|
|
|
|
source = self.source
|
|
|
|
source.ensure("existant").write("a" * 100)
|
|
|
|
source.ensure("existant2").write("a" * 10)
|
|
|
|
total = {}
|
|
|
|
def callback(cmd, lgt, channel):
|
|
|
|
total[(cmd, lgt)] = True
|
|
|
|
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync = RSync(source, callback=callback)
|
2007-02-05 20:55:31 +08:00
|
|
|
#rsync = RSync()
|
|
|
|
rsync.add_target(gw, dest)
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync.send()
|
2007-02-05 20:55:31 +08:00
|
|
|
|
|
|
|
assert total == {("list", 110):True, ("ack", 100):True, ("ack", 10):True}
|
|
|
|
|
|
|
|
def test_file_disappearing(self):
|
|
|
|
dest = self.dest1
|
|
|
|
source = self.source
|
|
|
|
source.ensure("ex").write("a" * 100)
|
|
|
|
source.ensure("ex2").write("a" * 100)
|
|
|
|
|
|
|
|
class DRsync(RSync):
|
|
|
|
def filter(self, x):
|
|
|
|
assert x != source
|
|
|
|
if x.endswith("ex2"):
|
|
|
|
self.x = 1
|
|
|
|
source.join("ex2").remove()
|
|
|
|
return True
|
|
|
|
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync = DRsync(source)
|
2007-02-05 20:55:31 +08:00
|
|
|
rsync.add_target(gw, dest)
|
2007-02-08 23:31:38 +08:00
|
|
|
rsync.send()
|
2007-02-05 20:55:31 +08:00
|
|
|
assert rsync.x == 1
|
|
|
|
assert len(dest.listdir()) == 1
|
|
|
|
assert len(source.listdir()) == 1
|
|
|
|
|