dmon - directory monitor
Python C
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
README.md
__init__.py
dmon.py

README.md

dmon - directory monitor

nutshell:

  • recursively watches a directory
  • create, update, delete events
  • runs on linux and osx
  • custom handler implementation

import:

  • from dmon import *

usage:

  • dmon.start(dir, handler_list)

example:

#!/usr/bin/env python
from subprocess import call
import os
import sys
import subprocess
from dmon import *

'''
sample implementation of a dmon
handler. expected methods are
- on_create(self, file)
- on_delete(self, file)
- on_update(self, file)
'''
class Dmonake:
    _compile = ["coffee", "-c"]
    _delete = ["rm"]

    def _check(self, file):
        return '.coffee' == file[-7:].lower()

    def _run(self, command, file):
        try:
            subprocess.check_output(command + [file])
        except subprocess.CalledProcessError as e:
            print(e.output)
        except:
            pass

    ''' interface method '''
    def on_delete(self, file):
        pass
        #if self._check(file):
        #    self._run(self._delete, file[:-7]+'.js')

    ''' interface method '''
    def on_update(self, file):
        if self._check(file):
            self._run(self._compile, file)

    ''' interface method '''
    def on_create(self, file):
        if self._check(file):
            self.on_update(file)


if __name__ == '__main__':
    dmon.start(sys.argv[1], [Dmonake()])