Beispiel #1
0
def file_move_xrootd(src, dst, *args, **kwargs):
    """Move file."""
    if current_app.config['XROOTD_ENABLED'] and \
            current_app.config['VIDEOS_XROOTD_ENDPOINT'] in src:
        from xrootdpyfs import XRootDPyFS
        # Get the filename
        _filename_src = src.split('/')[-1]
        _filename_dst = dst.split('/')[-1]
        # Remove filename from the path
        path = src.replace(_filename_src, '')
        fs = XRootDPyFS(path)
        return fs.move(_filename_src, _filename_dst)
    return os.rename(src, dst)
Beispiel #2
0
def test_move_good(tmppath):
    """Test move file."""
    fs = XRootDPyFS(mkurl(tmppath))

    src_exists = "data/testa.txt"
    dst_exists = "data/multiline.txt"
    dst_new = "data/ok.txt"
    dst_folder_exists = "data/bfolder/"
    dst_folder_new = "data/anothernewfolder/"
    content = _get_content(fs, src_exists)

    assert fs.exists(dst_exists)
    assert not fs.exists(dst_new)
    assert fs.exists(dst_folder_exists)
    assert not fs.exists(dst_folder_new)

    fs.move(src_exists, dst_new)
    assert not fs.exists(src_exists) and fs.exists(dst_new)

    fs.move(dst_new, src_exists)
    fs.move(src_exists, dst_folder_new)
    assert not fs.exists(src_exists) and fs.exists(dst_folder_new)

    fs.move(dst_folder_new, src_exists)
    fs.move(src_exists, dst_exists, overwrite=True)
    assert not fs.exists(src_exists) and fs.exists(dst_exists)
    assert content == _get_content(fs, dst_exists)

    fs.move(dst_exists, src_exists)
    fs.move(src_exists, dst_folder_exists, overwrite=True)
    assert not fs.exists(src_exists) and fs.exists(dst_folder_exists)
    assert content == _get_content(fs, dst_folder_exists)
Beispiel #3
0
def test_move_good(tmppath):
    """Test move file."""
    fs = XRootDPyFS(mkurl(tmppath))

    src_exists = "data/testa.txt"
    dst_exists = "data/multiline.txt"
    dst_new = "data/ok.txt"
    dst_folder_exists = "data/bfolder/"
    dst_folder_new = "data/anothernewfolder/"
    content = _get_content(fs, src_exists)

    assert fs.exists(dst_exists)
    assert not fs.exists(dst_new)
    assert fs.exists(dst_folder_exists)
    assert not fs.exists(dst_folder_new)

    fs.move(src_exists, dst_new)
    assert not fs.exists(src_exists) and fs.exists(dst_new)

    fs.move(dst_new, src_exists)
    fs.move(src_exists, dst_folder_new)
    assert not fs.exists(src_exists) and fs.exists(dst_folder_new)

    fs.move(dst_folder_new, src_exists)
    fs.move(src_exists, dst_exists, overwrite=True)
    assert not fs.exists(src_exists) and fs.exists(dst_exists)
    assert content == _get_content(fs, dst_exists)

    fs.move(dst_exists, src_exists)
    fs.move(src_exists, dst_folder_exists, overwrite=True)
    assert not fs.exists(src_exists) and fs.exists(dst_folder_exists)
    assert content == _get_content(fs, dst_folder_exists)