python pyinotify to monitor the specified suffix files in a dir
pI want to monitor a dir , and the dir has sub dirs and in subdir there
are somes files with code.md/code. (maybe there are some other files, such
as *.swp...)/p pI only want to monitor the .md files, I have read the doc,
and there is only a codeExcludeFilter/code, and in the issue : a
href=https://github.com/seb-m/pyinotify/issues/31
rel=nofollowhttps://github.com/seb-m/pyinotify/issues/31/a says, only dir
can be filter but not files./p pNow what I do is to filter in
codeprocess_*/code functions to check the codeevent.name/code by
codefnmatch/code./p pSo if I only want to monitor the specified suffix
files, is there a better way? Thanks./p pThis is the main code I have
written:/p precode!/usr/bin/env python # -*- coding: utf-8 -*- import
pyinotify import fnmatch def suffix_filter(fn): suffixes = [*.md,
*.markdown] for suffix in suffixes: if fnmatch.fnmatch(fn, suffix): return
False return True class EventHandler(pyinotify.ProcessEvent): def
process_IN_CREATE(self, event): if not suffix_filter(event.name): print
Creating:, event.pathname def process_IN_DELETE(self, event): if not
suffix_filter(event.name): print Removing:, event.pathname def
process_IN_MODIFY(self, event): if not suffix_filter(event.name): print
Modifing:, event.pathname def process_default(self, event): print
Default:, event.pathname /code/pre
No comments:
Post a Comment