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


Python pyinotify.Notifier方法代码示例

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


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

示例1: watch

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [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 Notifier [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: _loop_linux

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [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

示例4: linux_event_handler

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [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

示例5: start

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [as 别名]
def start(self):
        watchPath = self.config["input_dir"]
        self.notifier = pyinotify.Notifier(self.wm, self.handler, timeout=10)
        self.wdd = self.wm.add_watch(watchPath, self.mask, rec=False) 
开发者ID:dobin,项目名称:ffw,代码行数:6,代码来源:honggcorpusmanager.py

示例6: main

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [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

示例7: __init__

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [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

示例8: __init__

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [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

示例9: __init__

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [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

示例10: start_config_watch

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [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

示例11: watch

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [as 别名]
def watch(parent_id=None, mount=False):
    "Watch a folder for new torrents to add"

    if parent_id == None:
        parent_id = app.config.get('PUTIO_ROOT', 0)
    if mount and not os.path.exists(app.config['TORRENTS']):
        subprocess.call([
            'mount',
            '-a'
        ])

    add()

    class EventHandler(pyinotify.ProcessEvent):
        "Event handler for responding to a new or updated torrent file"
        def process_IN_CLOSE_WRITE(self, event):
            "Do the above"
            app.logger.debug('adding torrent, received event: %s' % event)
            transfer = app.client.Transfer.add_torrent(event.pathname, parent_id=parent_id)
            os.unlink(event.pathname)
            app.logger.info('added transfer: %s' % transfer)

    watch_manager = pyinotify.WatchManager()
    mask = pyinotify.IN_CLOSE_WRITE

    handler = EventHandler()
    notifier = pyinotify.Notifier(watch_manager, handler)

    wdd = watch_manager.add_watch(app.config['TORRENTS'], mask, rec=True)
    app.logger.debug('added watch: %s' % wdd)

    notifier.loop() 
开发者ID:datashaman,项目名称:putio-automator,代码行数:34,代码来源:torrents.py

示例12: __init__

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [as 别名]
def __init__(self, listener):
        threading.Thread.__init__(self)
        self.__p = Processor(self, listener)
        self.manager = WatchManager()
        self.notifier = Notifier(self.manager, self.__p)
        self.event = threading.Event()
        self.setDaemon(True)
        self.watches = []
        self.__isSuspended = False 
开发者ID:autokey,项目名称:autokey,代码行数:11,代码来源:monitor.py

示例13: __init__

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [as 别名]
def __init__(self, monitor_path, bcloud_app):

        super(WatchFileChange, self).__init__()
        self.setDaemon(True) 
        self.monitor_path = monitor_path 
        self.bcloud_app = bcloud_app
        self.submitter = TaskSubmitter(self.bcloud_app)
        self.submitter.start()
        self.handler = EventHandler(self.monitor_path, self.bcloud_app,
                                    self.submitter)
        self.wm = pyinotify.WatchManager()
        self.wdds = self.wm.add_watch(self.monitor_path, MASK, rec=True,
                                      auto_add=True)
        self.notifyer = pyinotify.Notifier(self.wm, self.handler) 
开发者ID:XuShaohua,项目名称:bcloud,代码行数:16,代码来源:FileWatcher.py

示例14: main

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [as 别名]
def main(args_ns: argparse.Namespace) -> None:
    tmpdir = tempfile.mkdtemp(prefix="rcrsv-gbstr")  # directory for gobuster scan results

    # watch manager stores the watches and provides operations on watches
    wm = pyinotify.WatchManager()

    version = get_gobuster_version()

    handler = EventHandler(
        target=args_ns.target,
        tmpdir=tmpdir,
        wordlist=args_ns.wordlist,
        threads=args_ns.threads,
        extensions=args_ns.extensions,
        devnull=args.devnull,
        user=args_ns.user,
        password=args_ns.password,
        proxy=args_ns.proxy,
        version=version,
        status=args_ns.status,
    )

    notifier = pyinotify.Notifier(wm, handler)

    # watch for file appends (found dir/file) and files closing (scan complete)
    mask = pyinotify.IN_MODIFY | pyinotify.IN_CLOSE_WRITE

    wm.add_watch(tmpdir, mask)

    handler.run_gobuster(args_ns.target)  # kick off first scan against initial target

    signal.signal(signal.SIGINT, handler.cleanup)  # register signal handler to handle SIGINT

    notifier.loop() 
开发者ID:epi052,项目名称:recursive-gobuster,代码行数:36,代码来源:__main__.py

示例15: main

# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import Notifier [as 别名]
def main():
    parser_description = "Cryptopuck: Encrypt your drives on the fly"
    parser = argparse.ArgumentParser(description=parser_description)
    parser.add_argument("--mountpoint",
                        help="Path to where new volumes are mounted",
                        required=True)
    parser.add_argument("--public-key",
                        help="Path to the public key", required=True)
    args = parser.parse_args()

    if not os.path.isdir(args.mountpoint):
        print("Mountpoint does not exist or not a directory:", args.mountpoint)
        sys.exit(1)

    # Setup the Led Manager
    main_thread = threading.current_thread()
    led_manager = LedManager(main_thread)
    led_thread = threading.Thread(target=led_manager.run)
    led_thread.start()

    # Setup pyInotify
    wm = pyinotify.WatchManager()  # Watch Manager
    mask = pyinotify.IN_CREATE  # watched events

    notifier = pyinotify.Notifier(wm, EventHandler(args.public_key,
                                  led_manager))
    wdd = wm.add_watch(args.mountpoint, mask)

    notifier.loop()  # Blocking loop
    led_thread.join() 
开发者ID:platisd,项目名称:cryptopuck,代码行数:32,代码来源:cryptopuck.py


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