Exemplo n.º 1
0
Arquivo: get.py Projeto: shizacat/dvc
def get(url, path, out=None, rev=None):
    from dvc.external_repo import external_repo
    from dvc.dvcfile import Dvcfile

    out = resolve_output(path, out)

    if Dvcfile.is_valid_filename(out):
        raise GetDVCFileError()

    # Creating a directory right beside the output to make sure that they
    # are on the same filesystem, so we could take the advantage of
    # reflink and/or hardlink. Not using tempfile.TemporaryDirectory
    # because it will create a symlink to tmpfs, which defeats the purpose
    # and won't work with reflink/hardlink.
    dpath = os.path.dirname(os.path.abspath(out))
    tmp_dir = os.path.join(dpath, "." + str(shortuuid.uuid()))
    try:
        with external_repo(url=url, rev=rev) as repo:
            if hasattr(repo, "cache"):
                repo.cache.local.cache_dir = tmp_dir

                # Try any links possible to avoid data duplication.
                #
                # Not using symlink, because we need to remove cache after we
                # are done, and to make that work we would have to copy data
                # over anyway before removing the cache, so we might just copy
                # it right away.
                #
                # Also, we can't use theoretical "move" link type here, because
                # the same cache file might be used a few times in a directory.
                repo.cache.local.cache_types = ["reflink", "hardlink", "copy"]

            repo.pull_to(path, PathInfo(out))
    finally:
        remove(tmp_dir)
Exemplo n.º 2
0
    def _validate_output_path(cls, path):
        from dvc.dvcfile import Dvcfile

        if Dvcfile.is_valid_filename(path):
            raise cls.IsStageFileError(path)