Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework of FileEventHandler to handle content change below given path #108

Open
emphasize opened this issue Mar 16, 2023 · 1 comment
Open
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@emphasize
Copy link
Member

emphasize commented Mar 16, 2023

i'd like to widen the scope of #54

FileWatcher class could be (re)used to monitor filechanges below a path with a slight addition.

Proposal:

class FileEventHandler(FileSystemEventHandler):
    def __init__(self, file_path, callback, ignore_creation=False):
        super().__init__()
        self._callback = callback
        self._file_path = file_path
        self._debounce = 1
        self._last_update = 0
        if ignore_creation:
            self._events = ('modified')
        else:
            self._events = ('created', 'deleted', 'modified')                         # add: also monitor deletions

    def on_any_event(self, event):
        if event.is_directory:
            return
        elif event.event_type in self._events:
            if isdir(self._file_path) or event.src_path == self._file_path:           # add: check if isdir
                if time.time() - self._last_update >= self._debounce:
                    self._callback(event.src_path)
                    self._last_update = time.time()

With this we can monitor either specifically a file if a file is passed or a directory (+subdirectories) otherwise

@JarbasAl JarbasAl added the enhancement New feature or request label Mar 16, 2023
@emphasize
Copy link
Member Author

emphasize commented Mar 16, 2023

Specifically with skill-ovos-filebrowser in mind, to tigger an event (re)creating a database of useable content (+metadata)
This should make OCP integration easier/quicker.

@JarbasAl JarbasAl added this to the 0.1.1 milestone May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants