summaryrefslogtreecommitdiff
path: root/kvmd/inotify.py
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2024-08-25 01:24:12 +0300
committerMaxim Devaev <[email protected]>2024-08-25 01:24:12 +0300
commit3837e1a1c8d64cccb12c4811a3975949ee904327 (patch)
tree5fa205c8fe5c78dec9850f788ce97f76c601bbdd /kvmd/inotify.py
parent8569ed406a0d5f1c5da100fb58c49208fd6e1887 (diff)
Simplified inotify API
Diffstat (limited to 'kvmd/inotify.py')
-rw-r--r--kvmd/inotify.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/kvmd/inotify.py b/kvmd/inotify.py
index 700247ef..c70ec465 100644
--- a/kvmd/inotify.py
+++ b/kvmd/inotify.py
@@ -142,6 +142,14 @@ class InotifyMask:
| MOVED_TO
)
+ # Helper for typicals events when we need to restart watcher
+ ALL_RESTART_EVENTS = (
+ DELETE_SELF
+ | MOVE_SELF
+ | UNMOUNT
+ | ISDIR
+ )
+
# Special flags for watch()
# DONT_FOLLOW = 0x02000000 # Don't follow a symbolic link
# EXCL_UNLINK = 0x04000000 # Exclude events on unlinked objects
@@ -172,6 +180,10 @@ class InotifyEvent:
name: str
path: str
+ @property
+ def restart(self) -> bool:
+ return bool(self.mask & InotifyMask.ALL_RESTART_EVENTS)
+
def __repr__(self) -> str:
return (
f"<InotifyEvent: wd={self.wd}, mask={InotifyMask.to_string(self.mask)},"
@@ -190,6 +202,9 @@ class Inotify:
self.__events_queue: "asyncio.Queue[InotifyEvent]" = asyncio.Queue()
+ async def watch_all_modify(self, *paths: str) -> None:
+ await self.watch(InotifyMask.ALL_MODIFY_EVENTS, *paths)
+
async def watch(self, mask: int, *paths: str) -> None:
for path in paths:
path = os.path.normpath(path)