本文整理汇总了Python中pyinotify.WatchManager类的典型用法代码示例。如果您正苦于以下问题:Python WatchManager类的具体用法?Python WatchManager怎么用?Python WatchManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WatchManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: enabled
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
开发者ID:Muges,项目名称:quodlibet,代码行数:31,代码来源:auto_library_update.py
示例2: watch_files
def watch_files(paths, mask):
"""
Vigila los ficheros de path y encola en queue los eventos producidos.
"""
watcher = WatchManager()
mask = (EventsCodes.ALL_FLAGS.get('IN_MODIFY', 0))
@asyncio.coroutine
def send_event(event):
"""Encola un evento en la cola."""
yield from event_queue.put(event)
notifier = ThreadedNotifier(
watcher,
lambda e: asyncio.get_event_loop().call_soon_threadsafe(
asyncio.async, send_event(e)))
for path in paths:
watcher.add_watch(path, mask, rec=True)
while True:
notifier.process_events()
event_present = yield from asyncio.get_event_loop().run_in_executor(
None, notifier.check_events)
if event_present:
notifier.read_events()
开发者ID:cmonteroes,项目名称:geoffrey,代码行数:27,代码来源:server.py
示例3: directory
def directory(directory, patterns):
"""
This method monitors a directory given by the "*directory*" parameter.
It creates a notifier object. The notifier is registered to await
the "*CLOSE_WRITE*" event on a new file that matches the "*pattern*"
parameter. If there is no such event, it yields control on timeout,
defaulted to 1 second. It returns the created notifier.
Parameters
----------
file : str
File Name including path
patterns : list
A list of strings representing file extension
Returns
-------
None
"""
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CLOSE_WRITE(self, event):
for pattern in patterns:
file = event.pathname
if file.endswith(pattern):
files.put(event.pathname)
break
wm = WatchManager()
mask = pyinotify.IN_CLOSE_WRITE
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler, timeout=1)
wdd = wm.add_watch(directory, mask, rec=False)
return notifier
开发者ID:bfrosik,项目名称:data-quality,代码行数:35,代码来源:accumulator.py
示例4: main
def main():
vm = WatchManager()
vm.add_watch(monitor_dirs,ALL_EVENTS,rec = True)
en = MyEvent()
notifier = Notifier(vm,en)
notifier.loop()
开发者ID:weekday,项目名称:jiankong,代码行数:7,代码来源:pyinotify_file.py
示例5: watch_path
def watch_path(path, add_watch_opt=None, watcher_opt=None):
"""Tail all the files specify by path.
path: By default all files under the path, which should be a directory, are tailed.
Path could also be list of paths or a glob pattern.
The behavior can be modified by add_watch_opt.
See pyinotify.WatchManager.add_watch.
output: defaults to stdout.
can be diverted any callable with:
watcher_opt=dict(out=got_log_line)
where got_log_line() takes a tuple (log_path, log_line)
*_opt: Are pass-through to pyinotify.WatchManager.add_watch and tailall.Monitor.
See respective functions for detail.
"""
wm = WatchManager()
notifier = Notifier(wm, default_proc_fun=FsEvent())
#mask=ALL_EVENTS
#mask=IN_MOVED_TO|IN_CREATE|IN_MODIFY
mask=IN_MODIFY|IN_CLOSE_WRITE
kw=dict(rec=True, auto_add=False)
kw.update(add_watch_opt or {})
wm.add_watch(path, mask, **kw)
monitor=Monitor(watcher_opt=watcher_opt)
notifier.loop(callback=monitor.got_event)
开发者ID:tengu,项目名称:tailall,代码行数:29,代码来源:tailall.py
示例6: fsMonitor
def fsMonitor(path="/data"):
wm = WatchManager()
mask = IN_DELETE | IN_MODIFY | IN_CREATE
notifier = Notifier(wm, EventHandler(), read_freq=10)
notifier.coalesce_events()
wm.add_watch(path, mask, rec=True, auto_add=True)
notifier.loop()
开发者ID:soone,项目名称:docker-rsync,代码行数:7,代码来源:pyrsync.py
示例7: watch
def watch(pathes, extensions):
manager = WatchManager()
handler = Handler(extensions=extensions)
notifier = Notifier(manager, default_proc_fun=handler)
for path in pathes:
manager.add_watch(path, IN_MODIFY, rec=True, auto_add=True)
notifier.loop()
开发者ID:zweifisch,项目名称:wsgi-supervisor,代码行数:7,代码来源:supervisor.py
示例8: enabled
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
开发者ID:MikeiLL,项目名称:quodlibet,代码行数:29,代码来源:auto_library_update.py
示例9: run
def run(self, location='.'):
transport = get_transport(location)
root = transport.local_abspath('.')
new_dirs = set('.')
relpaths = set('.')
while relpaths:
relpath = relpaths.pop()
paths = transport.list_dir(relpath)
for path in paths:
st = transport.stat(relpath + '/' + path)
if S_ISDIR(st.st_mode):
if path != '.bzr':
new_dirs.add(relpath + '/' + path)
relpaths.add(relpath + '/' + path)
# gather all dirs
wm = WatchManager()
added_flag = False
handler = ProcessClose()
handler._bzr_wm = wm
notifier = Notifier(wm, handler)
# read and process events
try:
while True:
if new_dirs:
for path in new_dirs:
wm.add_watch(root + '/' + path, dir_mask)
new_dirs = set()
notifier.process_events()
if notifier.check_events():
notifier.read_events()
finally:
notifier.stop()
开发者ID:davedoman,项目名称:dotfiles,代码行数:32,代码来源:__init__.py
示例10: add_watch
def add_watch(self, path):
if path not in self.watching_paths:
wm = WatchManager()
notifier = QNotifier(wm, self._emit_signal_on_change)
notifier.start()
wm.add_watch(path, mask, rec=True, auto_add=True)
self.watching_paths[path] = notifier
开发者ID:aguzubiaga,项目名称:ninja-ide,代码行数:7,代码来源:linux.py
示例11: TrackState
class TrackState(State, ProcessEvent):
mask = (EventsCodes.OP_FLAGS['IN_DELETE']
| EventsCodes.OP_FLAGS['IN_CLOSE_WRITE'])
def __init__(self, *args, **kwargs):
State.__init__(self, *args, **kwargs)
self.wm = WatchManager()
self.notifier = Notifier(self.wm, self)
def process_IN_CLOSE_WRITE(self, event):
debug("IN_CLOSE_WRITE: %r" % (event,))
path = os.path.join(event.path, event.name)
if os.path.isfile(path) and self.acceptable(path):
self.upload(self.filename_to_File(path))
def process_IN_DELETE(self, event):
debug("IN_DELETE: %r" % (event,))
path = os.path.join(event.path, event.name)
if self.acceptable(path):
self.delete(self.filename_to_File(path))
def run(self):
for f in self.files:
f = os.path.abspath(f)
self.wm.add_watch(f, self.mask, rec=True, auto_add=True)
try:
while True:
self.notifier.process_events()
if self.notifier.check_events(100):
self.notifier.read_events()
sleep(0)
except KeyboardInterrupt:
self.notifier.stop()
开发者ID:pombredanne,项目名称:autosync,代码行数:33,代码来源:daemon.py
示例12: run
def run(self):
self.pclose = PClose(self.path)
PC = self.pclose
# only watch these events
mask = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE
# watch manager instance
wm = WatchManager()
notifier = Notifier(wm, PC)
print 'monitoring of %s started' % self.path
added_flag = False
# read and process events
while True:
try:
if not added_flag:
# on first iteration, add a watch on path:
# watch path for events handled by mask.
wm.add_watch(self.path, mask)
added_flag = True
notifier.process_events()
if notifier.check_events():
notifier.read_events()
except KeyboardInterrupt:
# ...until c^c signal
print 'stop monitoring...'
# stop monitoring
notifier.stop()
break
except Exception, err:
# otherwise keep on watching
print err
开发者ID:boykov,项目名称:eab-auto,代码行数:33,代码来源:watch_share.py
示例13: create_notifier
def create_notifier(topic, instrument, posttroll_port, filepattern,
event_names, monitored_dirs, aliases=None,
tbus_orbit=False, history=0, granule_length=0):
'''Create new notifier'''
# Event handler observes the operations in defined folder
manager = WatchManager()
# Collect mask for events that are monitored
if type(event_names) is not list:
event_names = event_names.split(',')
event_mask = 0
for event in event_names:
try:
event_mask |= getattr(pyinotify, event)
except AttributeError:
LOGGER.warning('Event ' + event + ' not found in pyinotify')
event_handler = EventHandler(topic, instrument,
posttroll_port=posttroll_port,
filepattern=filepattern,
aliases=aliases,
tbus_orbit=tbus_orbit,
history=history,
granule_length=granule_length)
notifier = NewThreadedNotifier(manager, event_handler)
# Add directories and event masks to watch manager
for monitored_dir in monitored_dirs:
manager.add_watch(monitored_dir, event_mask, rec=True)
return notifier
开发者ID:tparker-usgs,项目名称:trollduction,代码行数:33,代码来源:trollstalker.py
示例14: LinuxFileSysMonitor
class LinuxFileSysMonitor(FileSysMonitor):
"""File system monitor thread"""
def __init__(self, name=None):
super(LinuxFileSysMonitor, self).__init__(name)
self.defaultMask = IN_DELETE | IN_CREATE | IN_MODIFY | IN_MOVED_TO | IN_MOVED_FROM
self.wm = WatchManager()
self.__lock = threading.Lock()
def addWatch(self, path, mask=None):
"""Add watch for path"""
super(LinuxFileSysMonitor, self).addWatch(path, mask)
if not mask:
mask = self.defaultMask
self.wm.add_watch(path, mask, auto_add=True, rec=True)
def run(self):
"""Thread entry"""
super(LinuxFileSysMonitor, self).run()
self.notifier = Notifier(self.wm, EventHandler(None, fsMonitor = self))
while not self.threadStop:
self.processMsg(1)
if self.notifier.check_events(1000):
self.notifier.read_events()
self.notifier.process_events()
def stop(self):
"""Stop watch"""
super(LinuxFileSysMonitor, self).stop()
self.notifier.stop()
开发者ID:harite,项目名称:BaiduYunPanPython,代码行数:30,代码来源:FSMonitor.py
示例15: persy_start
def persy_start(self):
"""
initializes the worker thread and notifier
"""
self.log.info("start working")
self.log.setStart()
self.running = True
FLAGS=EventsCodes.ALL_FLAGS
mask = FLAGS['IN_MODIFY'] | FLAGS['IN_DELETE_SELF']|FLAGS['IN_DELETE'] | FLAGS['IN_CREATE'] | FLAGS['IN_CLOSE_WRITE'] | FLAGS['IN_MOVE_SELF'] | FLAGS['IN_MOVED_TO'] | FLAGS['IN_MOVED_FROM'] # watched events
wm = WatchManager()
#addin the watched directories
for watch in self.config['local']['watched']:
wdd = wm.add_watch("%s"%(watch), mask, rec=True, auto_add=True)
#watch for changes of the configurationfile
if self.config['general']['autoshare']:
wdd = wm.add_watch(self.config.getAttribute('CONFIGFILE'), mask, rec=True, auto_add=True)
self.log.debug("init the syncer")
self.worker = TheSyncer(self, self.config, self.log, self.config['remote']['sleep'], self.config['local']['sleep'])
self.log.debug("init the filesystem notifier")
self.notifier = ThreadedNotifier(wm, FileChangeHandler(self.log, self.worker.newEvent))
self.log.resetError()
self.log.debug("starting syncer")
self.worker.start()
self.notifier.start()
开发者ID:rroemhild,项目名称:persy,代码行数:27,代码来源:persy_core.py
示例16: _reloader_inotify
def _reloader_inotify(fnames, interval=None):
#: Mutated by inotify loop when changes occur.
changed = [False]
# Setup inotify watches
from pyinotify import WatchManager, EventsCodes, Notifier
wm = WatchManager()
mask = "IN_DELETE_SELF IN_MOVE_SELF IN_MODIFY IN_ATTRIB".split()
mask = reduce(lambda m, a: m | getattr(EventsCodes, a), mask, 0)
def signal_changed(event):
if changed[0]:
return
_log('info', ' * Detected change in %r, reloading' % event.path)
changed[:] = [True]
for fname in fnames:
wm.add_watch(fname, mask, signal_changed)
# ... And now we wait...
notif = Notifier(wm)
try:
while not changed[0]:
notif.process_events()
if notif.check_events(timeout=interval):
notif.read_events()
# TODO Set timeout to something small and check parent liveliness
finally:
notif.stop()
sys.exit(3)
开发者ID:strogo,项目名称:werkzeug,代码行数:30,代码来源:serving.py
示例17: main
def main(argv):
if len(argv) == 1:
print "Usage: %s [file]" % argv[0]
return 1
path = argv[1]
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s",
datefmt="%H:%M:%S",
filename=None
# filename = "/tmp/filemon.log"
)
logging.debug("Init Watcher (%s)" % path)
class PClose(ProcessEvent):
def process_default(self, event):
logging.info("%s: %s: %s" % (getusers(event.pathname), event.pathname, str(event.maskname)))
wm = WatchManager()
notifier = Notifier(wm, PClose())
wm.add_watch(path, EventsCodes.ALL_FLAGS["ALL_EVENTS"], rec=True)
logging.info("Waiting for updates")
while True:
notifier.process_events()
if notifier.check_events():
notifier.read_events()
return 0
开发者ID:shish,项目名称:filemon,代码行数:32,代码来源:filemon.py
示例18: Notify
class Notify():
def __init__(self):
self.wm = WatchManager()
self.pe = ProcessNotifyEvents()
self.notifier = ThreadedNotifier(self.wm, self.pe)
self.notifier.start()
self.path = None
#thread.start_new_thread(self.jobTask, (self,))
def setNotify(self, path, cbfun):
#print 'setnotify ' + path
if self.path:
self.wm.rm_watch(list(self.wdd.values()))
self.path = path
self.pe.cbfun = cbfun # ugly...
#print sys.getfilesystemencoding()
self.wdd = self.wm.add_watch(self.path,
pyinotify.IN_CREATE |
pyinotify.IN_DELETE |
pyinotify.IN_MOVED_TO |
pyinotify.IN_MOVED_FROM |
pyinotify.IN_MODIFY)
def stop(self):
if self.path:
self.wm.rm_watch(list(self.wdd.values()))
self.notifier.stop()
def notifyThread(self):
while 1:
notifier.process_events()
if notifier.check_events():
notifier.read_events()
开发者ID:suncore,项目名称:dflynav,代码行数:33,代码来源:vfs_fsNotify_Linux.py
示例19: FSMonitor
def FSMonitor(path='/root/wpf'):
wm = WatchManager()
mask = IN_DELETE | IN_MODIFY | IN_CREATE
notifier = Notifier(wm, EventHandler(),read_freq=10)
notifier.coalesce_events()
# 设置受监视的事件,这里只监视文件创建事件,(rec=True, auto_add=True)为递归处理
wm.add_watch(path,mask,rec=True, auto_add=True)
notifier.loop()
开发者ID:ading2016,项目名称:My_Repo,代码行数:8,代码来源:notify.py
示例20: add_watch
def add_watch(self, path):
if path not in self.watching_paths:
wm = WatchManager()
notifier = QNotifier(wm, self._emit_signal_on_change)
notifier.start()
exclude = ExcludeFilter([os.path.join(path, folder) for folder in self._ignore_hidden])
wm.add_watch(path, mask, rec=True, auto_add=True, exclude_filter=exclude)
self.watching_paths[path] = notifier
开发者ID:ktosiu,项目名称:ninja-ide,代码行数:8,代码来源:linux.py
注:本文中的pyinotify.WatchManager类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论