Add more meta information to trove entries
This commit is contained in:
parent
4ada169bbe
commit
bd4d571c95
5 changed files with 80 additions and 7 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import sqlite3
|
||||
import tempfile
|
||||
import datetime as dt
|
||||
from pathlib import Path
|
||||
from typing import Optional, Dict, List, Self, Iterable
|
||||
from .trove import Note, Trove, TreeNote, BlobNote, Blob, Tree, BadNoteType, TreeEntry, NoteNotFound
|
||||
|
|
@ -24,6 +25,24 @@ class FSNote(Note):
|
|||
raise ValueError("Note not yet saved to disk")
|
||||
return self._inode
|
||||
|
||||
@property
|
||||
def mtime(self):
|
||||
"""Return modification time as datetime."""
|
||||
stat = self._path.stat()
|
||||
return dt.datetime.fromtimestamp(stat.st_mtime, tz=dt.timezone.utc)
|
||||
|
||||
@property
|
||||
def readonly(self) -> bool:
|
||||
"""Check if the note is readonly based on file permissions."""
|
||||
if self._inode is None:
|
||||
return False
|
||||
return not os.access(self._path, os.W_OK)
|
||||
|
||||
@property
|
||||
def mime(self) -> str:
|
||||
"""Return MIME type, defaulting to generic binary stream."""
|
||||
return "application/octet-stream"
|
||||
|
||||
@property
|
||||
def _path(self) -> Path:
|
||||
if self._fs_path is not None:
|
||||
|
|
@ -60,6 +79,11 @@ class FSBlobNote(FSNote, BlobNote):
|
|||
pass
|
||||
|
||||
class FSTreeNote(FSNote, TreeNote):
|
||||
@property
|
||||
def mime(self) -> str:
|
||||
"""Return MIME type for directory/tree nodes."""
|
||||
return "inode/directory"
|
||||
|
||||
def link(self, name: str, note: Note):
|
||||
if not isinstance(note, FSBlobNote):
|
||||
raise BadNoteType("Only blob notes can be linked")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue