當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。