Esempio n. 1
0
def contains_symlink_up_to(path, base_path):
    base_path = fspath(base_path)
    path = fspath(path)

    if base_path not in path:
        raise BasePathNotInCheckedPathException(path, base_path)

    if path == base_path:
        return False
    if System.is_symlink(path):
        return True
    if os.path.dirname(path) == path:
        return False
    return contains_symlink_up_to(os.path.dirname(path), base_path)
Esempio n. 2
0
    def test_pre_push_hook(self, tmp_dir, scm, dvc, tmp_path_factory):
        scm.install()

        temp = tmp_path_factory.mktemp("external")
        git_remote = temp / "project.git"
        storage_path = temp / "dvc_storage"

        RemoteConfig(dvc.config).add("store",
                                     fspath(storage_path),
                                     default=True)
        tmp_dir.dvc_gen("file", "file_content", "commit message")

        file_checksum = file_md5("file")[0]
        expected_storage_path = (storage_path / file_checksum[:2] /
                                 file_checksum[2:])

        scm.repo.clone(fspath(git_remote))
        scm.repo.create_remote("origin", fspath(git_remote))

        assert not expected_storage_path.is_file()
        scm.repo.git.push("origin", "master")
        assert expected_storage_path.is_file()
        assert expected_storage_path.read_text() == "file_content"
Esempio n. 3
0
File: fs.py Progetto: trallard/dvc
def move(src, dst, mode=None):
    """Atomically move src to dst and chmod it with mode.

    Moving is performed in two stages to make the whole operation atomic in
    case src and dst are on different filesystems and actual physical copying
    of data is happening.
    """

    src = fspath(src)
    dst = fspath(dst)

    dst = os.path.abspath(dst)
    tmp = "{}.{}".format(dst, uuid())

    if os.path.islink(src):
        shutil.copy(os.readlink(src), tmp)
        os.unlink(src)
    else:
        shutil.move(src, tmp)

    if mode is not None:
        os.chmod(tmp, mode)

    shutil.move(tmp, dst)
Esempio n. 4
0
File: fs.py Progetto: trallard/dvc
def walk_files(directory):
    for root, _, files in os.walk(fspath(directory)):
        for f in files:
            yield os.path.join(root, f)