Beispiel #1
0
 def test_None_cfg_disables_throttling(self):
     throttler = throttler_factory(None, make_fake_timer(0, [0, 0]))
     event = make_event("/tmp", "foo")
     self.assert_(throttler(event))  # always accepted
     self.assert_(throttler(event))  # two deltas
     self.assert_(throttler(event))
     self.assert_(throttler(event))  # timer isn't called
 def test_None_cfg_disables_throttling(self):
     throttler = throttler_factory(None, make_fake_timer(0, [0, 0]))
     event = make_event("/tmp", "foo")
     self.assert_(throttler(event))  # always accepted
     self.assert_(throttler(event))  # two deltas
     self.assert_(throttler(event))
     self.assert_(throttler(event))  # timer isn't called
Beispiel #3
0
def main():
    opts = cmdline.parse()
    try:
        cfg = config.read_config(opts.config_file)
    except config.ConfigurationError as e:
        print("%s" % e)
        return 1
    throttler = event_filters.throttler_factory(cfg.throttling)
    react = make_reporter(throttler=throttler, preprocessor=cfg.preprocessor)

    def callback():
        runner.run(cfg.command, react)
    wm = pyinotify.WatchManager()
    handler = EventHandler(
        callback=callback,
        filter=event_filters.and_(
            event_filters.not_(event_filters.is_delete_dir_event),
            event_filters.simple_event_filter_factory(cfg.watch, cfg.global_ignore),
            throttler,
        )
    )
    notifier = pyinotify.Notifier(wm, handler)
    for watch in cfg.watch:
        wm.add_watch(
            watch.path,
            pyinotify.IN_CLOSE_WRITE | pyinotify.IN_DELETE,
            rec=watch.recurse,
            auto_add=watch.auto_add
        )

    # force a test run on startup
    callback()

    notifier.loop()
Beispiel #4
0
def main():
    opts = cmdline.parse()
    try:
        cfg = config.read_config(opts.config_file)
    except config.ConfigurationError as e:
        print("%s" % e)
        return 1
    throttler = event_filters.throttler_factory(cfg.throttling)
    react = make_reporter(throttler=throttler, preprocessor=cfg.preprocessor)

    def callback():
        runner.run(cfg.command, react)

    wm = pyinotify.WatchManager()
    handler = EventHandler(
        callback=callback,
        filter=event_filters.and_(
            event_filters.not_(event_filters.is_delete_dir_event),
            event_filters.simple_event_filter_factory(cfg.watch,
                                                      cfg.global_ignore),
            throttler,
        ))
    notifier = pyinotify.Notifier(wm, handler)
    for watch in cfg.watch:
        wm.add_watch(watch.path,
                     pyinotify.IN_CLOSE_WRITE | pyinotify.IN_DELETE,
                     rec=watch.recurse,
                     auto_add=watch.auto_add)

    # force a test run on startup
    callback()

    notifier.loop()
Beispiel #5
0
 def set_up(self, deltas, start=0, count=10):
     self.cfg = Object(max_events_second=count)  # 10 events/second
     self.timer = make_fake_timer(start, deltas)
     self.throttler = throttler_factory(self.cfg, self.timer)
     self.event = make_event("/tmp", "foo")
 def set_up(self, deltas, start=0, count=10):
     self.cfg = Object(max_events_second=count)  # 10 events/second
     self.timer = make_fake_timer(start, deltas)
     self.throttler = throttler_factory(self.cfg, self.timer)
     self.event = make_event("/tmp", "foo")