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


Python Notifier.loop方法代码示例

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


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

示例1: test_update_filtered

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
    def test_update_filtered(self, default_config, show_notification):
        out_file = self.tmp_output.join("out.log")
        command_args = [
            "-c", self.config_file,
            "-r", "bash -c 'echo a | tee -a {}'".format(out_file),
            "-d", unicode(self.tmp.src),
        ]
        events = [
            (self.tmp.src, "filtered_1.pyc", "some new data"),
            (self.tmp.src, "filtered_2.tmp", "some new data"),
            (self.tmp.src, ".hidden", "some new data"),
        ]

        self._copy_default_config(default_config)
        default_config.RUNNER_DELAY = -1

        wm = WatchManager()
        config = Config(watch_manager=wm, command_args=command_args)
        handler = FileChangeHandler(config=config)
        notifier = Notifier(wm, handler)

        notifier.loop(callback=partial(self._event_generator, events))

        # There are some stupid race conditions (possibly due to the callbacks)
        # Sleep time allows to execute all needed code
        sleep(0.2)

        self.assertTrue(path.exists(self.tmp.src.join("filtered_1.pyc")))
        self.assertTrue(path.exists(self.tmp.src.join("filtered_2.tmp")))
        self.assertTrue(path.exists(self.tmp.src.join(".hidden")))
        self.assertFalse(path.exists(out_file))
        self.assertFalse(show_notification.called)
开发者ID:mrfuxi,项目名称:testrunner,代码行数:34,代码来源:test_functional.py

示例2: main

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
def main():
    vm = WatchManager()
    vm.add_watch(monitor_dirs,ALL_EVENTS,rec = True)

    en = MyEvent()
    notifier = Notifier(vm,en)
    notifier.loop()
开发者ID:weekday,项目名称:jiankong,代码行数:9,代码来源:pyinotify_file.py

示例3: run

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
 def run(self):
     p = PTmp()
     notifier = Notifier(Settings.wm, p)
     # TODO: Not necessary to watch the directories that already have
     # a procedures.xml
     Settings.wdd = Settings.wm.add_watch(Settings.monitor_path, Settings.mask, rec=True)
     notifier.loop()
开发者ID:masums,项目名称:uia2atk,代码行数:9,代码来源:qamon.py

示例4: test_update_conf

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
    def test_update_conf(self, default_config, show_notification):
        conf_time_1 = path.getmtime(self.tmp.conf.join("config.py"))
        out_file = self.tmp_output.join("out.log")
        command_args = [
            "-c", self.config_file,
            "-r", "bash -c 'echo a | tee -a {}'".format(out_file),
            "-d", unicode(self.tmp.src),
        ]
        events = [
            (self.tmp.conf, "config.py", "# some new data"),
            (self.tmp.conf, "config.py", "# some new data"),
        ]

        self._copy_default_config(default_config)
        default_config.RUNNER_DELAY = -1

        wm = WatchManager()
        config = Config(watch_manager=wm, command_args=command_args)
        handler = FileChangeHandler(config=config)
        notifier = Notifier(wm, handler, timeout=1000)

        notifier.loop(callback=partial(self._event_generator, events))

        # There are some stupid race conditions (possibly due to the callbacks)
        # Sleep time allows to execute all needed code
        sleep(0.2)

        conf_time_2 = path.getmtime(self.tmp.conf.join("config.py"))

        self.assertNotEqual(conf_time_1, conf_time_2)
        self.assertTrue(path.exists(out_file))
        self.assertEqual(show_notification.call_count, 2)
开发者ID:mrfuxi,项目名称:testrunner,代码行数:34,代码来源:test_functional.py

示例5: fsMonitor

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
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,代码行数:9,代码来源:pyrsync.py

示例6: watch

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
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,代码行数:9,代码来源:supervisor.py

示例7: watch_path

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
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,代码行数:31,代码来源:tailall.py

示例8: FSMonitor

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
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,代码行数:10,代码来源:notify.py

示例9: tailwatch

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
def tailwatch(dir):
    FLAGS = EventsCodes.ALL_FLAGS
    mask = FLAGS['IN_CREATE'] |FLAGS['IN_DELETE'] | FLAGS['IN_MODIFY']
    wm = WatchManager()
    p = PTmp()
    notifier = Notifier(wm, p)
    wdd = wm.add_watch(dir, mask, rec=True)
    notifier.loop()
开发者ID:danohuiginn,项目名称:doh,代码行数:10,代码来源:logwatch.py

示例10: builder_process

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
 def builder_process():
     logger.debug(' - Watched static files for changes to rebuild')
     wm = WatchManager()
     notifier = Notifier(wm, default_proc_fun=_build)
     wm.add_watch(
         watched_dir,
         IN_MODIFY, # | IN_CREATE | IN_DELETE,
         rec=True, auto_add=True
     )
     notifier.loop()
开发者ID:wreckah,项目名称:statika,代码行数:12,代码来源:dev.py

示例11: create_monitor

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
def create_monitor(to_watch, name):
    "Create and start a new directory monitor."
    messenger = NetworkSender(name)
    p = Monitor(messenger)
    wm = WatchManager()  # Watch Manager
    notifier = Notifier(wm, p) # Notifier
    try: 
        wdd = wm.add_watch(to_watch, IN_DELETE | IN_CREATE | IN_MODIFY)
        notifier.loop()
    except WatchManagerError, err:
        print err, err.wmd
开发者ID:abachman,项目名称:watch-me-work,代码行数:13,代码来源:watch_me.py

示例12: monitor

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
def monitor(watch_path, callback):
    watch_path = os.path.abspath(watch_path)
    if os.path.isfile(watch_path):
        path_for_manager = os.path.dirname(watch_path)
    else:
        path_for_manager = watch_path

    manager = WatchManager()
    notifier = Notifier(manager,
                        AutoRunner(watch_path, callback))
    manager.add_watch(path_for_manager, IN_MODIFY)

    notifier.loop()
开发者ID:fisadev,项目名称:ponytor,代码行数:15,代码来源:ponytor.py

示例13: start_queue

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
def start_queue():
    dir_queue = vmcheckerpaths.dir_queue()

    # register for inotify envents before processing stale jobs
    wm = WatchManager()
    notifier = Notifier(wm, _QueueManager())
    wm.add_watch(dir_queue, EventsCodes.ALL_FLAGS['IN_CLOSE_WRITE'])

    process_stale_jobs(dir_queue)

    # set callback to receive notifications (includes queued jobs after
    # setting up inotify but before we finished processing stale jobs)
    notifier.loop(callback=_callback)
开发者ID:MihaiTabara,项目名称:vmchecker,代码行数:15,代码来源:queue_manager.py

示例14: monitor_photos

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
def monitor_photos(directory='/mnt/photos'):
    wm = WatchManager() 
    # watched events
    mask = IN_DELETE | IN_CREATE |IN_MODIFY | IN_CLOSE_WRITE | IN_MOVED_FROM | IN_MOVED_TO
    emails = ["[email protected]@163.com"]

    class PFilePath(ProcessEvent):
        def process_IN_CREATE(self, event):
            print(datetime.now().strftime('%Y%m%d %H%M%S: '))
            print("***Create file: %s" %   os.path.join(event.path, event.name))

            print("%s sending email"%event.name)
            subject = "%s uploaded."%event.name
            body_text = "<a href=http://7xrst7.com1.z0.glb.clouddn.com/%s>%s</a>"%(event.name, event.name)
            #send_email(subject, body_text, emails)
            p = Process(target=send_email, args=(subject, body_text, emails))
            p.start()
            p.join()

        def process_IN_MODIFY(self, event):
            #print(datetime.now().strftime('%Y%m%d %H%M%S: '))
            #print("***Modify file: %s" %   os.path.join(event.path, event.name))
            pass

        def process_IN_CLOSE_WRITE(self, event):
            print(datetime.now().strftime('%Y%m%d %H%M%S: '))
            print("***Close file: %s" %   os.path.join(event.path, event.name))
            update_list(directory, 'add', event.name)

        def process_IN_MOVED_TO(self, event):
            print(datetime.now().strftime('%Y%m%d %H%M%S: '))
            print("***Movedto file: %s" %   os.path.join(event.path, event.name))
            update_list(directory, 'add', event.name)

        def process_IN_MOVED_FROM(self, event):
            print(datetime.now().strftime('%Y%m%d %H%M%S: '))
            print("***Movedfrom file: %s" %   os.path.join(event.path, event.name))
            update_list(directory, 'delete', event.name)

        def process_IN_DELETE(self, event):
            print(datetime.now().strftime('%Y%m%d %H%M%S: '))
            print("***Delete file: %s" %   os.path.join(event.path, event.name))
            update_list(directory, 'delete', event.name)

    notifier = Notifier(wm, PFilePath())
    wdd = wm.add_watch(directory, mask)

    print(datetime.now().strftime('%Y%m%d %H%M%S: '))
    print('***Start watching***')
    notifier.loop()
开发者ID:reaky,项目名称:dotfiles,代码行数:52,代码来源:updatelist.py

示例15: main

# 需要导入模块: from pyinotify import Notifier [as 别名]
# 或者: from pyinotify.Notifier import loop [as 别名]
def main(argv):
    server_config_file = _parseCommandArguments(argv)
    [static_path, minify_enabled] = configure_server_and_app(server_config_file)
    print "server_config_file = " + server_config_file
    print "static_path = " + static_path
    print "minify_enabled = " + str(minify_enabled)
    store = RedisStore(redis.StrictRedis())
    jso = jsOptimizer(minify_enabled)
    jso.watch(static_path, store, force=True)
    try:
        wm = WatchManager()
        notifier = Notifier(wm, StaticsChangesProcessor(jso, store))
        wm.add_watch(static_path, IN_CREATE | IN_MODIFY | IN_DELETE | IN_MOVED_TO, rec=True)
        notifier.loop()
    finally:
        pass
开发者ID:CaliopeProject,项目名称:CaliopeServer,代码行数:18,代码来源:jsOptimizerProcess.py


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