Esempio n. 1
0
 def test_exclude_excluced_file_in_subdirectory(self):
     subdir = self.make_subdir("subdir")
     event = make_event(subdir, "exclude.abc")
     filter = simple_event_filter_factory([
         make_watch(self.tmpdir, exclude=[u".*\\.abc"])
     ])
     self.failIf(filter(event))
Esempio 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()
Esempio n. 3
0
 def test_unwatched_directory_raises_ValueError(self):
     parent = os.path.dirname(self.tmpdir)
     event = make_event(parent, "exclude.abc")
     filter = simple_event_filter_factory([
         make_watch(self.tmpdir, include=[u".*\\.abc"])
     ])
     self.assertRaises(ValueError, filter, event)
Esempio n. 4
0
 def test_include_included_file_in_subdirectory(self):
     subdir = self.make_subdir("subdir")
     event = make_event(subdir, "include.abc")
     filter = simple_event_filter_factory([
         make_watch(self.tmpdir, include=[u".*\\.abc"])
     ])
     self.assert_(filter(event))
Esempio n. 5
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()
Esempio n. 6
0
 def test_neither_excluded_nor_included_gets_excluded_by_default(self):
     event = make_event(self.tmpdir, "exclude.txt")
     filter = simple_event_filter_factory([
         make_watch(self.tmpdir,
                    exclude=[u".*\\.abc"],
                    include=[u".*\\.py"])
     ])
     self.failIf(filter(event))
Esempio n. 7
0
 def test_global_exclude_takes_over_all(self):
     event = make_event(self.tmpdir, ".exclude.abc")
     filter = simple_event_filter_factory(
         watches=[
             make_watch(self.tmpdir, include=[u".*\\.abc"]),
         ],
         global_ignores=[re.compile("\\..*")])
     self.failIf(filter(event))
Esempio n. 8
0
 def test_include_specific_takes_over_generic(self):
     subdir = self.make_subdir("subdir")
     event = make_event(subdir, "exclude.abc")
     filter = simple_event_filter_factory([
         make_watch(self.tmpdir, exclude=[u".*\\.abc"]),  # /tmp
         make_watch(subdir, include=[u".*\\.abc"]),  # /tmp/subdir
     ])
     self.assert_(filter(event))
Esempio n. 9
0
 def test_include_specific_takes_over_generic(self):
     subdir = self.make_subdir("subdir")
     event = make_event(subdir, "exclude.abc")
     filter = simple_event_filter_factory([
         make_watch(self.tmpdir, exclude=[u".*\\.abc"]),  # /tmp
         make_watch(subdir, include=[u".*\\.abc"]),       # /tmp/subdir
     ])
     self.assert_(filter(event))
Esempio n. 10
0
 def test_global_exclude_takes_over_all(self):
     event = make_event(self.tmpdir, ".exclude.abc")
     filter = simple_event_filter_factory(
         watches=[
             make_watch(self.tmpdir, include=[u".*\\.abc"]),
         ],
         global_ignores=[re.compile("\\..*")]
     )
     self.failIf(filter(event))
Esempio n. 11
0
 def test_exclude_excluced_file_in_subdirectory(self):
     subdir = self.make_subdir("subdir")
     event = make_event(subdir, "exclude.abc")
     filter = simple_event_filter_factory(
         [make_watch(self.tmpdir, exclude=[u".*\\.abc"])])
     self.failIf(filter(event))
Esempio n. 12
0
 def test_include_included_file(self):
     event = make_event(self.tmpdir, "include.abc")
     filter = simple_event_filter_factory(
         [make_watch(self.tmpdir, include=[u".*\\.abc"])])
     self.assert_(filter(event))
Esempio n. 13
0
 def test_exclude_excluded_file(self):
     event = make_event(self.tmpdir, "exclude.abc")
     filter = simple_event_filter_factory(
         [make_watch(self.tmpdir, exclude=[u".*\\.abc"])])
     self.failIf(filter(event))
Esempio n. 14
0
 def test_unwatched_directory_raises_ValueError(self):
     parent = os.path.dirname(self.tmpdir)
     event = make_event(parent, "exclude.abc")
     filter = simple_event_filter_factory(
         [make_watch(self.tmpdir, include=[u".*\\.abc"])])
     self.assertRaises(ValueError, filter, event)
Esempio n. 15
0
 def test_exclude_excluded_file(self):
     event = make_event(self.tmpdir, "exclude.abc")
     filter = simple_event_filter_factory([make_watch(self.tmpdir, exclude=[u".*\\.abc"])])
     self.failIf(filter(event))
Esempio n. 16
0
 def test_neither_excluded_nor_included_gets_excluded_by_default(self):
     event = make_event(self.tmpdir, "exclude.txt")
     filter = simple_event_filter_factory([make_watch(self.tmpdir, exclude=[u".*\\.abc"], include=[u".*\\.py"])])
     self.failIf(filter(event))