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


Python ThreadedNotifier.start方法代码示例

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


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

示例1: _watch

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [as 别名]
 def _watch(self):
     wm = WatchManager()
     wm2 = WatchManager()
     
     clusterNotifier = ThreadedNotifier(wm, \
                         ClustersDefinitionsChangeHandler(\
                         masterCallback=self.callback))
     suiteNotifier = ThreadedNotifier(wm2, \
                         SuiteDefinitionsChangeHandler(\
                         masterCallback=self.callback))
     clusterNotifier.start()
     suiteNotifier.start()
     
     local_path = ''
     if self.config.has_option(self.repo, 'local_path'):
         local_path = self.config.get(self.repo, 'local_path')
     else:
         LOGGER.error('No local path defined for repository %s' % self.repo)
 
     if not self.config.has_option(self.repo, 'cluster_defs_path'):
         clustdir = local_path + os.sep + 'clusters'
     else: 
         clustdir = local_path + os.sep + self.config.get(self.repo, 'cluster_defs_path')
 
     if not self.config.has_option(self.repo, 'suite_defs_path'):
         suitedir = local_path + os.sep + 'test-suites'
     else: 
         suitedir = local_path + os.sep + self.config.get(self.repo, 'suite_defs_path')
     
     try:
         wm.add_watch(clustdir, self.mask, rec=True, quiet=False)
         wm2.add_watch(suitedir, self.mask, rec=True, quiet=False)
     except WatchManagerError, e:
         LOGGER.error(e)
开发者ID:jlsalmon,项目名称:xrootd-test-framework,代码行数:36,代码来源:DirectoryWatch.py

示例2: DirectoryWatcher

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [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

示例3: Notify

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [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

示例4: start_watching_disk_file

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [as 别名]
def start_watching_disk_file(filename, handler):
    logger.info("start watching %s" % filename)
    wm = WatchManager()
    notifier = ThreadedNotifier(wm, PTmp(wm, filename, handler))
    notifier.start()
    notifiers[filename] = notifier
    if os.path.exists(filename):
        handler.on_create(filename)
开发者ID:ChristophGr,项目名称:cryptdisk-control,代码行数:10,代码来源:mountwatcher.py

示例5: watch

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [as 别名]
	def watch(self):
		mask = pyinotify.IN_MODIFY | pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO

		self.__wm = WatchManager()
		self.__wm.add_watch(os.path.join(self.directory, *self.branch_dir), mask, rec = True)

		notifier = ThreadedNotifier(self.__wm, self.process_event)
		notifier.start()
开发者ID:mireq,项目名称:Git-watcher,代码行数:10,代码来源:gitwatcher.py

示例6: PhotoWatcher

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [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

示例7: __init__

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [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

示例8: setup_inotify

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [as 别名]
    def setup_inotify(self):
        if pyinotify is None:
            return False

        watch_manager = WatchManager()
        result = watch_manager.add_watch(self.__status_file, IN_MODIFY)[self.__status_file] > 0

        if result:
            global notifier
            def notify_cb(event):
                glib.idle_add(self.check_status_cb)
            notifier = ThreadedNotifier(watch_manager, notify_cb)
            notifier.start()
        return result
开发者ID:jeremybmerrill,项目名称:hdaps_indicator,代码行数:16,代码来源:indicator.py

示例9: schedule

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [as 别名]
 def schedule(self, name, event_handler, *paths):
     """Schedules monitoring."""
     #from pyinotify import PrintAllEvents
     #dispatcher = PrintAllEvents()
     dispatcher = _ProcessEventDispatcher(event_handler=event_handler)
     notifier = ThreadedNotifier(self.wm, dispatcher)
     self.notifiers.add(notifier)
     for path in paths:
         if not isinstance(path, str):
             raise TypeError(
                 "Path must be string, not '%s'." % type(path).__name__)
         descriptors = self.wm.add_watch(path, ALL_EVENTS, rec=True, auto_add=True)
     self.name_to_rule[name] = _Rule(name, notifier, descriptors)
     notifier.start()
开发者ID:stpremkumar,项目名称:watchdog,代码行数:16,代码来源:inotify_observer.py

示例10: live

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [as 别名]
def live(path, tv):
    chromedriver = os.path.join(os.path.split(os.path.realpath(__file__))[0],\
                                'chromedriver')
    os.environ['webdriver.chrome.driver'] = chromedriver
    browsers = [ getattr(webdriver, browser.title())() \
            for browser in [s.lower() for s in tv]]

    wm = WatchManager()
    notifier = ThreadedNotifier(wm, ProcessDir(browsers))
    notifier.start()

    print('watching %s' % os.path.abspath(path))
    mask = IN_MODIFY
    wdd = wm.add_watch(path, mask, rec=True)
开发者ID:leilux,项目名称:pagelive,代码行数:16,代码来源:pagelive.py

示例11: run

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [as 别名]
	def run(self):
		logging.info( 'Thead Watcher' )

		wm = WatchManager()
		notifier = ThreadedNotifier(wm, PTmp())
		notifier.start()
		wdd = wm.add_watch( account_dir, 4095, rec=True, auto_add=True) #ALL_EVENTS=>4095
		logging.info('Add watch on folder ' + account_dir);
		while True:
			try:
				notifier.process_events()
				if notifier.check_events():
					notifier.read_events()
			except KeyboardInterrupt:
				break
开发者ID:Panamedia-International,项目名称:Nube-x,代码行数:17,代码来源:nubex-client-listener.py

示例12: main

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [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

示例13: __init__

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [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

示例14: FileWatcher

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [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

示例15: lastwatch

# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import start [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


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