当前位置: 首页>>代码示例>>Python>>正文


Python pyinotify.WatchManager方法代码示例

本文整理汇总了Python中pyinotify.WatchManager方法的典型用法代码示例。如果您正苦于以下问题:Python pyinotify.WatchManager方法的具体用法?Python pyinotify.WatchManager怎么用?Python pyinotify.WatchManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyinotify的用法示例。


在下文中一共展示了pyinotify.WatchManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: watch

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def watch(watch_file):
	'''
	Watch the given file for changes
	'''
	
	wm = WatchManager()

	with TailHandler(watch_file) as th:

		notifier = Notifier(wm, th)
		wdd = wm.add_watch(watch_file, TailHandler.MASK)

		notifier.loop()

		# flush queue before exiting
		th.publish_queue.publish()


	print 'Exiting' 
开发者ID:adlnet-archive,项目名称:edx-xapi-bridge,代码行数:21,代码来源:__main__.py

示例2: run

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def run(self):
        self.running = True
        wm = pyinotify.WatchManager()
        notifier = pyinotify.Notifier(wm)

        def inotify_callback(event):
            if event.mask == pyinotify.IN_CLOSE_WRITE:
                self._parse_desktop_file(event.pathname)

            elif event.mask == pyinotify.IN_DELETE:
                with self.lock:
                    for cmd, data in self.apps.items():
                        if data[2] == event.pathname:
                            del self.apps[cmd]
                            break

        for p in DESKTOP_PATHS:
            if os.path.exists(p):
                wm.add_watch(p,
                             pyinotify.IN_CLOSE_WRITE | pyinotify.IN_DELETE,
                             inotify_callback)
        notifier.loop() 
开发者ID:evilsocket,项目名称:opensnitch,代码行数:24,代码来源:desktop_parser.py

示例3: setup

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def setup(self):
        """ Set up inotify manager.

            See https://github.com/seb-m/pyinotify/.
        """
        if not pyinotify.WatchManager:
            raise error.UserError("You need to install 'pyinotify' to use %s (%s)!" % (
                self.__class__.__name__, pyinotify._import_error)) # pylint: disable=E1101, W0212

        self.manager = pyinotify.WatchManager()
        self.handler = TreeWatchHandler(job=self)
        self.notifier = pyinotify.AsyncNotifier(self.manager, self.handler)

        if self.LOG.isEnabledFor(logging.DEBUG):
            mask = pyinotify.ALL_EVENTS
        else:
            mask = pyinotify.IN_CLOSE_WRITE | pyinotify.IN_MOVED_TO # bogus pylint: disable=E1101

        # Add all configured base dirs
        for path in self.config.path:
            self.manager.add_watch(path.strip(), mask, rec=True, auto_add=True) 
开发者ID:pyroscope,项目名称:pyrocore,代码行数:23,代码来源:watch.py

示例4: _loop_linux

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def _loop_linux(self, loop_callback):
        """loop implementation for linux platform"""
        import pyinotify
        handler = self._handle
        class EventHandler(pyinotify.ProcessEvent):
            def process_default(self, event):
                handler(event)

        watch_manager = pyinotify.WatchManager()
        event_handler = EventHandler()
        notifier = pyinotify.Notifier(watch_manager, event_handler)

        mask = pyinotify.IN_CLOSE_WRITE | pyinotify.IN_MOVED_TO
        for watch_this in self.watch_dirs:
            watch_manager.add_watch(watch_this, mask)

        notifier.loop(loop_callback) 
开发者ID:pydoit,项目名称:doit,代码行数:19,代码来源:filewatch.py

示例5: file_monitor

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def file_monitor(path='.', client=None):
    wm = WatchManager()
    mask = IN_DELETE | IN_CREATE | IN_MODIFY
    notifier = AsyncNotifier(wm, EventHandler(client))
    wm.add_watch(path, mask, auto_add=True, rec=True)
    if not os.path.isfile(path):
        logger.debug("File %s does not exist." % path)
        sys.exit(3)
    else:
        logger.debug("Now starting monitor file %s." % path)
        global f
        f = open(path, 'r')
        st_size = os.stat(path)[6]
        f.seek(st_size)

    while True:
        try:
            notifier.process_events()
            if notifier.check_events():
                notifier.read_events()
        except KeyboardInterrupt:
            print "keyboard Interrupt."
            notifier.stop()
            break 
开发者ID:zsjtoby,项目名称:DevOpsCloud,代码行数:26,代码来源:run_server.py

示例6: __init__

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def __init__(self, config, corpusManager):
        self.wm = pyinotify.WatchManager()
        self.mask = pyinotify.IN_CREATE
        self.handler = FileWatcherEventHandler(corpusManager)
        self.wdd = None
        self.config = config 
开发者ID:dobin,项目名称:ffw,代码行数:8,代码来源:honggcorpusmanager.py

示例7: linux_event_handler

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def linux_event_handler(logger, dir_watch_data, cond, tasks):
        watch_manager = pyinotify.WatchManager()
        mask = pyinotify.IN_CLOSE_WRITE | pyinotify.IN_MOVED_TO | pyinotify.IN_MODIFY | pyinotify.IN_CREATE
        for dir_watch in dir_watch_data:
            logger.info(_(u'Watching directory %s' % dir_watch['path']))
            watch_manager.add_watch(path=dir_watch['path'], mask=mask, rec=False, auto_add=True, do_glob=True)
        handler = LinuxEventHandler(logger=logger, dir_watch_data=dir_watch_data, cond=cond, tasks=tasks)
        notifier = pyinotify.Notifier(watch_manager, handler)
        notifier.loop()
        # end of linux-specific ################################################################################## 
开发者ID:abhishek-ram,项目名称:pyas2,代码行数:12,代码来源:runas2daemon.py

