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


Python Observer.unschedule方法代码示例

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


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

示例1: test_existing_directories_are_not_reported

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
    def test_existing_directories_are_not_reported(self):
        import os
        from fsevents import Stream, Observer

        events = []
        def callback(event):
            events.append(event)
        
        stream = Stream(callback, self.tempdir, file_events=True)
        new1 = os.path.join(self.tempdir, "newdir1")
        new2 = os.path.join(self.tempdir, "newdir2")
        os.mkdir(new1)
        observer = Observer()
        observer.schedule(stream)
        observer.start()

        import time
        while not observer.isAlive():
            time.sleep(0.1)
        del events[:]
        time.sleep(1)
        os.mkdir(new2)
        try:
            time.sleep(1.1)
            observer.stop()
            observer.unschedule(stream)
            observer.join()

            from fsevents import IN_CREATE
            self.assertEqual(len(events), 1)
            self.assertEqual(events[0].mask, IN_CREATE)
            self.assertEqual(events[0].name, os.path.realpath(new2))
        finally:
            os.rmdir(new1)
            os.rmdir(new2)
开发者ID:Mondego,项目名称:pyreco,代码行数:37,代码来源:allPythonContent.py

示例2: main

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
def main():
    arg_parser = argparse.ArgumentParser()

    arg_parser.add_argument('path')
    arg_parser.add_argument('-c', '--cmd', required=True, nargs='+', help='Console command for execute')
    arg_parser.add_argument('-d', '--delay', type=int, default=5, nargs='?', help='Synchronization delay in seconds')
    arg_parser.add_argument('-v', '--verbose', action='store_true', help='verbose flag')

    try:
        args = arg_parser.parse_args()
        path = args.path

        if not os.path.isdir(path):
            raise IOError('Path `%s` is not a directory' % path)

        event_handler = EventHandler()
        timer = TimerInterval(callback_func, args.delay, event_handler=event_handler, cmd=args.cmd, verbose=args.verbose)
        stream = Stream(event_handler.callback_handler, path, file_events=True)
        observer = Observer()

        observer.schedule(stream)
        observer.start()
        timer.start()
    except IOError as e:
        print e
    except KeyboardInterrupt:
        observer.unschedule(stream)
        observer.stop()
        timer.stop()
开发者ID:bu1ka,项目名称:fswatcher,代码行数:31,代码来源:fswatcher.py

示例3: _assert_action_after_watcher

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
    def _assert_action_after_watcher(self, process_asap, assertions_cb):
        events = []
        def callback(event):
            events.append(event)

        import os
        import time
        from fsevents import Stream
        from fsevents import Observer

        observer = Observer(process_asap=process_asap)
        observer.start()

        stream = Stream(callback, self.tempdir, file_events=True)
        observer.schedule(stream)
        # add single file
        del events[:]
        f = open(os.path.join(self.tempdir, "test"), "w")
        f.write("abc")
        f.flush()
        f.close()
        time.sleep(0.2)

        # stop and join observer
        observer.stop()
        observer.unschedule(stream)
        observer.join()

        os.unlink(f.name)
        assertions_cb(events, f)
开发者ID:poupas,项目名称:macfsevents,代码行数:32,代码来源:tests.py

示例4: run

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
def run():
    observer = Observer()
    observer.start()

    # start foreman
    forerunner = Forerunner()
    forerunner.start()

    # call callback when files under the cwd change
    stream = Stream(forerunner.callback, './', file_events=True)
    observer.schedule(stream)

    while True:
        try:
            sleep(1)
        except KeyboardInterrupt:
            observer.unschedule(stream)
            observer.stop()
            observer.join()

            foreman = forerunner.foreman

            for i in range(1, 10):
                if foreman.poll() is not None:
                    break

                print "sleeping... %i" % i
                sleep(1)

            if foreman.poll() is None:
                foreman.kill()

            sleep(1)
            break
开发者ID:dzaman,项目名称:forerunner,代码行数:36,代码来源:forerunner.py

示例5: test_single_file_added_multiple_streams

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
    def test_single_file_added_multiple_streams(self):
        events = []
        def callback(*args):
            events.append(args)

        f, path = self._make_temporary()
        from fsevents import Stream
        stream1 = Stream(callback, path)
        stream2 = Stream(callback, path)

        from fsevents import Observer
        observer = Observer()
        observer.schedule(stream1)
        observer.schedule(stream2)
        observer.start()

        # add single file
        import time
        while not observer.isAlive():
            time.sleep(0.1)
        time.sleep(0.1)
        del events[:]
        f.close()
        time.sleep(0.2)

        # stop and join observer
        observer.stop()
        observer.unschedule(stream1)
        observer.unschedule(stream2)
        observer.join()
        self.assertEquals(events[0][0], path)
        self.assertEquals(events[1][0], path)
开发者ID:poupas,项目名称:macfsevents_official,代码行数:34,代码来源:tests.py

示例6: test_single_file_added_with_observer_unscheduled

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
    def test_single_file_added_with_observer_unscheduled(self):
        events = []
        def callback(*args):
            events.append(args)

        f, path = self._make_temporary()
        from fsevents import Stream
        stream = Stream(callback, path)

        from fsevents import Observer
        observer = Observer()
        observer.start()
        import time
        while not observer.isAlive():
            time.sleep(0.1)

        observer.schedule(stream)
        observer.unschedule(stream)

        # add single file
        del events[:]
        f.close()
        time.sleep(0.1)

        # stop and join observer
        observer.stop()
        observer.join()

        self.assertEqual(events, [])
开发者ID:Mondego,项目名称:pyreco,代码行数:31,代码来源:allPythonContent.py

示例7: test_start_then_watch

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
    def test_start_then_watch(self):
        events = []
        def callback(*args):
            events.append(args)

        f, path = self._make_temporary()
        from fsevents import Stream
        stream = Stream(callback, path)

        from fsevents import Observer
        observer = Observer()
        observer.schedule(stream)
        observer.start()

        # add single file
        import time
        while not observer.isAlive():
            time.sleep(0.1)
        del events[:]
        f.close()
        time.sleep(0.2)

        # stop and join observer
        observer.stop()
        observer.unschedule(stream)
        observer.join()

        self.assertEqual(events, [(path, self.create_and_remove_mask)])
开发者ID:Mondego,项目名称:pyreco,代码行数:30,代码来源:allPythonContent.py

示例8: __init__

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
class Dmon:
    def __init__(self, dir, handlers):
        self._handlers = handlers
        self._dir = dir

    def _call_handler(self, method, fname):
        for handler in self._handlers:
            getattr(handler, method)(fname)

    def _run_pyinotify(self):
        from lib import pyinotify
        class PyInotifyEventProcessor(pyinotify.ProcessEvent):
            def __init__(self, c_handler):
                self._call = c_handler
            def process_IN_CREATE(self, event):
                self._call('on_create', event.pathname)
            def process_IN_DELETE(self, event):
                self._call('on_delete', event.pathname)
            def process_IN_MODIFY(self, event):
                self._call('on_update', event.pathname)
        wm = pyinotify.WatchManager()
        self._observer = pyinotify.Notifier(wm, PyInotifyEventProcessor(self._call_handler))
        mask = pyinotify.ALL_EVENTS
        wm.add_watch(self._dir, mask, rec=True)
        while True:
            self._observer.process_events()
            if self._observer.check_events():
                self._observer.read_events()
            time.sleep(1)

    def _run_macfse(self):
        from lib import fsevents
        from fsevents import Stream
        from fsevents import Observer
        def macfse_callback(event):
            if event.mask in [256, 128]:
                self._call_handler('on_create', event.name)
            elif event.mask in [512, 64]:
                self._call_handler('on_delete', event.name)
            elif event.mask == 2:
                self._call_handler('on_update', event.name)
        self._observer = Observer()
        self._stream = Stream(macfse_callback, self._dir, file_events=True)
        self._observer.schedule(self._stream)
        self._observer.start()


    def start(self):
        if 'darwin' in sys.platform.lower():
            self._run_macfse()
        elif 'linux' in sys.platform.lower():
            self._run_pyinotify()

    def stop(self):
        if 'darwin' in sys.platform.lower():
            self._observer.unschedule(self._stream)
            self._observer.stop()
        elif 'linux' in sys.platform.lower():
            self._observer.stop()
