Skip to content

Feature: InotifyTree depth, or path mask #105

@EsipovPA

Description

@EsipovPA

Feature description
Add tree_depth parameter to an InotifyTree __init__, thus add option to limit the number of created watchers. Or add watch path_mask.

Problem at hand
I have a wast tree of directories that goes something like this:

- parent_dir
  - date
    - time
      - [some_data_files]

The files from date/time are being constantly removed from my system and new date and time directories are being added. Let's say this operations are performed at random order. For my purposes, it would be convenient to add watchers only to first 3 levels of this tree, or add a filter predicate at the beginning of the process.

Possible resulting interface
The resulting interface, as I see it, might be something like this:

import inotofy.adapters

tree_watcher = inotify.adapters.InotifyTree("/my/folder/path", tree_depth=2)

for event in tree_watcher.event_gen():
    # do my work here

or something like this:

import inotofy.adapters

tree_watcher = inotify.adapters.Inotfy()
watcher = tree_watcher.add_watch("/my/folder/path/*/*")

for event in watcher.event_gen():
    # do my work here

or even something like this

import inotofy.adapters

tree_watcher = inotify.adapters.InotifyTree("/my/folder/path", filter_mask="(.+)?.my.file.path.regex")

for event in watcher.event_gen():
    # do my work here

If I understand this correctly, there is no way to do it with current implementation. Or is there some way?
I think I'll try to add a patch on my side for this, but if this may be interesting to anyone here, I'd be glad to share it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions