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

Fix observer positional argument + closed_no_write management #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class MyEventHandler(AIOEventHandler):
async def on_opened(self, event):
print('Opened:', event.src_path) # add your functionality here

async def on_closed_no_write(self, event):
print('Closed no write:', event.src_path) # add your functionality here

async def watch_fs(watch_dir):
evh = MyEventHandler()
Expand Down
2 changes: 2 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ async def on_closed(self, event):
async def on_opened(self, event):
print('Opened:', event.src_path) # add your functionality here

async def on_closed_no_write(self, event):
print('Closed no write:', event.src_path) # add your functionality here

async def watch_fs(watch_dir):
evh = MyEventHandler()
Expand Down
7 changes: 5 additions & 2 deletions hachiko/hachiko.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
EVENT_TYPE_MODIFIED = "modified"
EVENT_TYPE_CLOSED = "closed"
EVENT_TYPE_OPENED = "opened"

EVENT_TYPE_CLOSED_NO_WRITE = "closed_no_write"

class AIOEventHandler(object):
"""An asyncio-compatible event handler."""
Expand All @@ -26,6 +26,7 @@ def __init__(self, loop=None):
EVENT_TYPE_DELETED: self.on_deleted,
EVENT_TYPE_CLOSED: self.on_closed,
EVENT_TYPE_OPENED: self.on_opened,
EVENT_TYPE_CLOSED_NO_WRITE: self.on_closed_no_write,
}

async def on_any_event(self, event):
Expand All @@ -49,6 +50,8 @@ async def on_closed(self, event):
async def on_opened(self, event):
pass

async def on_closed_no_write(self, event):
pass

def dispatch(self, event):
handler = self._method_map[event.event_type]
Expand All @@ -65,7 +68,7 @@ def __init__(self, path=".", recursive=True, event_handler=None, observer=None):

evh = event_handler or AIOEventHandler()

self._observer.schedule(evh, path, recursive)
self._observer.schedule(evh, path=path, recursive=recursive)

def start(self):
self._observer.start()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
watchdog
watchdog>=5.0.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def read(filename):
url="https://github.com/biesnecker/hachiko",
packages=["hachiko"],
package_dir={"hachiko": "./hachiko"},
install_requires=["watchdog"],
install_requires=["watchdog>=5.0.0"],
description="Asyncio wrapper around watchdog.",
license="mit",
long_description=read("README.txt"),
Expand Down