开发者ID:fscz,项目名称:dmon,代码行数:61,代码来源:dmon.py

示例9: test_since_stream

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
    def test_since_stream(self):
        events = []
        def callback(*args):
            events.append(args)
        
        # two files in same directory
        import os
        path1 = os.path.realpath(self._make_tempdir()) + '/'
        f = self._make_temporary(path1)[0]
        g = self._make_temporary(path1)[0]

        from fsevents import Stream, FS_FLAGHISTORYDONE
        
        stream = Stream(callback, path1, ids = True)
        
        from fsevents import Observer
        observer = Observer()
        observer.schedule(stream)
        observer.start()
        
        #create one file
        import time
        while not observer.isAlive():
            time.sleep(0.1)
        del events[:]
        f.close()
        time.sleep(0.2)
        
        # stop and join observer
        observer.stop()
        observer.unschedule(stream)
        observer.join()
        self.assertEqual(len(events),1)
        self.assertEqual(events[0][:-1], (path1, self.create_and_remove_mask))

        #create a second file
        g.close()
           
        stream = Stream(callback, path1, since = events[0][2])
        del events[:]
        # new observer
        observer = Observer()
        observer.schedule(stream)
        observer.start()
        time.sleep(0.2)

        # stop and join observer
        observer.stop()
        observer.unschedule(stream)
        observer.join()

        self.assertEqual(len(events),2)
        #FIXME: why do events arrive here in reversed order?            
        self.assertEqual(events[1], (path1, self.create_and_remove_mask))
        self.assertEqual(events[0], (path1[:-1], FS_FLAGHISTORYDONE))
开发者ID:chrisgee,项目名称:macfsevents,代码行数:57,代码来源:tests.py

示例10: loop

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
 def loop(self):
     observer = Observer()
     observer.schedule(self.stream)
     observer.daemon = True
     observer.start()
     try:
         while True:
             # Cannot use observer.join() as it is not interrupted by
             # Ctrl-C
             time.sleep(10000)
     finally:
         observer.unschedule(self.stream)
         observer.stop()
开发者ID:tguigue,项目名称:calibre,代码行数:15,代码来源:auto_reload.py

示例11: test_file_moved_to_not_watched_path

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
    def test_file_moved_to_not_watched_path(self):
        import os
        events = []
        def callback(event):
            events.append(event)

        from fsevents import Stream
        not_watched_path = os.path.realpath(self._make_tempdir()) + '/'
        stream = Stream(callback, self.tempdir, file_events=True)

        from fsevents import Observer
        observer = Observer()
        observer.schedule(stream)
        observer.start()

        # add single file
        import time
        while not observer.isAlive():
            time.sleep(0.1)
        del events[:]
        time.sleep(2.1)

        src_name = os.path.join(self.tempdir, "test")
        dst_name = os.path.join(not_watched_path, "test")
        f = open(src_name, "w")
        f.write("abc")
        f.close()

        time.sleep(1.0)

        os.rename(src_name, dst_name)

        time.sleep(0.1)

        # stop and join observer
        observer.stop()
        observer.unschedule(stream)
        observer.join()

        os.unlink(dst_name)
        os.rmdir(not_watched_path)
        from fsevents import IN_CREATE, IN_MODIFY, IN_DELETE

        self.assertEquals(len(events), 3)
        # assert the creation events
        self.assertEquals(events[0].mask, IN_CREATE)
        self.assertEquals(events[0].name, os.path.realpath(src_name))
        self.assertEquals(events[1].mask, IN_MODIFY)
        self.assertEquals(events[1].name, os.path.realpath(src_name))
        self.assertEquals(events[2].mask, IN_DELETE)
        self.assertEquals(events[2].name, os.path.realpath(src_name))
开发者ID:poupas,项目名称:macfsevents,代码行数:53,代码来源:tests.py

示例12: start_scanner

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
def start_scanner(path):
    """
    watch for file events in the supplied path
    """
    try:
        observer = Observer()
        observer.start()
        stream = Stream(file_modified, path, file_events=True)
        observer.schedule(stream)
        print "Watching for changes. Press Ctrl-C to stop."
        while 1:
          pass
    except (KeyboardInterrupt, OSError, IOError):
        observer.unschedule(stream)
        observer.stop()
开发者ID:coded-by-hand,项目名称:mass,代码行数:17,代码来源:monitor.py

示例13: test_multiple_files_added

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
    def test_multiple_files_added(self):
        events = []
        def callback(*args):
            events.append(args)

        from fsevents import Observer
        observer = Observer(callback, file_events=True)
        observer.start()

        # wait until activation
        import time
        while not observer.isAlive():
            time.sleep(0.1)
        time.sleep(0.1)

        # two files in same directory
        import os
        path1 = os.path.realpath(self._make_tempdir()) + '/'
        f = self._make_temporary(path1)[0]
        g = self._make_temporary(path1)[0]

        # one file in a separate directory
        path2 = os.path.realpath(self._make_tempdir()) + '/'
        h = self._make_temporary(path2)[0]

        observer.schedule(path1)
        observer.schedule(path2)

        try:
            del events[:]
            f.close()
            g.close()
            h.close()
            time.sleep(0.2)
            events = [e[0] for e in events]
            self.assertEqual(sorted(events), sorted([path1, path2]))
        finally:
            f.close()
            g.close()
            h.close()
            os.rmdir(path1)
            os.rmdir(path2)

            # stop and join observer
            observer.stop()
            observer.unschedule(path1)
            observer.unschedule(path2)
            observer.join()
开发者ID:poupas,项目名称:macfsevents,代码行数:50,代码来源:tests.py

示例14: test_single_file_created_and_modified

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
    def test_single_file_created_and_modified(self):
        events = []
        def callback(event):
            events.append(event)

        from fsevents import Stream
        stream = Stream(callback, self.tempdir, file_events=True)

        from fsevents import Observer
        observer = Observer()
        observer.schedule(stream)
        observer.start()

        # add single file
        import time
        while not observer.isAlive():
            time.sleep(0.1)
        del events[:]
        time.sleep(2.1)

        import os
        f = open(os.path.join(self.tempdir, "test"), "w")
        f.write("abc")
        f.flush()

        time.sleep(1.0)

        f.write("def")
        f.flush()
        f.close()
        time.sleep(0.1)

        # stop and join observer
        observer.stop()
        observer.unschedule(stream)
        observer.join()

        os.unlink(f.name)
        from fsevents import IN_CREATE, IN_MODIFY
        self.assertEquals(len(events), 3)
        # assert events related to the creations
        self.assertEquals(events[0].mask, IN_CREATE)
        self.assertEquals(events[0].name, os.path.realpath(f.name))
        self.assertEquals(events[1].mask, IN_MODIFY)
        self.assertEquals(events[1].name, os.path.realpath(f.name))
        # assert events related to the modify
        self.assertEquals(events[2].mask, IN_MODIFY)
        self.assertEquals(events[2].name, os.path.realpath(f.name))
开发者ID:poupas,项目名称:macfsevents,代码行数:50,代码来源:tests.py

示例15: loop

# 需要导入模块: from fsevents import Observer [as 别名]
# 或者: from fsevents.Observer import unschedule [as 别名]
 def loop(self):
     observer = Observer()
     observer.schedule(self.stream)
     observer.daemon = True
     observer.start()
     try:
         while True:
             try:
                 # Cannot use blocking get() as it is not interrupted by
                 # Ctrl-C
                 if self.wait_queue.get(10000) is True:
                     self.force_restart()
             except Empty:
                 pass
     finally:
         observer.unschedule(self.stream)
         observer.stop()
开发者ID:AEliu,项目名称:calibre,代码行数:19,代码来源:auto_reload.py


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