Ejemplo n.º 1
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()
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
 def test_ok(self):
     config = b"""
     {
         "command" : "echo 1",
         "verbosity" : 2
     }
     """
     path = self.create_config_file(config)
     cfg = read_config(path, self.SCHEMA)
     self.assertEqual(cfg.command, "echo 1")
     self.assertEqual(cfg.verbosity, 2)
Ejemplo n.º 4
0
 def test_ok(self):
     config = b"""
     {
         "command" : "echo 1",
         "verbosity" : 2
     }
     """
     path = self.create_config_file(config)
     cfg = read_config(path, self.SCHEMA)
     self.assertEqual(cfg.command, "echo 1")
     self.assertEqual(cfg.verbosity, 2)