Beispiel #1
0
    def metadata(self, path):
        abspath = os.path.abspath(path)
        path_info = PathInfo(abspath)
        fs, dvc_fs = self._get_fs_pair(path_info)

        dvc_meta = None
        if dvc_fs:
            with suppress(FileNotFoundError):
                dvc_meta = dvc_fs.metadata(path_info)

        stat_result = None
        with suppress(FileNotFoundError):
            stat_result = fs.stat(path_info)

        if not stat_result and not dvc_meta:
            raise FileNotFoundError

        from ._metadata import Metadata

        meta = dvc_meta or Metadata(
            path_info=path_info,
            repo=self._get_repo(abspath) or self._main_repo,
        )

        isdir = bool(stat_result) and stat.S_ISDIR(stat_result.st_mode)
        meta.isdir = meta.isdir or isdir

        if not dvc_meta:
            from dvc.utils import is_exec

            meta.is_exec = bool(stat_result) and is_exec(stat_result.st_mode)
        return meta
Beispiel #2
0
    def metadata(self, path):
        abspath = os.path.abspath(path)
        path_info = PathInfo(abspath)
        tree, dvc_tree = self._get_tree_pair(path_info)

        dvc_meta = None
        if dvc_tree:
            with suppress(FileNotFoundError):
                dvc_meta = dvc_tree.metadata(path_info)

        stat_result = None
        with suppress(FileNotFoundError):
            stat_result = tree.stat(path_info)

        if not stat_result and not dvc_meta:
            raise FileNotFoundError

        meta = dvc_meta or Metadata(
            path_info=path_info,
            repo=self._get_repo(abspath) or self._main_repo,
        )

        isdir = bool(stat_result) and stat.S_ISDIR(stat_result.st_mode)
        meta.isdir = meta.isdir or isdir

        if not dvc_meta:
            meta.is_exec = bool(stat_result) and is_exec(stat_result.st_mode)
        return meta
Beispiel #3
0
    def info(self, path):
        fs, dvc_fs, dvc_path = self._get_fs_pair(path)

        try:
            dvc_info = dvc_fs.info(dvc_path)
        except FileNotFoundError:
            dvc_info = None

        try:
            from dvc.utils import is_exec

            fs_info = fs.info(path)
            fs_info["repo"] = dvc_fs.repo
            fs_info["isout"] = (
                dvc_info.get("isout", False) if dvc_info else False
            )
            fs_info["outs"] = dvc_info["outs"] if dvc_info else None
            fs_info["isdvc"] = dvc_info["isdvc"] if dvc_info else False
            fs_info["meta"] = dvc_info.get("meta") if dvc_info else None

            isexec = False
            if dvc_info:
                isexec = dvc_info["isexec"]
            elif fs_info["type"] == "file":
                isexec = is_exec(fs_info["mode"])
            fs_info["isexec"] = isexec
            return fs_info

        except FileNotFoundError:
            if not dvc_info:
                raise

            dvc_info["repo"] = dvc_fs.repo
            dvc_info["isdvc"] = True
            return dvc_info
Beispiel #4
0
Datei: repo.py Projekt: pared/dvc
    def metadata(self, path):
        fs_path = os.path.abspath(path)
        fs, dvc_fs = self._get_fs_pair(fs_path)

        dvc_meta = None
        if dvc_fs:
            with suppress(FileNotFoundError):
                dvc_meta = dvc_fs.metadata(fs_path)

        info_result = None
        with suppress(FileNotFoundError):
            info_result = fs.info(fs_path)

        if not info_result and not dvc_meta:
            raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
                                    fs_path)

        from ._metadata import Metadata

        meta = dvc_meta or Metadata(
            fs_path=fs_path,
            repo=self._get_repo(fs_path) or self._main_repo,
        )

        isdir = bool(info_result) and info_result["type"] == "directory"
        meta.isdir = meta.isdir or isdir

        if not dvc_meta:
            from dvc.utils import is_exec

            meta.is_exec = bool(info_result) and is_exec(info_result["mode"])
        return meta
Beispiel #5
0
    def isexec(self, path: AnyFSPath) -> bool:
        from dvc.utils import is_exec

        try:
            return is_exec(self.info(path)["mode"])
        except FileNotFoundError:
            return False
Beispiel #6
0
def _get_file_hash(fs_path, fs, name):
    info = _adapt_info(fs.info(fs_path), fs.scheme)

    if name in info:
        assert not info[name].endswith(".dir")
        hash_value = info[name]
    elif hasattr(fs, name):
        func = getattr(fs, name)
        hash_value = func(fs_path)
    elif name == "md5":
        hash_value = file_md5(fs_path, fs)
    else:
        raise NotImplementedError

    meta = Meta(size=info["size"], isexec=is_exec(info.get("mode", 0)))
    hash_info = HashInfo(name, hash_value)
    return meta, hash_info
Beispiel #7
0
def _merge_info(repo, fs_info, dvc_info):
    from dvc.utils import is_exec

    ret = {"repo": repo}

    if dvc_info:
        ret["dvc_info"] = dvc_info
        ret["type"] = dvc_info["type"]
        ret["size"] = dvc_info["size"]
        if not fs_info and "md5" in dvc_info:
            ret["md5"] = dvc_info["md5"]

    if fs_info:
        ret["type"] = fs_info["type"]
        ret["size"] = fs_info["size"]
        isexec = False
        if fs_info["type"] == "file":
            isexec = is_exec(fs_info["mode"])
        ret["isexec"] = isexec

    return ret
Beispiel #8
0
 def isexec(self, path_info):
     mode = self.stat(path_info).st_mode
     return is_exec(mode)
Beispiel #9
0
 def isexec(self, path):
     mode = os.stat(path).st_mode
     return is_exec(mode)
Beispiel #10
0
 def isexec(self, path_info):
     mode = self.info(path_info)["mode"]
     return is_exec(mode)
Beispiel #11
0
    def isexec(self, path_info):
        if not self.exists(path_info):
            return False

        mode = self.info(path_info)["mode"]
        return is_exec(mode)
Beispiel #12
0
    def isexec(self, path_info):
        if not self.exists(path_info):
            return False

        mode = self.stat(path_info).st_mode
        return is_exec(mode)
Beispiel #13
0
 def isexec(self, path):
     return is_exec(self.stat(path).st_mode)