Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceasar committed Oct 7, 2012
1 parent 4cd1a2b commit 938dce7
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 1 deletion.
7 changes: 7 additions & 0 deletions LICENSE.txt
@@ -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.
35 changes: 34 additions & 1 deletion README.md
@@ -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.
4 changes: 4 additions & 0 deletions easywatch/__init__.py
@@ -0,0 +1,4 @@
__version_info__ = ('0', '0', '1')
__version__ = '.'.join(__version_info__)

from easywatch import watch
36 changes: 36 additions & 0 deletions easywatch/easywatch.py
@@ -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()
1 change: 1 addition & 0 deletions requirements.txt
@@ -0,0 +1 @@
watchdog==0.6.0
27 changes: 27 additions & 0 deletions setup.py
@@ -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",
],
)

0 comments on commit 938dce7

Please sign in to comment.