dsoprea / PyInotify

An efficient and elegant inotify (Linux filesystem activity monitor) library for Python. Python 2 and 3 compatible.
GNU General Public License v2.0
245 stars 73 forks source link

question: how to watch for a specific event (IN_CLOSE_WRITE) #47

Closed nskalis closed 6 years ago

nskalis commented 6 years ago

hi,

and thanks a lot for this library, so useful :) may I ask you the following; how the original snippet that watches a directory (non-recursively) can be changed in order to watch for a specific event only, for example,

for event in i.event_gen(yield_nones=False):
        (_, type_names, path, filename) = event

I do not wish to loop through type_names but I would like to get an event if and only if there is a IN_CLOSE_WRITE file event

if I am interested only in IN_CLOSE_WRITE file events, how can I I specify that ? so that I can take action after that event takes place ?

joydashy commented 6 years ago

Why not just do:

            for type in  type_names:
                if type == "IN_CLOSE_WRITE":
nskalis commented 6 years ago

yes, this is what I did:

if "IN_CLOSE_WRITE" in type_names:

I was wondering if was a declarative way to do that. anyways I am happy with it :)