本文整理汇总了Python中pyinotify.ThreadedNotifier类的典型用法代码示例。如果您正苦于以下问题:Python ThreadedNotifier类的具体用法?Python ThreadedNotifier怎么用?Python ThreadedNotifier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ThreadedNotifier类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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
示例2: run
def run(self):
"""
Run notify process in loop.
"""
notifier = ThreadedNotifier(self.wm, EventHandler(), read_freq=0, threshold=0, timeout=10)
self._addWatchers()
notifier.loop()
开发者ID:psusloparov,项目名称:watchdog,代码行数:7,代码来源:watchdog_service.py
示例3: 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
示例4: start_watching_disk_file
def start_watching_disk_file(filename, handler):
logger.info("start watching %s" % filename)
wm = WatchManager()
notifier = ThreadedNotifier(wm, PTmp(wm, filename, handler))
notifier.start()
notifiers[filename] = notifier
if os.path.exists(filename):
handler.on_create(filename)
开发者ID:ChristophGr,项目名称:cryptdisk-control,代码行数:8,代码来源:mountwatcher.py
示例5: watch
def watch(self):
mask = pyinotify.IN_MODIFY | pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO
self.__wm = WatchManager()
self.__wm.add_watch(os.path.join(self.directory, *self.branch_dir), mask, rec = True)
notifier = ThreadedNotifier(self.__wm, self.process_event)
notifier.start()
开发者ID:mireq,项目名称:Git-watcher,代码行数:8,代码来源:gitwatcher.py
示例6: __watch_thread
def __watch_thread(self, root_lst, sync_list, cond, eventq):
"""
初始化客户端监控文件变化的同步线程,根据同步的根目录列表和
需要同步的文件目录白名单,获取需要监控的目录列表以及监控排除的文件列表添加到INotifier中
@param root_lst: 监控的根目录列表
@type root_lst: tuple
@param sync_list: 需要同步的文件和目录的列表
@type sync_list: tuple
@param cond: 线程同步条件变量
@type cond: threading.Condition
@param eventq: 保存文件变化的事件队列
@type eventq: pyinotify.Event
@return: 初始化后的监控线程
@rtype: pyinotify.ThreadedNotifier
"""
wm = WatchManager()
mask = IN_DELETE | IN_CLOSE_WRITE | IN_CREATE | IN_MOVED_FROM | IN_MOVED_TO
thread_notifier = ThreadedNotifier(wm,
EventHandler(cond=cond, eventq=eventq,
sync_list=sync_list),
read_freq=10, timeout=9)
thread_notifier.coalesce_events() # Enable coalescing of events
watch_lst = [] # INotifier watch direcory list
exclude_lst = [] # INotifier exclude directory list
LOGGER.debug('root:%s', str(root_lst))
LOGGER.debug('sublist:%s', str(sync_list))
for root_path in root_lst:
# add root directory to watch list
watch_lst.append(root_path['name'])
if not root_path['is_all']:
# get exclude sub direcory list
for dirpath, _, _ in os.walk(root_path['name']):
if dirpath != root_path['name']:
for file_path in sync_list:
is_exclude = True
if file_path.startswith(dirpath) \
or dirpath.startswith(file_path):
# 遍历的目录为同步列表文件的父目录,
# 或者同步文件列表下的子目录,都不添加到排除目录列表
LOGGER.debug('dirpath:%s', dirpath)
LOGGER.debug('file_path:%s', file_path)
is_exclude = False
break
if is_exclude:
exclude_lst.append(dirpath)
LOGGER.debug('watchlist:%s', str(watch_lst))
LOGGER.debug('excludelist:%s', str(exclude_lst))
excl = ExcludeFilter(exclude_lst)
# 设置受监视的事件,(rec=True, auto_add=True)为递归处理
wm_dict = wm.add_watch(watch_lst, mask, rec=True, auto_add=True,
exclude_filter=excl)
LOGGER.debug('client monitor lst:%s', str(wm_dict))
return thread_notifier
开发者ID:Element-s,项目名称:pyisync,代码行数:55,代码来源:isync_client.py
示例7: PhotoWatcher
class PhotoWatcher(ProcessEvent):
MASK = (EventsCodes.ALL_FLAGS['IN_DELETE'] |
EventsCodes.ALL_FLAGS['IN_CLOSE_WRITE'] |
EventsCodes.ALL_FLAGS['IN_MOVED_FROM'] |
EventsCodes.ALL_FLAGS['IN_MOVED_TO'])
def __init__(self, db, walker, root):
self.root = root
self.db = db
self.walker = walker
self.wm = WatchManager()
self.wdds = []
def Watch(self):
self.notifier = ThreadedNotifier(self.wm, self)
self.notifier.start()
self.wdds.append(self.wm.add_watch(self.root, self.MASK, rec=True))
# add soft link sub-folders
for dirname, dirnames, _filenames in os.walk(self.root, followlinks=True):
for d in dirnames:
path = os.path.join(dirname, d)
if os.path.islink(path):
self.wdds.append(
self.wm.add_watch(os.path.realpath(path), self.MASK, rec=True))
def Stop(self):
self.notifier.stop()
def process_IN_DELETE(self, event):
self.db.DeletePhoto(os.path.join(event.path, event.name))
def process_IN_MOVED_FROM(self, event):
self.process_IN_DELETE(event)
def process_IN_MOVED_TO(self, event):
full_path = os.path.join(event.path, event.name)
try:
meta = self.walker.ReadMetadata(full_path)
except Exception:
return
self.db.StorePhoto(full_path, meta)
def process_IN_CLOSE_WRITE(self, event):
full_path = os.path.join(event.path, event.name)
try:
meta = self.walker.ReadMetadata(full_path)
except Exception:
return
if self.db.HasPhoto(full_path):
self.db.UpdatePhoto(full_path, meta)
else:
self.db.StorePhoto(full_path, meta)
开发者ID:drseergio,项目名称:photofs,代码行数:54,代码来源:watcher.py
示例8: __init__
class FileEvent:
def __init__(self, eventHandler):
self.logger = logging.getLogger('FileEvent')
self.wm = WatchManager()
self.watches = dict()
# Set the flags of the events that are to be listened to
FLAGS = EventsCodes.ALL_FLAGS
self.mask = FLAGS['IN_CREATE'] | FLAGS['IN_DELETE'] | FLAGS['IN_MODIFY'] | FLAGS['IN_DELETE_SELF']
# Set-up notifier
self.notifier = ThreadedNotifier(self.wm, EventProcessor(eventHandler))
def startNotifyLoop(self):
self.notifier.start()
def stopNotifyLoop(self):
self.notifier.stop()
def addWatches(self, paths, mask=None):
added_watches = dict()
for path in paths:
added_watches.update(self.addWatch(path, mask))
return added_watches
# Also monitors all sub-directories of the given directory and automatically adds newly
# created directories to watch.
# TODO should be able to add files as well, but doesn't work atm
def addWatch(self, path, mask=None):
if mask is None:
mask = self.mask
added_watches = self.wm.add_watch(path, mask, rec=True, auto_add=True)
self.watches.update(added_watches)
return added_watches
def removeWatch(self, path):
watch_descriptor = self.wm.get_wd(path)
if watch_descriptor is not None:
result = self.wm.rm_watch(watch_descriptor, rec=True)
# Remove the no longer active watches from the current watches dictionary
for key, value in self.watches.items():
if value in result:
del self.watches[key]
else:
result = None
return result
def getWatches(self):
return self.watches
开发者ID:vesz,项目名称:kempt,代码行数:52,代码来源:file_event.py
示例9: schedule
def schedule(self, name, event_handler, *paths):
"""Schedules monitoring."""
#from pyinotify import PrintAllEvents
#dispatcher = PrintAllEvents()
dispatcher = _ProcessEventDispatcher(event_handler=event_handler)
notifier = ThreadedNotifier(self.wm, dispatcher)
self.notifiers.add(notifier)
for path in paths:
if not isinstance(path, str):
raise TypeError(
"Path must be string, not '%s'." % type(path).__name__)
descriptors = self.wm.add_watch(path, ALL_EVENTS, rec=True, auto_add=True)
self.name_to_rule[name] = _Rule(name, notifier, descriptors)
notifier.start()
开发者ID:stpremkumar,项目名称:watchdog,代码行数:14,代码来源:inotify_observer.py
示例10: live
def live(path, tv):
chromedriver = os.path.join(os.path.split(os.path.realpath(__file__))[0],\
'chromedriver')
os.environ['webdriver.chrome.driver'] = chromedriver
browsers = [ getattr(webdriver, browser.title())() \
for browser in [s.lower() for s in tv]]
wm = WatchManager()
notifier = ThreadedNotifier(wm, ProcessDir(browsers))
notifier.start()
print('watching %s' % os.path.abspath(path))
mask = IN_MODIFY
wdd = wm.add_watch(path, mask, rec=True)
开发者ID:leilux,项目名称:pagelive,代码行数:14,代码来源:pagelive.py
示例11: setup_inotify
def setup_inotify(self):
if pyinotify is None:
return False
watch_manager = WatchManager()
result = watch_manager.add_watch(self.__status_file, IN_MODIFY)[self.__status_file] > 0
if result:
global notifier
def notify_cb(event):
glib.idle_add(self.check_status_cb)
notifier = ThreadedNotifier(watch_manager, notify_cb)
notifier.start()
return result
开发者ID:jeremybmerrill,项目名称:hdaps_indicator,代码行数:14,代码来源:indicator.py
示例12: 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
示例13: enabled
def enabled( self ):
if not self.running :
self.wm = WatchManager()
# the event handler will do the actual event processing,
# see the ALE class below for details
self.event_handler = self.ALE( self )
# we'll use a threaded notifier flagged as a daemon thread
# so that it will stop when QL does
self.tn = ThreadedNotifier( self.wm, self.event_handler )
self.tn.daemon = True
self.tn.start()
# mask for watched events:
FLAGS=EventsCodes.ALL_FLAGS
mask = FLAGS['IN_DELETE'] | FLAGS['IN_CLOSE_WRITE']\
| FLAGS['IN_MOVED_FROM'] | FLAGS['IN_MOVED_TO']
# watch paths in scan_list:
for path in self.scan_list():
log ( 'Adding watch: for ' + path )
self.wm.add_watch( path, mask, rec=True )
self.running = True
开发者ID:draxil,项目名称:Auto-library-update-plugin-for-quodlibet,代码行数:25,代码来源:auto_library_update.py
示例14: __init__
def __init__(self, makeRunView):
self.wm = WatchManager()
self.eh = EventHandler(makeRunView)
self.notifier = ThreadedNotifier(self.wm, self.eh)
self.notifier.start()
# Watched events
self.mask = IN_DELETE | IN_CREATE | IN_CLOSE_WRITE
开发者ID:mwidz,项目名称:makeRunView,代码行数:7,代码来源:observer.py
示例15: main
def main():
# Add a dummy message to the queue:
add_msg( MsgTypes.Initialise )
# Setup the HTTP server:
SocketServer.TCPServer.allow_reuse_address = True
HOST, PORT = "localhost", 9000
server = ThreadedHTTPServer((HOST, PORT), MyTCPHandler)
server_thread = threading.Thread(target=server.serve_forever)
server_thread.daemon = True
server_thread.start()
# Setup the heartbeat:
heartbeat_thread = threading.Thread(target=heartbeat_messages)
heartbeat_thread.daemon = True
heartbeat_thread.start()
# Setup pyinotify so files are being watched:
wm = WatchManager()
notifier = ThreadedNotifier(wm, PTmp())
notifier.start()
mask = EventsCodes.ALL_FLAGS['IN_DELETE'] | EventsCodes.ALL_FLAGS['IN_CREATE'] | EventsCodes.ALL_FLAGS['IN_ATTRIB'] |EventsCodes.ALL_FLAGS['IN_MODIFY']# watched events
#mask = EventsCodes.ALL_FLAGS['IN_DELETE'] | EventsCodes.ALL_FLAGS['IN_CREATE'] | EventsCodes.ALL_FLAGS['IN_MODIFY']# watched events
wdd = wm.add_watch('../sentry.py', mask, rec=True)
wdd = wm.add_watch('../', mask, rec=True)
try:
while True:
time.sleep(5)
except:
# Turn off pyinotify:
notifier.stop()
print 'Exception caught: shutting down connections'
add_msg(MsgTypes.Shutdown)
time.sleep(0.5)
print 'Terminating...'
raise
开发者ID:mikehulluk,项目名称:python-devtools,代码行数:46,代码来源:test2.py
示例16: loop
def loop(self):
wm = WatchManager()
handler = EventHandler(self.workq, self.src, self.dst)
self.notifier = ThreadedNotifier(wm, handler)
self.notifier.start()
mask = IN_CREATE | IN_MODIFY
wm.add_watch(self.src, mask, rec=self.gdr.rec)
开发者ID:Noncz,项目名称:Sync,代码行数:9,代码来源:Watcher.py
示例17: create_watcher
def create_watcher():
from pyinotify import WatchManager, Notifier, ThreadedNotifier, \
EventsCodes, ProcessEvent, IN_CLOSE_WRITE
wm = WatchManager()
mask = IN_CLOSE_WRITE #| EventsCodes.IN_CREATE # watched events
class PTmp(ProcessEvent):
def process_IN_CLOSE_WRITE(self, event):
def inner(): on_reload_event(event)
gdb.post_event(inner)
notifier = ThreadedNotifier(wm, PTmp())
wdd = wm.add_watch(WORKING_DIR, mask, rec=True)
notifier.daemon = True # Then our atexit function will work
notifier.start()
def on_exited(*e): notifier.stop()
import atexit
atexit.register(on_exited)
return (notifier, wdd)
开发者ID:sublimator,项目名称:ripple-gdb,代码行数:19,代码来源:reloadwatcher.py
示例18: start_daemon
def start_daemon(path, dbpath, md_queue, fd_queue, condition):
""" installs a subtree listener and wait for events """
os.nice(19)
wm_auto = WatchManager()
subtreemask = IN_CLOSE_WRITE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO | IN_CREATE | IN_ISDIR
excludefilter = ExcludeFilter(["(.*)sqlite"])
notifier_sb = ThreadedNotifier(wm_auto, SubtreeListener(dbpath, md_queue, fd_queue, condition))
notifier_sb.start()
THREADS.append(notifier_sb)
wdd_sb = wm_auto.add_watch(path, subtreemask, auto_add=True, rec=True, exclude_filter=excludefilter)
THREADS.append(PollAnalyzer(condition, dbpath))
THREADS[-1].start()
# THREADS.append(CatalogThreadingTCPServer(("localhost", 8080), CatalogHTTPRequestHandler, dbpath))
# THREADS[-1].serve_forever()
THREADS[-1].join()
开发者ID:biappi,项目名称:Scriptcicletti,代码行数:19,代码来源:catalog.py
示例19: lastwatch
def lastwatch(paths, settings, dry_run=False):
flags = EventsCodes.FLAG_COLLECTIONS.get('OP_FLAGS', None)
if flags:
mask = flags.get('IN_OPEN') | flags.get('IN_CLOSE_NOWRITE')
mask |= flags.get('IN_CREATE') | flags.get('IN_MOVED_TO')
else:
mask = EventsCodes.IN_OPEN | EventsCodes.IN_CLOSE_NOWRITE
mask |= EventsCodes.IN_CREATE | EventsCodes.IN_MOVED_TO
wm = WatchManager()
handler = Handler(settings, dry_run=dry_run)
watcher = ThreadedNotifier(wm, handler)
watcher.start()
try:
for path in paths:
path = os.path.realpath(path)
sys.stdout.write(_("Indexing %s for watching...") % path)
sys.stdout.flush()
wm.add_watch(path, mask, rec=True, auto_add=True)
sys.stdout.write(_(" done.") + "\n")
print _("You have successfully launched Lastwatch.")
print "\n".join(wrap(_("The directories you have specified will be "
"monitored as long as this process is running, "
"the flowers are blooming and the earth "
"revolves around the sun..."), 80))
# flowers to devhell ;-)
handler.set_active()
while True:
time.sleep(1)
except KeyboardInterrupt:
watcher.stop()
print _("LastWatch stopped.")
return
except Exception, err:
print err
开发者ID:aszlig,项目名称:LastWatch,代码行数:43,代码来源:lastwatch.py
示例20: Watch
def Watch(self):
self.notifier = ThreadedNotifier(self.wm, self)
self.notifier.start()
self.wdds.append(self.wm.add_watch(self.root, self.MASK, rec=True))
# add soft link sub-folders
for dirname, dirnames, _filenames in os.walk(self.root, followlinks=True):
for d in dirnames:
path = os.path.join(dirname, d)
if os.path.islink(path):
self.wdds.append(
self.wm.add_watch(os.path.realpath(path), self.MASK, rec=True))
开发者ID:drseergio,项目名称:photofs,代码行数:11,代码来源:watcher.py
注:本文中的pyinotify.ThreadedNotifier类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论