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

Watchdog Extension #394

Closed
derks opened this Issue Jul 13, 2016 · 1 comment

Comments

Projects
None yet
1 participant
@derks
Member

derks commented Jul 13, 2016

Add an extension based on Watchdog library. The extension should make watching and reacting to file/directory changes easy.

class MyEventHandler(WatchdogEventHandler):
    def on_any_event(self, event):
        # do something with the event
        pass

class MyApp(CementApp):
    class Meta:
        label = 'myapp'
        extension = 'watchdog'
        watchdog_paths = [
            ('/path/to/some/directory', MyEventHandler),
        ]

Will be used as a prerequisite to properly redo the ext_reload_config extension, as noted in issue #326.

@derks derks added this to the 2.10.0 Stable milestone Jul 13, 2016

@derks derks self-assigned this Jul 13, 2016

derks added a commit that referenced this issue Jul 13, 2016

@derks derks closed this Jul 13, 2016

@derks

This comment has been minimized.

Show comment
Hide comment
@derks

derks Jul 13, 2016

Member

This is implemented in master via the watchdog extension:

import os
from time import sleep
from cement.core.foundation import CementApp
from cement.core.exc import CaughtSignal
from cement.ext.ext_watchdog import WatchdogEventHandler


class MyEventHandler(WatchdogEventHandler):
    def on_any_event(self, event):
        # do something with the ``event`` object
        print("The modified path was: %s" % event.src_path)


class MyApp(CementApp):
    class Meta:
        label = 'myapp'
        extensions = ['watchdog']
        watchdog_paths = [
            ('./tmp/', MyEventHandler),
        ]


with MyApp() as app:
    app.run()

    try:
        while True:
            sleep(1)
    except CaughtSignal as e:
        print(e)
Member

derks commented Jul 13, 2016

This is implemented in master via the watchdog extension:

import os
from time import sleep
from cement.core.foundation import CementApp
from cement.core.exc import CaughtSignal
from cement.ext.ext_watchdog import WatchdogEventHandler


class MyEventHandler(WatchdogEventHandler):
    def on_any_event(self, event):
        # do something with the ``event`` object
        print("The modified path was: %s" % event.src_path)


class MyApp(CementApp):
    class Meta:
        label = 'myapp'
        extensions = ['watchdog']
        watchdog_paths = [
            ('./tmp/', MyEventHandler),
        ]


with MyApp() as app:
    app.run()

    try:
        while True:
            sleep(1)
    except CaughtSignal as e:
        print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment