Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright (c) 2014 Ceasar Bautista | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,37 @@ | ||
easywatch | ||
========= | ||
|
||
Dead-simple way to watch a directory. | ||
Dead-simple way to watch a directory. | ||
|
||
Installation | ||
------------ | ||
|
||
`pip install easywatch` | ||
|
||
Quickstart | ||
---------- | ||
|
||
`easywatch` has just one function, `watch` which watches a directory for changes and notifies a handler the type of event and the name of the file that triggered it. | ||
|
||
There are four types of events that the handler can be notified about: | ||
|
||
- `created` - a file was created | ||
- `deleted` - a file was deleted | ||
- `modified` - a file was modified | ||
- `moved` - a file was moved | ||
|
||
For instance: | ||
|
||
```python | ||
import easywatch | ||
|
||
if __name__ == "__main__": | ||
def handler(event_type, src_path): | ||
print event_type | ||
print src_path | ||
easy.watch(".", handler) | ||
``` | ||
|
||
Note that `src_path` is just the absolute path to the file. | ||
|
||
And that's pretty much it. If you need more customization, check out `watchdog`, which `easywatch` wraps. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
__version_info__ = ('0', '0', '1') | ||
__version__ = '.'.join(__version_info__) | ||
|
||
from easywatch import watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
Simple static page generator. | ||
Uses jinja2 to compile templates. | ||
Templates should live inside `./templates` and will be compiled in '.'. | ||
""" | ||
import functools | ||
import time | ||
|
||
from watchdog.observers import Observer | ||
from watchdog.events import FileSystemEventHandler | ||
|
||
|
||
def watch(path, handler): | ||
"""Watch a directory for events. | ||
- path should be the directory to watch | ||
- handler should a function which takes an event_type and src_path | ||
and does something interesting. event_type will be one of 'created', | ||
'deleted', 'modified', or 'moved'. src_path will be the absolute | ||
path to the file that triggered the event. | ||
""" | ||
# let the user just deal with events | ||
@functools.wraps(handler) | ||
def wrapper(self, event): | ||
if not event.is_directory: | ||
return handler(event.event_type, event.src_path) | ||
attrs = {'on_any_event': wrapper} | ||
EventHandler = type("EventHandler", (FileSystemEventHandler,), attrs) | ||
observer = Observer() | ||
observer.schedule(EventHandler(), path=path) | ||
observer.start() | ||
try: | ||
while True: | ||
time.sleep(1) | ||
except KeyboardInterrupt: | ||
observer.stop() | ||
observer.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
watchdog==0.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from distutils.core import setup | ||
|
||
from easywatch import __version__ | ||
|
||
|
||
setup( | ||
name="easywatch", | ||
version=__version__, | ||
description="super simple directory monitoring", | ||
author="Ceasar Bautista", | ||
author_email="cbautista2010@gmail.com", | ||
url="https://github.com/Ceasar/easywatch", | ||
keywords=["directory", "polling", "monitoring"], | ||
packages=["easywatch"], | ||
classifiers=[ | ||
"Intended Audience :: Developers", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 2.5", | ||
"Programming Language :: Python :: 2.6", | ||
"Programming Language :: Python :: 2.7", | ||
"Topic :: Software Development :: Libraries :: Python Modules", | ||
"Development Status :: 4 - Beta", | ||
"Intended Audience :: Developers", | ||
], | ||
) |