madhadron / pydaemonize

Utilities for building system daemons in Python
GNU General Public License v3.0
2 stars 0 forks source link

Can't find inotify #1

Open twekberg opened 12 years ago

twekberg commented 12 years ago

Fred,

I don't see pydaemonize.inotify in the master branch. I see it in the commit log and at tree 567cd23ab2. Would you mind pushing it to the master branch? The readme looks old too - no mention of inotify.

Tom Ekberg tekberg at uw.edu

madhadron commented 12 years ago

On 6/14/12 9:21 AM, twekberg wrote:

Fred,

I don't see pydaemonize.inotify in the master branch. I see it in the commit log and at tree 567cd23ab2. Would you mind pushing it to the master branch? The readme looks old too - no mention of inotify.

Actually, there was a change in the primary API from function based (a port of my earlier Haskell library) to class based (to be more Pythonic). The inotify daemon didn't get translated. Here's the code for it, if you want to translate it:

""" pydaemonize/inotify.py - Generic inotify daemon. """

Copyright 2011 Frederick J. Ross.

#

This program is free software: you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.

#

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

#

You should have received a copy of the GNU General Public License

along with this program. If not, see http://www.gnu.org/licenses/.

import os import sys import syslog import pyinotify from init import serviced

for flag, val in pyinotify.EventsCodes.ALL_FLAGS.iteritems(): globals()[flag] = val

def daemon(paths, callback, init=lambda: None, mask=pyinotify.ALL_EVENTS, name=os.path.basename(sys.argv[0]), user=None, group=None, syslog_options=0, pidfile_directory='/var/run', exitevent=None): if isinstance(paths, basestring): paths = [paths] else: paths = paths

 def daemon_behavior(state):
     class Handler(pyinotify.ProcessEvent):
         def process_IN_UNMOUNT(self, event):
             syslog.syslog(syslog.LOG_NOTICE, "Backing filesystem of 

%s was unmounted. Exiting." % event.path) exit(0) def process_default(self, event): callback(state, event)

     wm = pyinotify.WatchManager()
     notifier = pyinotify.Notifier(wm, Handler())
     for p in paths:
         wm.add_watch(p, mask, rec=True)

     while exitevent==None or not(exitevent.is_set()):
         notifier.process_events()
         while notifier.check_events():
             notifier.read_events()
             notifier.process_events()
         time.sleep(0.01)

 serviced(daemon_behavior,
          privileged_action=init,
          name=name,
          user=user,
          group=group,
          syslog_options=syslog_options,
          pidfile_directory=pidfile_directory)

Frederick Ross http://madhadron.com https://github.com/madhadron/ My new novel is now available: Monologue: A Comedy of Telepathy Kidnapping, blackmail, slander... http://frederickjross.com