fix filemon support in linux
This commit is contained in:
parent
36634e8306
commit
e251f09483
3 changed files with 37 additions and 20 deletions
|
@ -412,6 +412,8 @@ class FileMonitorCommand(Subcommand):
|
|||
name = 'filemon'
|
||||
description = "Manage the file monitor service"
|
||||
|
||||
appname = 'edbob'
|
||||
|
||||
def add_parser_args(self, parser):
|
||||
subparsers = parser.add_subparsers(title='subcommands')
|
||||
|
||||
|
@ -430,6 +432,11 @@ class FileMonitorCommand(Subcommand):
|
|||
uninstall = subparsers.add_parser('uninstall', help="Uninstall (remove) service")
|
||||
uninstall.set_defaults(subcommand='remove')
|
||||
|
||||
else:
|
||||
parser.add_argument('-D', '--dont-daemonize',
|
||||
action='store_false', dest='daemonize',
|
||||
help="Don't daemonize when starting")
|
||||
|
||||
def get_win32_module(self):
|
||||
from edbob.filemon import win32
|
||||
return win32
|
||||
|
@ -447,7 +454,7 @@ class FileMonitorCommand(Subcommand):
|
|||
from edbob.filemon import linux as filemon
|
||||
|
||||
if args.subcommand == 'start':
|
||||
filemon.start_daemon()
|
||||
filemon.start_daemon(self.appname, daemonize=args.daemonize)
|
||||
|
||||
elif args.subcommand == 'stop':
|
||||
filemon.stop_daemon()
|
||||
|
|
|
@ -30,10 +30,14 @@ import sys
|
|||
import os
|
||||
import os.path
|
||||
import signal
|
||||
import logging
|
||||
import pyinotify
|
||||
|
||||
import edbob
|
||||
from edbob.filemon import MonitorProfile
|
||||
from edbob.filemon import get_monitor_profiles
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EventHandler(pyinotify.ProcessEvent):
|
||||
|
@ -45,20 +49,15 @@ class EventHandler(pyinotify.ProcessEvent):
|
|||
self.actions = actions
|
||||
|
||||
def process_IN_CREATE(self, event):
|
||||
log.debug("EventHandler: IN_CREATE: %s" % event.pathname)
|
||||
self.perform_actions(event.pathname)
|
||||
|
||||
def process_IN_MOVED_TO(self, event):
|
||||
log.debug("EventHandler: IN_MOVED_TO: %s" % event.pathname)
|
||||
self.perform_actions(event.pathname)
|
||||
|
||||
def perform_actions(self, path):
|
||||
for action in self.actions:
|
||||
if isinstance(action, tuple):
|
||||
func = action[0]
|
||||
args = action[1:]
|
||||
else:
|
||||
func = action
|
||||
args = []
|
||||
func = edbob.load_spec(func)
|
||||
for spec, func, args in self.actions:
|
||||
func(path, *args)
|
||||
|
||||
|
||||
|
@ -71,7 +70,7 @@ def get_pid_path():
|
|||
return '/tmp/%s_filemon.pid' % basename
|
||||
|
||||
|
||||
def start_daemon():
|
||||
def start_daemon(appname, daemonize=True):
|
||||
"""
|
||||
Starts the file monitor daemon.
|
||||
"""
|
||||
|
@ -84,19 +83,16 @@ def start_daemon():
|
|||
wm = pyinotify.WatchManager()
|
||||
notifier = pyinotify.Notifier(wm)
|
||||
|
||||
monitored = {}
|
||||
keys = edbob.config.require('edbob.filemon', 'monitored')
|
||||
keys = keys.split(',')
|
||||
for key in keys:
|
||||
key = key.strip()
|
||||
monitored[key] = MonitorProfile(key)
|
||||
monitored = get_monitor_profiles(appname)
|
||||
|
||||
mask = pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO
|
||||
for profile in monitored.itervalues():
|
||||
for path in profile.dirs:
|
||||
wm.add_watch(path, mask, proc_fun=EventHandler(actions=profile.actions))
|
||||
|
||||
notifier.loop(daemonize=True, pid_file=pid_path)
|
||||
if not daemonize:
|
||||
sys.stderr.write("Starting file monitor. (Press Ctrl+C to quit.)\n")
|
||||
notifier.loop(daemonize=daemonize, pid_file=pid_path)
|
||||
|
||||
|
||||
def stop_daemon():
|
||||
|
@ -113,7 +109,7 @@ def stop_daemon():
|
|||
pid = f.read().strip()
|
||||
f.close()
|
||||
if not pid.isdigit():
|
||||
print "Hm, found bogus PID:", pid
|
||||
log.warning("stop_daemon: Found bogus PID (%s) in file: %s" % (pid, pid_path))
|
||||
return
|
||||
|
||||
os.kill(int(pid), signal.SIGKILL)
|
||||
|
|
16
setup.py
16
setup.py
|
@ -104,6 +104,13 @@ extras = {
|
|||
'Sphinx', # 1.1.3
|
||||
],
|
||||
|
||||
'filemon': [
|
||||
#
|
||||
# package # low high
|
||||
|
||||
# This is just a placeholder on Windows; Linux requires this extra.
|
||||
],
|
||||
|
||||
'pyramid': [
|
||||
#
|
||||
# package # low high
|
||||
|
@ -147,7 +154,7 @@ if sys.platform == 'win32':
|
|||
'py-bcrypt-w32', # 0.2.2
|
||||
]
|
||||
|
||||
else:
|
||||
elif sys.platform == 'linux2':
|
||||
|
||||
extras['db'] += [
|
||||
#
|
||||
|
@ -156,6 +163,13 @@ else:
|
|||
'py-bcrypt', # 0.2
|
||||
]
|
||||
|
||||
extras['filemon'] += [
|
||||
#
|
||||
# package # low high
|
||||
|
||||
'pyinotify', # 0.9.3
|
||||
]
|
||||
|
||||
extras['pyramid'] += [
|
||||
#
|
||||
# package # low high
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue