本文整理汇总了Python中pyinotify.Notifier.start方法的典型用法代码示例。如果您正苦于以下问题:Python Notifier.start方法的具体用法?Python Notifier.start怎么用?Python Notifier.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyinotify.Notifier
的用法示例。
在下文中一共展示了Notifier.start方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AutoLibraryUpdate
# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import start [as 别名]
class AutoLibraryUpdate(EventPlugin):
PLUGIN_ID = "Automatic library update"
PLUGIN_NAME = _("Automatic Library Update")
PLUGIN_DESC = _("Keeps your library up to date with inotify. "
"Requires %s.") % "pyinotify"
# TODO: make a config option
USE_THREADS = True
event_handler = None
running = False
def enabled(self):
if not self.running:
wm = WatchManager()
self.event_handler = LibraryEvent(app.library)
# Choose event types to watch for
# FIXME: watch for IN_CREATE or for some reason folder copies
# are missed, --nickb
FLAGS = ['IN_DELETE', 'IN_CLOSE_WRITE',# 'IN_MODIFY',
'IN_MOVED_FROM', 'IN_MOVED_TO', 'IN_CREATE']
mask = reduce(lambda x, s: x | EventsCodes.ALL_FLAGS[s], FLAGS, 0)
if self.USE_THREADS:
print_d("Using threaded notifier")
self.notifier = ThreadedNotifier(wm, self.event_handler)
# Daemonize to ensure thread dies on exit
self.notifier.daemon = True
self.notifier.start()
else:
self.notifier = Notifier(wm, self.event_handler, timeout=100)
GLib.timeout_add(1000, self.unthreaded_callback)
for path in get_scan_dirs():
print_d('Watching directory %s for %s' % (path, FLAGS))
# See https://github.com/seb-m/pyinotify/wiki/
# Frequently-Asked-Questions
wm.add_watch(path, mask, rec=True, auto_add=True)
self.running = True
def unthreaded_callback(self):
"""Processes as much of the inotify events as allowed"""
assert self.notifier._timeout is not None, \
'Notifier must be constructed with a [short] timeout'
self.notifier.process_events()
# loop in case more events appear while we are processing
while self.notifier.check_events():
self.notifier.read_events()
self.notifier.process_events()
return True
# disable hook, stop the notifier:
def disabled(self):
if self.running:
self.running = False
if self.notifier:
print_d("Stopping inotify watch...")
self.notifier.stop()
示例2: process_IN_DELETE
# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import start [as 别名]
print "Create:%s" % os.path.join(event.path, event.name)
def process_IN_DELETE(self, event):
print "Remove:%s" % os.path.join(event.path, event.name)
notifier = Notifier(wm, PTmp())
wdd = wm.add_watch("/tmp", mask, rec=True)
while True:
try:
notifier.process_events()
if notifier.check_events():
notifier.read_events()
#todo
print '.',
except KeyboardInterrupt:
notifier.stop()
break
notifier = ThreadedNotitier(wm, PTmp())
notifier.start()
wdd = wm.add_watch('/tmp', mask, rec=True)
if wdd['/tmp']>0:
wm.rm_watch(wdd['/tmp'])
#wm.rm_watch(wdd['/tmp'], rec=True)
wm.rm_watch(wdd.values())
notifier.stop()
示例3: AutoLibraryUpdate
# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import start [as 别名]
class AutoLibraryUpdate(EventPlugin):
PLUGIN_ID = "Automatic library update"
PLUGIN_NAME = _("Automatic Library Update")
PLUGIN_DESC = _("Keeps your library up to date with inotify. "
"Requires %s.") % "pyinotify"
PLUGIN_ICON = Icons.VIEW_REFRESH
# TODO: make a config option
USE_THREADS = True
event_handler = None
running = False
def enabled(self):
if not self.running:
wm = WatchManager()
self.event_handler = LibraryEvent(library=app.library)
FLAGS = ['IN_DELETE', 'IN_CLOSE_WRITE', # 'IN_MODIFY',
'IN_MOVED_FROM', 'IN_MOVED_TO', 'IN_CREATE']
masks = [EventsCodes.FLAG_COLLECTIONS['OP_FLAGS'][s]
for s in FLAGS]
mask = reduce(operator.or_, masks, 0)
if self.USE_THREADS:
print_d("Using threaded notifier")
self.notifier = ThreadedNotifier(wm, self.event_handler)
# Daemonize to ensure thread dies on exit
self.notifier.daemon = True
self.notifier.start()
else:
self.notifier = Notifier(wm, self.event_handler, timeout=100)
GLib.timeout_add(1000, self.unthreaded_callback)
for path in get_scan_dirs():
real_path = os.path.realpath(path)
print_d('Watching directory %s for %s (mask: %x)'
% (real_path, FLAGS, mask))
# See https://github.com/seb-m/pyinotify/wiki/
# Frequently-Asked-Questions
wm.add_watch(real_path, mask, rec=True, auto_add=True)
self.running = True
def unthreaded_callback(self):
"""Processes as much of the inotify events as allowed"""
assert self.notifier._timeout is not None, \
'Notifier must be constructed with a [short] timeout'
self.notifier.process_events()
# loop in case more events appear while we are processing
while self.notifier.check_events():
self.notifier.read_events()
self.notifier.process_events()
return True
# disable hook, stop the notifier:
def disabled(self):
if self.running:
self.running = False
if self.notifier:
print_d("Stopping inotify watch...")
self.notifier.stop()