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


Python ThreadedNotifier.stop方法代码示例

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


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

示例1: DirectoryWatcher

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
class DirectoryWatcher(WatchManager):
	def __init__(self):
		WatchManager.__init__(self)

	
	def start(self):
		self.inotify = ThreadedNotifier(self)
		self.inotify.start()
		self.inotify.join()


	def stop(self):
		self.inotify.stop()
	
	
	def add_monitor_path(self, path):
		if path is None:
			Logger.error("FS: unable to monitor None directory")
			return False
		
		exclude1 = "^%s/conf.Windows*"%(path)
		exclude2 = "^%s/conf.Linux*"%(path)
		exc_filter = ExcludeFilter([exclude1, exclude2])
		
		try:
			self.add_watch(path=path, mask=Rec.mask, proc_fun=Rec(), rec=True, auto_add=True, exclude_filter=exc_filter)
		except WatchManagerError, e:
			Logger.error("FS: unable to monitor directory %s, %s"%(path, str(e)))
			return False
		
		return False
开发者ID:Oyatsumi,项目名称:ulteo4Kode4kids,代码行数:33,代码来源:DirectoryWatcher.py

示例2: Notify

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
class Notify():
    def __init__(self):
        self.wm = WatchManager()
        self.pe = ProcessNotifyEvents()
        self.notifier = ThreadedNotifier(self.wm, self.pe)
        self.notifier.start()
        self.path = None
        #thread.start_new_thread(self.jobTask, (self,))

    def setNotify(self, path, cbfun):
        #print 'setnotify ' + path
        if self.path:
            self.wm.rm_watch(list(self.wdd.values()))
        self.path = path
        self.pe.cbfun = cbfun # ugly...
        #print sys.getfilesystemencoding()
        self.wdd = self.wm.add_watch(self.path, 
                          pyinotify.IN_CREATE | 
                          pyinotify.IN_DELETE |
                          pyinotify.IN_MOVED_TO |
                          pyinotify.IN_MOVED_FROM |
                          pyinotify.IN_MODIFY)

    def stop(self):
        if self.path:
            self.wm.rm_watch(list(self.wdd.values()))
        self.notifier.stop()

    def notifyThread(self):
        while 1:
            notifier.process_events()
            if notifier.check_events():
                notifier.read_events()
开发者ID:suncore,项目名称:dflynav,代码行数:35,代码来源:vfs_fsNotify_Linux.py

示例3: PhotoWatcher

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
class PhotoWatcher(ProcessEvent):
  MASK = (EventsCodes.ALL_FLAGS['IN_DELETE'] |
          EventsCodes.ALL_FLAGS['IN_CLOSE_WRITE'] |
          EventsCodes.ALL_FLAGS['IN_MOVED_FROM'] |
          EventsCodes.ALL_FLAGS['IN_MOVED_TO'])

  def __init__(self, db, walker, root):
    self.root = root
    self.db = db
    self.walker = walker
    self.wm = WatchManager()
    self.wdds = []

  def Watch(self):
    self.notifier = ThreadedNotifier(self.wm, self)
    self.notifier.start()
    self.wdds.append(self.wm.add_watch(self.root, self.MASK, rec=True))
    # add soft link sub-folders
    for dirname, dirnames, _filenames in os.walk(self.root, followlinks=True):
      for d in dirnames:
        path = os.path.join(dirname, d)
        if os.path.islink(path):
          self.wdds.append(
              self.wm.add_watch(os.path.realpath(path), self.MASK, rec=True))

  def Stop(self):
    self.notifier.stop()

  def process_IN_DELETE(self, event):
    self.db.DeletePhoto(os.path.join(event.path, event.name))

  def process_IN_MOVED_FROM(self, event):
    self.process_IN_DELETE(event)

  def process_IN_MOVED_TO(self, event):
    full_path = os.path.join(event.path, event.name)
    try:
      meta = self.walker.ReadMetadata(full_path)
    except Exception:
      return

    self.db.StorePhoto(full_path, meta)

  def process_IN_CLOSE_WRITE(self, event):
    full_path = os.path.join(event.path, event.name)
    try:
      meta = self.walker.ReadMetadata(full_path)
    except Exception:
      return

    if self.db.HasPhoto(full_path):
      self.db.UpdatePhoto(full_path, meta)
    else:
      self.db.StorePhoto(full_path, meta)
开发者ID:drseergio,项目名称:photofs,代码行数:56,代码来源:watcher.py

示例4: __init__

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
class FileEvent:
	def __init__(self, eventHandler):
		self.logger = logging.getLogger('FileEvent')
		self.wm = WatchManager()
		self.watches = dict()
		
		# Set the flags of the events that are to be listened to
		FLAGS = EventsCodes.ALL_FLAGS
		self.mask = FLAGS['IN_CREATE'] | FLAGS['IN_DELETE'] | FLAGS['IN_MODIFY'] | FLAGS['IN_DELETE_SELF']
		
		# Set-up notifier
		self.notifier = ThreadedNotifier(self.wm, EventProcessor(eventHandler))
		
	def startNotifyLoop(self):
		self.notifier.start()
	
	def stopNotifyLoop(self):
		self.notifier.stop()
	
	def addWatches(self, paths, mask=None):
		added_watches = dict()
		for path in paths:
			added_watches.update(self.addWatch(path, mask))
		return added_watches
	# Also monitors all sub-directories of the given directory and automatically adds newly
	# created directories to watch. 
	# TODO should be able to add files as well, but doesn't work atm
	def addWatch(self, path, mask=None):
		if mask is None:
			mask = self.mask
		added_watches = self.wm.add_watch(path, mask, rec=True, auto_add=True)
		self.watches.update(added_watches)
		return added_watches
	
	
	def removeWatch(self, path):
		watch_descriptor = self.wm.get_wd(path)
		
		if watch_descriptor is not None:
			result = self.wm.rm_watch(watch_descriptor, rec=True)
			
			# Remove the no longer active watches from the current watches dictionary
			for key, value in self.watches.items():
				if value in result:
					del self.watches[key]
		else:
			result = None
		
		return result
	
	def getWatches(self):
		return self.watches
开发者ID:vesz,项目名称:kempt,代码行数:54,代码来源:file_event.py

示例5: main

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
def main():

    # Add a dummy message to the queue:
    add_msg( MsgTypes.Initialise )



    # Setup the HTTP server:
    SocketServer.TCPServer.allow_reuse_address = True
    HOST, PORT = "localhost", 9000
    server = ThreadedHTTPServer((HOST, PORT), MyTCPHandler)
    server_thread = threading.Thread(target=server.serve_forever)
    server_thread.daemon = True
    server_thread.start()

    # Setup the heartbeat:
    heartbeat_thread = threading.Thread(target=heartbeat_messages)
    heartbeat_thread.daemon = True
    heartbeat_thread.start()


    # Setup pyinotify so files are being watched:
    wm = WatchManager()
    notifier = ThreadedNotifier(wm, PTmp())
    notifier.start()

    mask = EventsCodes.ALL_FLAGS['IN_DELETE'] | EventsCodes.ALL_FLAGS['IN_CREATE'] | EventsCodes.ALL_FLAGS['IN_ATTRIB']   |EventsCodes.ALL_FLAGS['IN_MODIFY']# watched events
    #mask = EventsCodes.ALL_FLAGS['IN_DELETE'] | EventsCodes.ALL_FLAGS['IN_CREATE'] | EventsCodes.ALL_FLAGS['IN_MODIFY']# watched events
    wdd = wm.add_watch('../sentry.py', mask, rec=True)
    wdd = wm.add_watch('../', mask, rec=True)


    try:
        while True:
            time.sleep(5)

    except:
        # Turn off pyinotify:
        notifier.stop()

        print 'Exception caught: shutting down connections'
        add_msg(MsgTypes.Shutdown)
        time.sleep(0.5)
        print 'Terminating...'

        raise
开发者ID:mikehulluk,项目名称:python-devtools,代码行数:48,代码来源:test2.py

示例6: FileWatcher

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
class FileWatcher(Thread):

    def __init__(self, holder, uri, schedule_reader):
        Thread.__init__(self)
        self._loop = True
        self._error_event = Event()
        self._wm = WatchManager()
        self._holder = holder
        self._uri = uri
        self._schedule_reader = schedule_reader
        self._notifier = ThreadedNotifier(self._wm,
                                          _EventHandler(self._holder,
                                                        self._uri,
                                                        self._schedule_reader,
                                                        self._error_event))
        self._path, self._pattern = os.path.split(urlparse(uri).path)

    def start(self):
        """Start the file watcher
        """
        self._notifier.start()
        self._wm.add_watch(self._path, IN_OPEN | IN_CLOSE_WRITE | IN_MODIFY)
        Thread.start(self)

    def run(self):
        while self._loop:
            if self._error_event.wait(1):
                self._error_event.clear()
                self._notifier.stop()
                del self._notifier
                self._notifier = ThreadedNotifier(
                    self._wm,
                    _EventHandler(self._holder,
                                  self._uri,
                                  self._schedule_reader,
                                  self._error_event))
                self._notifier.start()
                self._wm.add_watch(
                    self._path, IN_OPEN | IN_CLOSE_WRITE | IN_MODIFY)

    def stop(self):
        """Stop the file watcher
        """
        self._notifier.stop()
        self._loop = False
开发者ID:pytroll,项目名称:trollcast,代码行数:47,代码来源:server.py

示例7: lastwatch

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
def lastwatch(paths, settings, dry_run=False):
    flags = EventsCodes.FLAG_COLLECTIONS.get('OP_FLAGS', None)
    if flags:
        mask = flags.get('IN_OPEN') | flags.get('IN_CLOSE_NOWRITE')
        mask |= flags.get('IN_CREATE') | flags.get('IN_MOVED_TO')
    else:
        mask = EventsCodes.IN_OPEN | EventsCodes.IN_CLOSE_NOWRITE
        mask |= EventsCodes.IN_CREATE | EventsCodes.IN_MOVED_TO

    wm = WatchManager()

    handler = Handler(settings, dry_run=dry_run)

    watcher = ThreadedNotifier(wm, handler)
    watcher.start()

    try:
        for path in paths:
            path = os.path.realpath(path)

            sys.stdout.write(_("Indexing %s for watching...") % path)
            sys.stdout.flush()

            wm.add_watch(path, mask, rec=True, auto_add=True)
            sys.stdout.write(_(" done.") + "\n")

        print _("You have successfully launched Lastwatch.")
        print "\n".join(wrap(_("The directories you have specified will be "
                               "monitored as long as this process is running, "
                               "the flowers are blooming and the earth "
                               "revolves around the sun..."), 80))
                               # flowers to devhell ;-)
        handler.set_active()

        while True:
            time.sleep(1)

    except KeyboardInterrupt:
        watcher.stop()
        print _("LastWatch stopped.")
        return
    except Exception, err:
        print err
开发者ID:aszlig,项目名称:LastWatch,代码行数:45,代码来源:lastwatch.py

示例8: Watch

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
class Watch(object):
	def __init__(self, path, callback, ignore_modifications=False, latency=None):
		self.event_mask = EVENT_MASK if ignore_modifications else EVENT_MASK_WITH_MODIFICATIONS
		self._dir_queue = queue.Queue()
		self._root = os.path.realpath(path)

		self._watch_manager = WatchManager()

		self._processor = FileProcessEvent(directory_queue=self._dir_queue, root=self._root, callback=callback, latency=latency)
		self._notifier = ThreadedNotifier(self._watch_manager, self._processor)

		self._notifier.name = "[inotify] notifier"
		self._notifier.daemon = True
		self._notifier.start()

		self._watch_manager.add_watch(path, self.event_mask, rec=True, auto_add=True)
	
	def stop(self):
		self._notifier.stop()
		self._processor.stop()
开发者ID:timbertson,项目名称:simple_notify,代码行数:22,代码来源:simple_notify.py

示例9: Watcher

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
class Watcher(object):
    """
        Watching on the fly
    """
    def __init__(self, gdr, workq, src, dst):
        self.gdr = gdr
        self.workq = workq
        self.src = src
        self.dst = dst

    def loop(self):
        wm = WatchManager()
        handler = EventHandler(self.workq, self.src, self.dst)

        self.notifier = ThreadedNotifier(wm, handler)
        self.notifier.start()

        mask =  IN_CREATE | IN_MODIFY
        wm.add_watch(self.src, mask, rec=self.gdr.rec)

    def stop(self):
        self.notifier.stop()
开发者ID:Noncz,项目名称:Sync,代码行数:24,代码来源:Watcher.py

示例10: main_loop

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
def main_loop():

    # Setup pyinotify so files are being watched:
    wm = WatchManager()
    notifier = ThreadedNotifier(wm, PTmp())
    notifier.start()

    mask = EventsCodes.ALL_FLAGS['IN_DELETE'] | EventsCodes.ALL_FLAGS['IN_CREATE'] | EventsCodes.ALL_FLAGS['IN_ATTRIB']   |EventsCodes.ALL_FLAGS['IN_MODIFY']# watched events
    #mask = EventsCodes.ALL_FLAGS['IN_DELETE'] | EventsCodes.ALL_FLAGS['IN_CREATE'] | EventsCodes.ALL_FLAGS['IN_MODIFY']# watched events
    #wdd = wm.add_watch('../sentry.py', mask, rec=True)
    #wdd = wm.add_watch('../', mask, rec=True)


    try:
        while True:

            print '\rConnections to %d clients. (%s)' % (len(open_handles), time_string()),
            sys.stdout.flush()
            update_subscribers(msg_type=MsgTypes.Heartbeat)
            time.sleep(5)

    except:
        notifier.stop()
        raise
开发者ID:mikehulluk,项目名称:python-devtools,代码行数:26,代码来源:test1,.py

示例11: __init__

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
class Observer:
    """Monitor files and notify the main program when changes happen"""
    def __init__(self, makeRunView):
        self.wm = WatchManager()
        self.eh = EventHandler(makeRunView)
        self.notifier = ThreadedNotifier(self.wm, self.eh)
        self.notifier.start()
        # Watched events
        self.mask = IN_DELETE | IN_CREATE | IN_CLOSE_WRITE

    def kill(self):
        status = self.notifier.stop()
        logging.debug("Observer shut down")
        return status

    def addFile(self, fname):
        wdd = self.wm.add_watch(fname, self.mask, rec=True)
开发者ID:mwidz,项目名称:makeRunView,代码行数:19,代码来源:observer.py

示例12: AutoLibraryUpdate

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
class AutoLibraryUpdate ( EventPlugin ):
    
    # Tell QL about our plugin:
    PLUGIN_ID = "Automatic library update"
    PLUGIN_NAME = "Automatic library update"
    PLUGIN_DESC = "Keep your quodlibet library up-to-date with inotify."
    PLUGIN_VERSION = "0.1"
    
    library = None
    wm = None
    tn = None
    event_handler = None
    running = False

    # Set everything up:
    def __init__( self ):
        from quodlibet.library import library as library

        self.library = library

    # enabled hook, get everything cooking:
    def enabled( self ):
        if not self.running :
            self.wm = WatchManager()
            
            # the event handler will do the actual event processing,
            # see the ALE class below for details
            self.event_handler = self.ALE( self )
            
            # we'll use a threaded notifier flagged as a daemon thread
            # so that it will stop when QL does
            self.tn = ThreadedNotifier( self.wm, self.event_handler )
            self.tn.daemon = True
            self.tn.start()

            # mask for watched events:
            FLAGS=EventsCodes.ALL_FLAGS
            mask = FLAGS['IN_DELETE'] | FLAGS['IN_CLOSE_WRITE']\
                | FLAGS['IN_MOVED_FROM'] | FLAGS['IN_MOVED_TO']

            # watch paths in scan_list:
            for path in self.scan_list():
                log ( 'Adding watch: for ' + path )
                self.wm.add_watch( path, mask, rec=True )

            self.running = True
    
    # disable hook, stop the notifier:
    def disabled( self ):
        if self.running:
            self.running = False
            self.tn.stop()

    # find list of directories to scan
    def scan_list( self ):
        return config.get( "settings", "scan").split(":")

    # auto-library-event class, handles the events
    class ALE( ProcessEvent ):
        def __init__( self, alu ):
            self._alu = alu
            log("alu : %s" % alu )
        # process close-write event (  copy, new file etc )
        def process_IN_CLOSE_WRITE(self, event):
            glib.idle_add( self.add_event, event )

        # process moved-to event:
        def process_IN_MOVED_TO( self, event ):
            log( 'moved event' )
            glib.idle_add( self.add_event, event )

        # general we think we added something callback:
        def add_event ( self, event ):
            lib = self._alu.library
            path = os.path.join(event.path, event.name)
            if event.dir:
                for path, dnames, fnames in os.walk(path):
                    for filename in fnames:
                        fullfilename = os.path.join(path, filename)
                        lib.add_filename(fullfilename)
            else:
                item =  lib.add_filename ( path )
                log( '%s added to library' % item )
            return False

        # process delete event
        def process_IN_DELETE(self, event):
            glib.idle_add( self.check_event, event )

        # process the moved-from event:
        def process_IN_MOVED_FROM( self, event ):
            glib.idle_add( self.check_event, event )
        
        # general "check to see if it's still there" callback:
        def check_event( self, event ):
            lib = self._alu.library
            path = os.path.join(event.path, event.name)

            log( 'check (%s) event for %s' %  (event.path, path) )

#.........这里部分代码省略.........
开发者ID:draxil,项目名称:Auto-library-update-plugin-for-quodlibet,代码行数:103,代码来源:auto_library_update.py

示例13: FilesystemMonitor

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
class FilesystemMonitor(object):
    """
    FileMonitor Class keeps track of all files down a tree starting at the root
    """

    def __init__(self, searcher):
        self.searcher = searcher
        
        self._thread_pool = ThreadPool(THREAD_POOL_WORKS)

        # Add a watch to the root of the dir
        self.watch_manager = WatchManager()
        self.notifier = ThreadedNotifier(self.watch_manager, FileProcessEvent(self))
        self.notifier.start()

        self._build_exclude_list()


    def _build_exclude_list(self):
        log.info("[FileMonitor] Set Regexs for Ignore List")

        self._exclude_regexs = []
        # Complie Ignore list in to a list of regexs
        for ignore in self.searcher.configuration.get_value("EXCLUDE_LIST"):
            ignore = ignore.strip()
            ignore = ignore.replace(".", "\.")
            ignore = ignore.replace("*", ".*")
            ignore = "^"+ignore+"$"
            log.debug("[FileMonitor] Ignore Regex = %s" % ignore)
            self._exclude_regexs.append(re.compile(ignore))

    def change_root(self, previous_root):
        self._thread_pool.clearTasks()

        wd = self.watch_manager.get_wd(previous_root)
        if wd:
          self.watch_manager.rm_watch(wd, rec=True)

        self.searcher.clear_database()
        self.add_directory(self.searcher.current_root)

    def add_directory(self, path):
        """
        Starts a WalkDirectoryThread to add the directory
        """
        basename = os.path.basename(path)
        if self.validate(basename):
            self.watch_manager.add_watch(path, EVENT_MASK)
            self._thread_pool.queueTask(self.walk_directory, path)

    def add_file(self, path, name):
        """
        Add a single file to the databse
        """
        if self.validate(name):
            self.searcher.add_file(path, name)

    def remove_file(self, path, name):
        self.searcher.remove_file(path, name)

    def remove_directory(self, path):
        self.searcher.remove_directory(path)

    def walk_directory(self, root):
        """
        From a give root of a tree this method will walk through ever branch
        and return a generator.
        """
        if os.path.isdir(root):
            names = os.listdir(root)
            for name in names:
                try:
                    file_stat = os.lstat(os.path.join(root, name))
                except os.error:
                    continue

                if stat.S_ISDIR(file_stat.st_mode):
                    self.add_directory(os.path.join(root, name))
                else:
                    if not stat.S_ISLNK(file_stat.st_mode):
                        self.add_file(root, name)
    def finish(self):
        wd = self.watch_manager.get_wd(self.searcher.current_root)
        self.watch_manager.rm_watch(wd, rec=True)
        self.notifier.stop()
        self._thread_pool.joinAll(waitForTasks=False)

    def validate(self, name):
         # Check to make sure the file not in the ignore list
        for ignore_re in self._exclude_regexs:
            if ignore_re.match(name):
                log.debug("[WalkDirectoryThread] ##### Ignored %s #####", name)
                return False
        log.debug("[WalkDirectoryThread] # Passed %s", name)
        return True
开发者ID:dguaraglia,项目名称:gedit-openfiles,代码行数:97,代码来源:filesystem_monitor.py

示例14: FileWatcher

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
class FileWatcher(ProcessEvent):

    """ FileWatcher -> Starts an INotify thread to watch a directory for
    file changes.

    """

    def __init__(self):
        """ FileWatcher(directory) -> Watch the directory for changes.

        """

        if not pyinotify:
            raise Exception("pyinotify is not loaded.")

        super(FileWatcher, self).__init__()

        self._file_callback_dict = {}

        self._watch_manager = WatchManager()
        self._events_mask = EventsCodes.ALL_FLAGS['IN_MODIFY']

        self._notifier = ThreadedNotifier(self._watch_manager, self)
        self._notifier.setDaemon(True)

    @classmethod
    def check(cls):
        """ Returns true if pyinotify is loaded otherwise false.

        """

        return pyinotify

    def is_running(self):
        """ Returns a boolean indecating the state of the notifier.

        """

        return self._notifier.isAlive()

    def start(self):
        """ Start the notifier thread.

        """

        self._notifier.start()

    def stop(self):
        """ Stop the notifier thread.

        """

        self._notifier.stop()

    def add_directory(self, directory):
        """ add_directory(directory) -> Add a directory to watch.

        """

        dir_watch = self._watch_manager.add_watch(directory, self._events_mask, rec=True)

    def remove_directory(self, directory):
        """ remove_directory(directory) -> Remove a directory from the watch.

        """

        self._watch_manager.rm_watch(directory, rec=True)

    def has_file(self, filename):
        """ Returns a boolean indecating if the file is being watched.

        """

        return filename in self._file_callback_dict

    def add_file(self, filename, callback, *user_data):
        """ add_file(filename, callback, *user_data) -> Add a file to watch
        with its callback and optional user_data.

        """

        self._file_callback_dict[filename] = (callback, user_data)

    def remove_file(self, filename):
        """ remove_file(filename) -> Remove the file from the watch list.

        """

        return self._file_callback_dict.pop(filename, None)

    def process_IN_MODIFY(self, event):
        """ Process modify events.

        """

        filename = os.path.join(event.path, event.name)
        callback_data = self._file_callback_dict.get(filename, ())

        if callback_data:
            callback = callback_data[0]
#.........这里部分代码省略.........
开发者ID:zepto,项目名称:webbrowser,代码行数:103,代码来源:file_watch.py

示例15: _process_directory

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import stop [as 别名]
      self._dispatch_download(file_path, file_name)
    else:
      print "Skipping %s" % file_name

  def _process_directory(self, dir_path):
    candidates = os.listdir(dir_path)
    print candidates
    for candidate in candidates:
      if candidate.split('.')[-1].lower() in allowed_extensions:
        self._dispatch_download(dir_path, candidate)
      else:
        print "Skipping %s" % candidate

print "SDownloader is now starting..."

wm = WatchManager()

wm.add_watch(target_dir, mask, rec=True, auto_add=True)
print "Sdownloader is now watching %s" % target_dir

notifier = ThreadedNotifier(wm, MyWatcher())
notifier.start()


while True:
  try:
    time.sleep(0.5)
  except (Exception, KeyboardInterrupt):
    notifier.stop()
    break
开发者ID:humwerthuz,项目名称:sdownloader,代码行数:32,代码来源:srt_auto_dwn.py


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