示例8: main

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def main():
    (options, args) = parser.parse_args()
    if None in [options.watch_dir, options.backup_dir]:
        parser.print_help()
        return

    # 删除最后的 /
    options.watch_dir = options.watch_dir.rstrip('/')
    options.backup_dir = options.backup_dir.rstrip('/')

    global watch_dir_name
    global back_dir_name
    watch_dir_name = options.watch_dir
    back_dir_name = options.backup_dir

    logger.info('watch dir %s' % options.watch_dir)
    logger.info('back  dir %s' % options.backup_dir)

    if not options.disable_backup:
        backup_monitor_dir(options.watch_dir, options.backup_dir)

    # watch manager
    wm = pyinotify.WatchManager()
    wm.add_watch(options.watch_dir, pyinotify.ALL_EVENTS, rec=True)
    wm.add_watch(options.backup_dir, pyinotify.ALL_EVENTS, rec=True)

    # event handler
    eh = FileEventHandler()

    # notifier
    notifier = pyinotify.Notifier(wm, eh)
    notifier.loop() 
开发者ID:restran,项目名称:hacker-scripts,代码行数:34,代码来源:monitor.py

示例9: __init__

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def __init__(self, file_created_captured, file_modified_captured):
		self.WATCHDIR = u'/tmp'
		
		self.file_created_captured = file_created_captured
		self.file_modified_captured = file_modified_captured
		
		self.wm = pyinotify.WatchManager()  # Watch Manager
		self.mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE  | pyinotify.IN_MODIFY # watched events
		
		self.notifier = pyinotify.Notifier(self.wm, self)
		self.wdd = self.wm.add_watch(self.WATCHDIR, self.mask, rec = True) 
开发者ID:turingsec,项目名称:marsnake,代码行数:13,代码来源:fs_change_linux.py

示例10: __init__

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def __init__(self, file_paths, watch_mask=FILE_CHANGE_MASK):
        self.inotify_watch_manager = pyinotify.WatchManager()
        self._file_paths = file_paths
        self._event_handler = ModifiedFileEventHandler(callback=self._reload_modified_file)
        self._inotify_notifier = pyinotify.Notifier(self.inotify_watch_manager, default_proc_fun=self._event_handler)
        self._loop_thread = threading.Thread(target=self._inotify_notifier.loop, daemon=True)
        for file_path in self._file_paths:
            self.inotify_watch_manager.add_watch(file_path, watch_mask)
        self._loop_thread.start()
        atexit.register(self._shutdown) 
开发者ID:Tufin,项目名称:pytos,代码行数:12,代码来源:file_monitor.py

示例11: __init__

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def __init__(
        self,
        instances_to_bounce: DelayDeadlineQueueProtocol,
        cluster: str,
        config: SystemPaastaConfig,
        **kwargs: Any,
    ) -> None:
        super().__init__(instances_to_bounce, cluster, config)
        self.wm = pyinotify.WatchManager()
        self.wm.add_watch(DEFAULT_SOA_DIR, self.mask, rec=True)
        self.notifier = pyinotify.Notifier(
            watch_manager=self.wm,
            default_proc_fun=YelpSoaEventHandler(filewatcher=self),
        ) 
开发者ID:Yelp,项目名称:paasta,代码行数:16,代码来源:watchers.py

示例12: start_config_watch

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def start_config_watch(self):
        wm = pyinotify.WatchManager()
        wm.add_watch('./config/mitmf.conf', pyinotify.IN_MODIFY)
        notifier = pyinotify.Notifier(wm, self)
        
        t = threading.Thread(name='ConfigWatcher', target=notifier.loop)
        t.setDaemon(True)
        t.start() 
开发者ID:paranoidninja,项目名称:piSociEty,代码行数:10,代码来源:configwatcher.py

示例13: _watch_file

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def _watch_file(self):
        mask = pyinotify.IN_MOVED_FROM | pyinotify.IN_DELETE
        watch_manager = pyinotify.WatchManager()
        handler = _FileKeeper(watched_handler=self,
                              watched_file=self._log_file)
        notifier = _EventletThreadedNotifier(
            watch_manager,
            default_proc_fun=handler,
            read_freq=FastWatchedFileHandler.READ_FREQ,
            timeout=FastWatchedFileHandler.TIMEOUT)
        notifier.daemon = True
        watch_manager.add_watch(self._log_dir, mask)
        notifier.start() 
开发者ID:openstack,项目名称:oslo.log,代码行数:15,代码来源:watchers.py

示例14: watch_folder

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def watch_folder(module, params):
    log.debug('Watching folder %s for screenshots ...' % params['in'])
    screen_wm = pyinotify.WatchManager()
    screen_mask = pyinotify.IN_CLOSE_WRITE
    screen_notifier = pyinotify.AsyncNotifier(screen_wm, ScreenshotHandler())
    screen_wdd = screen_wm.add_watch(params['in'], screen_mask, rec = True)
    asyncore.loop() 
开发者ID:wavestone-cdt,项目名称:dyode,代码行数:9,代码来源:screen.py

示例15: watch_folder

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import WatchManager [as 别名]
def watch_folder(properties):
    log.debug('Function "folder" launched with params %s: ' % properties)

    # inotify kernel watchdog stuff
    wm = pyinotify.WatchManager()
    mask = pyinotify.IN_CLOSE_WRITE
    notifier = pyinotify.AsyncNotifier(wm, EventHandler())
    wdd = wm.add_watch(properties['in'], mask, rec = True)
    log.debug('watching :: %s' % properties['in'])
    asyncore.loop() 
开发者ID:wavestone-cdt,项目名称:dyode,代码行数:12,代码来源:dyode_in.py


注:本文中的pyinotify.WatchManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。