Example #1
0
    def __init__(self, root):
        assert isinstance(root, Path)
        self.root = root
        self.mdd = _metadata_path(root)
        self.keydb = KeyDB(_keys_path(root))
        self.udd = Path(self.keydb.read('udd'))
        self.bs = FileBlobstore(self.udd)
        self.snapdb = KeyDBFactory(KeyDBWindow("snaps", self.keydb),
                                   encode_snapshot,
                                   partial(decode_snapshot, self.bs.reverser))
        self.remotedb = KeyDBFactory(KeyDBWindow("remotes", self.keydb),
                                     encode_volume, decode_volume)

        exclude_file = Path('.farmignore', self.root)
        ignored = [safetype(self.mdd)]
        try:
            with exclude_file.open('rb') as exclude_fd:
                for raw_pattern in exclude_fd.readlines():
                    pattern = ingest(raw_pattern.strip())
                    excluded = safetype(Path(pattern, root))
                    ignored.append(excluded)
        except IOError as e:
            if e.errno == NoSuchFile:
                pass
            else:
                raise e
        self.is_ignored = partial(skip_ignored, ignored)
Example #2
0
def test_KeyDBFactory_copy(tmp_Path):
    with KeyDBWrapper(Path("db1", tmp_Path)) as db1:
        window1 = KeyDBWindow("window", db1)
        factory1 = KeyDBFactory(window1, str,
                                lambda data, name: safetype(data))
        assert factory1.list() == []
        factory1.write("five", 5)
        with KeyDBWrapper(Path("db2", tmp_Path)) as db2:
            window2 = KeyDBWindow("other", db2)
            factory2 = KeyDBFactory(window2, str,
                                    lambda data, name: safetype(data))
            factory2.copy("five", window1)
            value = factory2.read("five")
            assert value == safetype(5)
Example #3
0
def test_KeyDBFactory_diff(tmp_Path):
    with KeyDBWrapper(tmp_Path) as db:
        window = KeyDBWindow("window", db)
        factory = KeyDBFactory(window, str, lambda data, name: safetype(data))
        assert factory.list() == []
        factory.write("five", 5)
        assert factory.list() == ["five"]
        value = factory.read("five")
        assert value == safetype(5)
        factory.delete("five")
        assert factory.list() == []