Beispiel #1
0
  def __init__(self):
    self.runsignal = True
    signal.signal(signal.SIGINT, self.sigint_handler)

    # The watch manager stores the watches and provides operations on watches
    self.wm = pyinotify.WatchManager()

    self.queue = Queue.Queue()
    handler = HandleEvents(self.queue)
    self.manager = FolderManager()
    self.notifier = pyinotify.ThreadedNotifier(self.wm, handler)
    self.notifier.start()
Beispiel #2
0
class Monitor(object):

  def __init__(self):
    self.runsignal = True
    signal.signal(signal.SIGINT, self.sigint_handler)

    # The watch manager stores the watches and provides operations on watches
    self.wm = pyinotify.WatchManager()

    self.queue = Queue.Queue()
    handler = HandleEvents(self.queue)
    self.manager = FolderManager()
    self.notifier = pyinotify.ThreadedNotifier(self.wm, handler)
    self.notifier.start()

  def run(self):
    indexer = IndexFiles()
    while self.runsignal:
      for folder in self.manager.get_followed():
        if not self.wm.get_wd(folder):
          mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE | \
                 pyinotify.IN_MODIFY | pyinotify.IN_MOVED_TO | \
                 pyinotify.IN_MOVE_SELF | pyinotify.IN_MOVED_FROM
          self.wm.add_watch(folder, mask, rec=True)
          print 'Monitoring folder %s...' % folder
      try:
        data = self.queue.get(False)
      except:
        data = None
      if data:
        if data[0] == '+':
          indexer.index_files(add=[data[1]])
        else:
          indexer.index_files(remove=[data[1]])
      time.sleep(5)

  def sigint_handler(self, signal, frame):
    print 'Stopping monitor...'
    self.notifier.stop()
    self.runsignal = False
Beispiel #3
0
from libs.indexmanager import FolderManager
from index import IndexFiles

if __name__ == "__main__":
    manager = FolderManager()
    indexer = IndexFiles()
    for followed in manager.get_followed():
        print "Updating folder %s..." % followed
        indexer.index_folder(followed)
    print "Updated."