Example #1
0
    def test_callback(self, dirs, gw1):
        dest = dirs.dest1
        source = dirs.source
        source.ensure("existant").write("a" * 100)
        source.ensure("existant2").write("a" * 10)
        total = {}
        def callback(cmd, lgt, channel):
            total[(cmd, lgt)] = True

        rsync = RSync(source, callback=callback)
        #rsync = RSync()
        rsync.add_target(gw1, dest)
        rsync.send()

        assert total == {("list", 110):True, ("ack", 100):True, ("ack", 10):True}
Example #2
0
 def test_rsync_default_reporting(self, capsys, dirs, gw1):
     source = dirs.source
     source.ensure("hello")
     rsync = RSync(source)
     rsync.add_target(gw1, dirs.dest1)
     rsync.send()
     out, err = capsys.readouterr()
     assert out.find("hello") != -1
Example #3
0
 def test_rsync_non_verbose(self, capsys, dirs, gw1):
     source = dirs.source
     source.ensure("hello")
     rsync = RSync(source, verbose=False)
     rsync.add_target(gw1, dirs.dest1)
     rsync.send()
     out, err = capsys.readouterr()
     assert not out
     assert not err
Example #4
0
    def test_2_to_3_bridge_can_send_binary_files(self, tmpdir, makegateway):
        python = _find_version('3')
        gw = makegateway('popen//python=%s' % python)
        source = tmpdir.ensure('source', dir=1)
        for i, content in enumerate('foo bar baz \x10foo'):
            source.join(str(i)).write(content)
        rsync = RSync(source)

        target = tmpdir.join('target')
        rsync.add_target(gw, target)
        rsync.send()
Example #5
0
    def test_symlink_rsync(self, dirs, gw1):
        source = dirs.source
        dest = dirs.dest1
        sourcefile = dirs.source.ensure("subdir", "existant")
        source.join("rellink").mksymlinkto(sourcefile, absolute=0)
        source.join('abslink').mksymlinkto(sourcefile)

        rsync = RSync(source)
        rsync.add_target(gw1, dest)
        rsync.send()

        expected = dest.join(sourcefile.relto(dirs.source))
        assert dest.join('rellink').readlink() == "subdir/existant"
        assert dest.join('abslink').readlink() == expected
Example #6
0
 def test_symlink2_rsync(self, dirs, gw1):
     source = dirs.source
     dest = dirs.dest1
     subdir = dirs.source.ensure("subdir", dir=1)
     sourcefile = subdir.ensure("somefile")
     subdir.join("link1").mksymlinkto(subdir.join("link2"), absolute=0)
     subdir.join("link2").mksymlinkto(sourcefile, absolute=1)
     subdir.join("link3").mksymlinkto(source.dirpath(), absolute=1)
     rsync = RSync(source)
     rsync.add_target(gw1, dest)
     rsync.send()
     expected = dest.join(sourcefile.relto(dirs.source))
     destsub = dest.join("subdir")
     assert destsub.check()
     assert destsub.join('link1').readlink() == "link2"
     assert destsub.join('link2').readlink() == expected
     assert destsub.join('link3').readlink() == source.dirpath()
Example #7
0
    def test_callback(self, dirs, gw1):
        dest = dirs.dest1
        source = dirs.source
        source.ensure("existant").write("a" * 100)
        source.ensure("existant2").write("a" * 10)
        total = {}

        def callback(cmd, lgt, channel):
            total[(cmd, lgt)] = True

        rsync = RSync(source, callback=callback)
        # rsync = RSync()
        rsync.add_target(gw1, dest)
        rsync.send()

        assert total == {
            ("list", 110): True,
            ("ack", 100): True,
            ("ack", 10): True,
        }
Example #8
0
 def test_dirsync_twice(self, dirs, gw1, gw2):
     source = dirs.source
     source.ensure("hello")
     rsync = RSync(source)
     rsync.add_target(gw1, dirs.dest1)
     rsync.send()
     assert dirs.dest1.join('hello').check()
     py.test.raises(IOError, "rsync.send()")
     assert rsync.send(raises=False) is None
     rsync.add_target(gw1, dirs.dest2)
     rsync.send()
     assert dirs.dest2.join('hello').check()
     py.test.raises(IOError, "rsync.send()")
     assert rsync.send(raises=False) is None
Example #9
0
    def test_dirsync(self, dirs, gw1, gw2):
        dest = dirs.dest1
        dest2 = dirs.dest2
        source = dirs.source

        for s in ('content1', 'content2', 'content2-a-bit-longer'):
            source.ensure('subdir', 'file1').write(s)
            rsync = RSync(dirs.source)
            rsync.add_target(gw1, dest)
            rsync.add_target(gw2, dest2)
            rsync.send()
            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
            for x in dest, dest2:
                fn = x.join("subdir", "file1")
                fn.setmtime(0)

        source.join('subdir').remove('file1')
        rsync = RSync(source)
        rsync.add_target(gw2, dest2)
        rsync.add_target(gw1, dest)
        rsync.send()
        assert dest.join('subdir', 'file1').check(file=1)
        assert dest2.join('subdir', 'file1').check(file=1)
        rsync = RSync(source)
        rsync.add_target(gw1, dest, delete=True)
        rsync.add_target(gw2, dest2)
        rsync.send()
        assert not dest.join('subdir', 'file1').check()
        assert dest2.join('subdir', 'file1').check()
Example #10
0
 def test_notargets(self, dirs):
     rsync = RSync(dirs.source)
     py.test.raises(IOError, "rsync.send()")
     assert rsync.send(raises=False) is None
Example #11
0
    def test_permissions(self, dirs, gw1, gw2):
        source = dirs.source
        dest = dirs.dest1
        onedir = dirs.source.ensure("one", dir=1)
        onedir.chmod(448)
        onefile = dirs.source.ensure("file")
        onefile.chmod(504)
        onefile_mtime = onefile.stat().mtime

        rsync = RSync(source)
        rsync.add_target(gw1, dest)
        rsync.send()

        destdir = dirs.dest1.join(onedir.basename)
        destfile = dirs.dest1.join(onefile.basename)
        assert destfile.stat().mode & 511 == 504
        mode = destdir.stat().mode
        assert mode & 511 == 448

        # transfer again with changed permissions
        onedir.chmod(504)
        onefile.chmod(448)
        onefile.setmtime(onefile_mtime)

        rsync = RSync(source)
        rsync.add_target(gw1, dest)
        rsync.send()

        mode = destfile.stat().mode
        assert mode & 511 == 448, mode
        mode = destdir.stat().mode
        assert mode & 511 == 504