Ejemplo n.º 1
0
    def read(self) -> "Branch":
        content = list(self.path.glob("./*"))
        content = list(filter(lambda x: not x.stem.startswith("."), content))
        branches = list(filter(lambda x: x.suffix != ".leaf", content))
        data = list(filter(lambda x: x.suffix == ".leaf", content))

        for branch in branches:
            self._content[branch.name] = Branch(
                self, branch.name, {},
                Meta.from_json(self.path / branch.name / ".meta.json"))
            self._content[branch.name].read()

        for data_node in data:
            self._content[data_node.with_suffix("").name] = Leaf.initialize(
                self,
                data_node.with_suffix("").name)
Ejemplo n.º 2
0
    def initialize(parent: Node, name: str) -> "Leaf":
        name = name.replace(".leaf", "")
        leaf_path = (parent.path / name).with_suffix(".leaf")
        meta = Meta.from_json(leaf_path / ".meta.json")

        # read all the non-hidden files
        content = list(leaf_path.with_suffix(".leaf").glob("./*"))
        content = list(filter(lambda x: not x.stem.startswith("."), content))

        if len(content) == 0:
            import data_formats
            return data_formats.available_extensions[content[0].suffix](
                parent, name.replace(".leaf"), meta)
        else:
            if len(content) > 1:
                raise FileNotFoundError("To many files in the leaf")
            else:
                raise FileNotFoundError(
                    "The leaf does not exist {:s} {:s}".format(
                        str(leaf_path), name))
    def test_list_authors(self):
        path = Path("../../test_new.struct/.meta.json")

        meta = Meta.from_json(path)