コード例 #1
0
ファイル: test_odb.py プロジェクト: vishalbelsare/dvc
    def test(self):
        from dvc.objects import load

        dir_hash = "123.dir"
        fname = os.fspath(self.dvc.odb.local.hash_to_path(dir_hash))
        self.create(fname, "<clearly>not,json")
        with pytest.raises(ObjectFormatError):
            load(self.dvc.odb.local, HashInfo("md5", dir_hash))

        dir_hash = "234.dir"
        fname = os.fspath(self.dvc.odb.local.hash_to_path(dir_hash))
        self.create(fname, '{"a": "b"}')
        with pytest.raises(ObjectFormatError):
            load(self.dvc.odb.local, HashInfo("md5", dir_hash))
コード例 #2
0
ファイル: test_checkout.py プロジェクト: vishalbelsare/dvc
    def test(self):
        from dvc.objects import load

        # NOTE: using 'copy' so that cache and link don't have same inode
        ret = main(["config", "cache.type", "copy"])
        self.assertEqual(ret, 0)

        self.dvc.config.load()

        stages = self.dvc.add(self.DATA_DIR)
        self.assertEqual(len(stages), 1)
        self.assertEqual(len(stages[0].outs), 1)
        out = stages[0].outs[0]

        # NOTE: modifying cache file for one of the files inside the directory
        # to check if dvc will detect that the cache is corrupted.
        obj = load(self.dvc.odb.local, out.hash_info)
        _, _, entry_oid = list(obj)[0]
        cache = self.dvc.odb.local.hash_to_path(entry_oid.value)

        os.chmod(cache, 0o644)
        with open(cache, "w+", encoding="utf-8") as fobj:
            fobj.write("1")

        with pytest.raises(CheckoutError):
            self.dvc.checkout(force=True)

        self.assertFalse(os.path.exists(cache))
コード例 #3
0
    def test(self):
        from dvc.objects import load

        # NOTE: using 'copy' so that cache and link don't have same inode
        ret = main(["config", "cache.type", "copy"])
        self.assertEqual(ret, 0)

        self.dvc = DvcRepo(".")
        stages = self.dvc.add(self.DATA_DIR)
        self.assertEqual(len(stages), 1)
        self.assertEqual(len(stages[0].outs), 1)
        out = stages[0].outs[0]

        # NOTE: modifying cache file for one of the files inside the directory
        # to check if dvc will detect that the cache is corrupted.
        _, entry_hash = next(
            load(self.dvc.cache.local,
                 out.hash_info).hash_info.dir_info.items())
        cache = os.fspath(
            self.dvc.cache.local.hash_to_path_info(entry_hash.value))

        os.chmod(cache, 0o644)
        with open(cache, "w+") as fobj:
            fobj.write("1")

        with pytest.raises(CheckoutError):
            self.dvc.checkout(force=True)

        self.assertFalse(os.path.exists(cache))
コード例 #4
0
ファイル: base.py プロジェクト: pyanezs/dvc
    def get_dir_cache(self, **kwargs):

        if not self.is_dir_checksum:
            raise DvcException("cannot get dir cache for file checksum")

        try:
            objects.check(self.odb, self.odb.get(self.hash_info))
        except (FileNotFoundError, objects.ObjectFormatError):
            self.repo.cloud.pull(
                NamedCache.make("local", self.hash_info.value, str(self)),
                show_checksums=False,
                **kwargs,
            )

        try:
            objects.load(self.odb, self.hash_info)
            assert self.hash_info.dir_info
        except (objects.ObjectFormatError, FileNotFoundError):
            self.hash_info.dir_info = None

        return self.dir_cache
コード例 #5
0
ファイル: test_add.py プロジェクト: JordanSimba/dvc
def test_add_directory(tmp_dir, dvc):
    from dvc.objects import load

    (stage, ) = tmp_dir.dvc_gen({"dir": {"file": "file"}})

    assert stage is not None
    assert len(stage.deps) == 0
    assert len(stage.outs) == 1

    hash_info = stage.outs[0].hash_info

    dir_info = load(dvc.odb.local, hash_info).hash_info.dir_info
    for path, _ in dir_info.trie.items():
        assert "\\" not in path
コード例 #6
0
ファイル: test_add.py プロジェクト: rajasekharponakala/dvc
def test_add_directory(tmp_dir, dvc):
    from dvc.objects import load

    (stage, ) = tmp_dir.dvc_gen({"dir": {"file": "file"}})

    assert stage is not None
    assert len(stage.deps) == 0
    assert len(stage.outs) == 1

    hash_info = stage.outs[0].hash_info

    obj = load(dvc.odb.local, hash_info)
    for key, _, _ in obj:
        for part in key:
            assert "\\" not in part
コード例 #7
0
    def get_obj(self, filter_info=None, **kwargs):
        if self.obj:
            obj = self.obj
        elif self.hash_info:
            try:
                obj = objects.load(self.odb, self.hash_info)
            except FileNotFoundError:
                return None
        else:
            return None

        if filter_info and filter_info != self.path_info:
            prefix = filter_info.relative_to(self.path_info).parts
            obj = obj.get(self.odb, prefix)

        return obj
コード例 #8
0
    def get_dir_cache(self, **kwargs):
        if not self.is_dir_checksum:
            raise DvcException("cannot get dir cache for file checksum")

        obj = self.odb.get(self.hash_info)
        try:
            objects.check(self.odb, obj)
        except FileNotFoundError:
            self.repo.cloud.pull([obj], **kwargs)

        try:
            self.obj = objects.load(self.odb, self.hash_info)
        except (FileNotFoundError, ObjectFormatError):
            self.obj = None

        return self.obj
コード例 #9
0
ファイル: output.py プロジェクト: vishalbelsare/dvc
    def get_obj(self, filter_info=None, **kwargs):
        if self.obj:
            obj = self.obj
        elif self.hash_info:
            try:
                obj = objects.load(self.odb, self.hash_info)
            except FileNotFoundError:
                return None
        else:
            return None

        fs_path = self.fs.path
        if filter_info and filter_info != self.fs_path:
            prefix = fs_path.relparts(filter_info, self.fs_path)
            obj = obj.get(self.odb, prefix)

        return obj
コード例 #10
0
ファイル: checkout.py プロジェクト: vijay-pinjala/dvc
def _remove(path_info, fs, cache, force=False):
    if not fs.exists(path_info):
        return

    if force:
        fs.remove(path_info)
        return

    current = stage(cache, path_info, fs, fs.PARAM_CHECKSUM).hash_info
    try:
        obj = load(cache, current)
        check(cache, obj)
    except (FileNotFoundError, ObjectFormatError):
        msg = (f"file/directory '{path_info}' is going to be removed. "
               "Are you sure you want to proceed?")

        if not prompt.confirm(msg):
            raise ConfirmRemoveError(str(path_info))

    fs.remove(path_info)