Remove Tree type and adjust API to continue working
This commit is contained in:
parent
6470aee802
commit
b251614667
4 changed files with 38 additions and 126 deletions
|
|
@ -3,7 +3,7 @@ import datetime as dt
|
|||
from pathlib import Path
|
||||
from typing import Optional, Iterable, Iterator, override
|
||||
|
||||
from .trove import Note, Trove, TreeNote, BadNoteType, TreeEntry, NoteNotFound, ObjectId
|
||||
from .trove import Note, Trove, BadNoteType, TreeEntry, NoteNotFound, ObjectId
|
||||
from . import trove as tr
|
||||
|
||||
class FSNote(Note):
|
||||
|
|
@ -77,7 +77,7 @@ class FSNote(Note):
|
|||
if mime == 'inode/directory':
|
||||
if content:
|
||||
raise NotImplementedError("FSNote does not support children")
|
||||
return FSTreeNote(self._trove, self._new_child_subdir(name, False))
|
||||
return FSNote(self._trove, self._new_child_subdir(name, False))
|
||||
|
||||
ex_path = self._fs_path / name
|
||||
ex_path.write_bytes(content)
|
||||
|
|
@ -143,29 +143,7 @@ class FSNote(Note):
|
|||
for item in self._fs_path.iterdir():
|
||||
if item.name == ".trove":
|
||||
continue
|
||||
yield TreeEntry(name=item.name, object_id=item.stat().st_ino)
|
||||
|
||||
class FSTreeNote(FSNote, TreeNote):
|
||||
def mkdir(self, name: str) -> 'FSTreeNote':
|
||||
target_path = self._fs_path / name
|
||||
target_path.mkdir(exist_ok=True)
|
||||
return FSTreeNote(self._trove, path=target_path)
|
||||
|
||||
def entries(self) -> Iterable[TreeEntry]:
|
||||
try:
|
||||
for item in self._fs_path.iterdir():
|
||||
if item.name == ".trove":
|
||||
continue
|
||||
yield TreeEntry(name=item.name, object_id=str(item))
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
def unlink(self, name: str):
|
||||
return self.unlink_(name)
|
||||
|
||||
def link(self, name: str, note: Note):
|
||||
return self.link_(name, note)
|
||||
|
||||
yield TreeEntry(name=item.name, object_id=str(self._fs_path / item.name))
|
||||
|
||||
|
||||
class FSTrove(Trove):
|
||||
|
|
@ -189,8 +167,6 @@ class FSTrove(Trove):
|
|||
def get_raw_note_by_path(self, path: Path) -> Note:
|
||||
if not path.exists():
|
||||
raise tr.ErrorNotFound(str(path))
|
||||
if path.is_dir():
|
||||
return FSTreeNote(self, path=path)
|
||||
return FSNote(self, path=path)
|
||||
|
||||
def get_raw_note(self, note_id: ObjectId) -> Note:
|
||||
|
|
@ -221,8 +197,8 @@ class FSTrove(Trove):
|
|||
def create_blob(self, data: bytes | None = None) -> Note:
|
||||
raise NotImplementedError("FSTrove does not support blobs")
|
||||
|
||||
def get_root(self) -> TreeNote:
|
||||
return FSTreeNote(self, path=self.root)
|
||||
def get_root(self) -> Note:
|
||||
return FSNote(self, path=self.root)
|
||||
|
||||
def _get_metadata(self, inode: int, key: str) -> Optional[bytes]:
|
||||
raise NotImplementedError("FSTrove does not support metadata")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue