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'
|
name = 'filemon'
|
||||||
description = "Manage the file monitor service"
|
description = "Manage the file monitor service"
|
||||||
|
|
||||||
|
appname = 'edbob'
|
||||||
|
|
||||||
def add_parser_args(self, parser):
|
def add_parser_args(self, parser):
|
||||||
subparsers = parser.add_subparsers(title='subcommands')
|
subparsers = parser.add_subparsers(title='subcommands')
|
||||||
|
|
||||||
|
@ -430,6 +432,11 @@ class FileMonitorCommand(Subcommand):
|
||||||
uninstall = subparsers.add_parser('uninstall', help="Uninstall (remove) service")
|
uninstall = subparsers.add_parser('uninstall', help="Uninstall (remove) service")
|
||||||
uninstall.set_defaults(subcommand='remove')
|
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):
|
def get_win32_module(self):
|
||||||
from edbob.filemon import win32
|
from edbob.filemon import win32
|
||||||
return win32
|
return win32
|
||||||
|
@ -447,7 +454,7 @@ class FileMonitorCommand(Subcommand):
|
||||||
from edbob.filemon import linux as filemon
|
from edbob.filemon import linux as filemon
|
||||||
|
|
||||||
if args.subcommand == 'start':
|
if args.subcommand == 'start':
|
||||||
filemon.start_daemon()
|
filemon.start_daemon(self.appname, daemonize=args.daemonize)
|
||||||
|
|
||||||
elif args.subcommand == 'stop':
|
elif args.subcommand == 'stop':
|
||||||
filemon.stop_daemon()
|
filemon.stop_daemon()
|
||||||
|
|
|
@ -30,10 +30,14 @@ import sys
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import signal
|
import signal
|
||||||
|
import logging
|
||||||
import pyinotify
|
import pyinotify
|
||||||
|
|
||||||
import edbob
|
import edbob
|
||||||
from edbob.filemon import MonitorProfile
|
from edbob.filemon import get_monitor_profiles
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class EventHandler(pyinotify.ProcessEvent):
|
class EventHandler(pyinotify.ProcessEvent):
|
||||||
|
@ -45,20 +49,15 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
self.actions = actions
|
self.actions = actions
|
||||||
|
|
||||||
def process_IN_CREATE(self, event):
|
def process_IN_CREATE(self, event):
|
||||||
|
log.debug("EventHandler: IN_CREATE: %s" % event.pathname)
|
||||||
self.perform_actions(event.pathname)
|
self.perform_actions(event.pathname)
|
||||||
|
|
||||||
def process_IN_MOVED_TO(self, event):
|
def process_IN_MOVED_TO(self, event):
|
||||||
|
log.debug("EventHandler: IN_MOVED_TO: %s" % event.pathname)
|
||||||
self.perform_actions(event.pathname)
|
self.perform_actions(event.pathname)
|
||||||
|
|
||||||
def perform_actions(self, path):
|
def perform_actions(self, path):
|
||||||
for action in self.actions:
|
for spec, func, args in self.actions:
|
||||||
if isinstance(action, tuple):
|
|
||||||
func = action[0]
|
|
||||||
args = action[1:]
|
|
||||||
else:
|
|
||||||
func = action
|
|
||||||
args = []
|
|
||||||
func = edbob.load_spec(func)
|
|
||||||
func(path, *args)
|
func(path, *args)
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,7 +70,7 @@ def get_pid_path():
|
||||||
return '/tmp/%s_filemon.pid' % basename
|
return '/tmp/%s_filemon.pid' % basename
|
||||||
|
|
||||||
|
|
||||||
def start_daemon():
|
def start_daemon(appname, daemonize=True):
|
||||||
"""
|
"""
|
||||||
Starts the file monitor daemon.
|
Starts the file monitor daemon.
|
||||||
"""
|
"""
|
||||||
|
@ -84,19 +83,16 @@ def start_daemon():
|
||||||
wm = pyinotify.WatchManager()
|
wm = pyinotify.WatchManager()
|
||||||
notifier = pyinotify.Notifier(wm)
|
notifier = pyinotify.Notifier(wm)
|
||||||
|
|
||||||
monitored = {}
|
monitored = get_monitor_profiles(appname)
|
||||||
keys = edbob.config.require('edbob.filemon', 'monitored')
|
|
||||||
keys = keys.split(',')
|
|
||||||
for key in keys:
|
|
||||||
key = key.strip()
|
|
||||||
monitored[key] = MonitorProfile(key)
|
|
||||||
|
|
||||||
mask = pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO
|
mask = pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO
|
||||||
for profile in monitored.itervalues():
|
for profile in monitored.itervalues():
|
||||||
for path in profile.dirs:
|
for path in profile.dirs:
|
||||||
wm.add_watch(path, mask, proc_fun=EventHandler(actions=profile.actions))
|
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():
|
def stop_daemon():
|
||||||
|
@ -113,7 +109,7 @@ def stop_daemon():
|
||||||
pid = f.read().strip()
|
pid = f.read().strip()
|
||||||
f.close()
|
f.close()
|
||||||
if not pid.isdigit():
|
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
|
return
|
||||||
|
|
||||||
os.kill(int(pid), signal.SIGKILL)
|
os.kill(int(pid), signal.SIGKILL)
|
||||||
|
|
16
setup.py
16
setup.py
|
@ -104,6 +104,13 @@ extras = {
|
||||||
'Sphinx', # 1.1.3
|
'Sphinx', # 1.1.3
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'filemon': [
|
||||||
|
#
|
||||||
|
# package # low high
|
||||||
|
|
||||||
|
# This is just a placeholder on Windows; Linux requires this extra.
|
||||||
|
],
|
||||||
|
|
||||||
'pyramid': [
|
'pyramid': [
|
||||||
#
|
#
|
||||||
# package # low high
|
# package # low high
|
||||||
|
@ -147,7 +154,7 @@ if sys.platform == 'win32':
|
||||||
'py-bcrypt-w32', # 0.2.2
|
'py-bcrypt-w32', # 0.2.2
|
||||||
]
|
]
|
||||||
|
|
||||||
else:
|
elif sys.platform == 'linux2':
|
||||||
|
|
||||||
extras['db'] += [
|
extras['db'] += [
|
||||||
#
|
#
|
||||||
|
@ -156,6 +163,13 @@ else:
|
||||||
'py-bcrypt', # 0.2
|
'py-bcrypt', # 0.2
|
||||||
]
|
]
|
||||||
|
|
||||||
|
extras['filemon'] += [
|
||||||
|
#
|
||||||
|
# package # low high
|
||||||
|
|
||||||
|
'pyinotify', # 0.9.3
|
||||||
|
]
|
||||||
|
|
||||||
extras['pyramid'] += [
|
extras['pyramid'] += [
|
||||||
#
|
#
|
||||||
# package # low high
|
# package # low high
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue