示例#1
0
def add(repo, target, recursive=False, no_commit=False, fname=None):
    if recursive and fname:
        raise RecursiveAddingWhileUsingFilename()

    targets = [target]

    if os.path.isdir(target) and recursive:
        targets = [
            file
            for file in walk_files(target)
            if not Stage.is_stage_file(file)
            if os.path.basename(file) != repo.scm.ignore_file
            if not repo.scm.is_tracked(file)
        ]

    stages = _create_stages(repo, targets, fname, no_commit)

    repo.check_dag(repo.stages() + stages)

    for stage in stages:
        stage.dump()

    repo.remind_to_git_add()

    return stages
示例#2
0
文件: fs.py 项目: thecooltechguy/dvc
def get_mtime_and_size(path, dvcignore):
    if os.path.isdir(fspath_py35(path)):
        size = 0
        files_mtimes = {}
        for file_path in walk_files(path, dvcignore):
            try:
                stat = os.stat(file_path)
            except OSError as exc:
                # NOTE: broken symlink case.
                if exc.errno != errno.ENOENT:
                    raise
                continue
            size += stat.st_size
            files_mtimes[file_path] = stat.st_mtime

        # We track file changes and moves, which cannot be detected with simply
        # max(mtime(f) for f in non_ignored_files)
        mtime = dict_md5(files_mtimes)
    else:
        base_stat = os.stat(fspath_py35(path))
        size = base_stat.st_size
        mtime = base_stat.st_mtime
        mtime = int(nanotime.timestamp(mtime))

    # State of files handled by dvc is stored in db as TEXT.
    # We cast results to string for later comparisons with stored values.
    return str(mtime), str(size)
示例#3
0
def _find_all_targets(repo, target, recursive):
    if os.path.isdir(target) and recursive:
        return [
            file for file in walk_files(target)
            if not repo.is_dvc_internal(file) if not Stage.is_stage_file(file)
            if not repo.scm.belongs_to_scm(file)
            if not repo.scm.is_tracked(file)
        ]
    return [target]
示例#4
0
    def _discard_working_directory_changes(self, path, dir_info, force=False):
        working_dir_files = set(path for path in walk_files(path))

        cached_files = set(
            os.path.join(path, file["relpath"]) for file in dir_info)

        delta = working_dir_files - cached_files

        for file in delta:
            self.safe_remove({"scheme": "local", "path": file}, force=force)
示例#5
0
    def outs_info(self, stage):
        FileInfo = collections.namedtuple("FileInfo", "path inode")

        paths = [
            path for output in stage.outs for path in walk_files(output.path)
        ]

        return [
            FileInfo(path=path, inode=System.inode(path)) for path in paths
        ]
示例#6
0
    def outs_info(self, stage):
        FileInfo = collections.namedtuple("FileInfo", "path inode")

        paths = [
            path for output in stage["outs"]
            for path in walk_files(output["path"], self.dvc.dvcignore)
        ]

        return [
            FileInfo(path=path, inode=System.inode(path)) for path in paths
        ]
示例#7
0
def test_download_dir(remote, tmpdir):
    path = str(tmpdir / "data")
    to_info = PathInfo(path)
    remote.download(remote.path_info / "data", to_info)
    assert os.path.isdir(path)
    data_dir = tmpdir / "data"
    assert len(list(walk_files(path, None))) == 7
    assert (data_dir / "alice").read_text(encoding="utf-8") == "alice"
    assert (data_dir / "alpha").read_text(encoding="utf-8") == "alpha"
    assert (data_dir / "subdir-file.txt").read_text(
        encoding="utf-8"
    ) == "subdir"
    assert (data_dir / "subdir" / "1").read_text(encoding="utf-8") == "1"
    assert (data_dir / "subdir" / "2").read_text(encoding="utf-8") == "2"
    assert (data_dir / "subdir" / "3").read_text(encoding="utf-8") == "3"
    assert (data_dir / "subdir" / "empty_file").read_text(
        encoding="utf-8"
    ) == ""
示例#8
0
 def _unprotect_dir(self, path, allow_copy=True):
     for fname in walk_files(path, self.repo.dvcignore):
         self._unprotect_file(fname, allow_copy)
示例#9
0
文件: __init__.py 项目: vibhor98/dvc
 def _unprotect_dir(path):
     for path in walk_files(path):
         RemoteLOCAL._unprotect_file(path)
示例#10
0
文件: local.py 项目: deppp/dvc
 def walk_files(self, path_info):
     for fname in walk_files(path_info, self.repo.dvcignore):
         yield PathInfo(fname)
示例#11
0
文件: local.py 项目: chenmin008/dvc
 def list_cache_paths(self):
     assert self.path_info is not None
     return walk_files(self.path_info)
示例#12
0
 def _unprotect_dir(self, path):
     for fname in walk_files(path, self.repo.dvcignore):
         RemoteLOCAL._unprotect_file(fname)
示例#13
0
def test_walk_files(tmp_dir):
    assert list(walk_files(".")) == list(walk_files(tmp_dir))
示例#14
0
def _unprotect_dir(path):
    for path in walk_files(path):
        _unprotect_file(path)
示例#15
0
def test_partial_checkout(tmp_dir, dvc, target):
    tmp_dir.dvc_gen({"dir": {"subdir": {"file": "file"}, "other": "other"}})
    shutil.rmtree("dir")
    dvc.checkout([target])
    assert list(walk_files("dir")) == [os.path.join("dir", "subdir", "file")]
示例#16
0
def _files_set(root, dvcignore):
    return {to_posixpath(f) for f in walk_files(root, dvcignore)}