def run(self):
     """
     Run notify process in loop.
     """
     notifier = ThreadedNotifier(self.wm, EventHandler(), read_freq=0, threshold=0, timeout=10)
     self._addWatchers()
     notifier.loop()
Beispiel #2
0
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()
Beispiel #3
0
    def __init__(self, configuration, builder, watch_index):
        self._builder = builder
        self._root = configuration.GetExpandedDir("projects", "root_dir")
        self._batch_timeout = float(
            configuration.Get("file_watcher", "event_batch_timeout_ms")) / 1000
        self._moddef_filename = configuration.Get(
            "general", "module_definition_filename")
        self.wm = WatchManager()

        self.watch_index = watch_index
        self.watched_module_definitions = collections.defaultdict(dict)

        mask = (EventsCodes.ALL_FLAGS['IN_DELETE']
                | EventsCodes.ALL_FLAGS['IN_CREATE']
                | EventsCodes.ALL_FLAGS['IN_MODIFY'])
        handler = functools.partial(TargetWatcher.ProcessEvent, self)

        self.events_queue = queue.Queue()

        self.acc_thread = threading.Thread(target=functools.partial(
            TargetWatcher.AccumulationThreadProc, self),
                                           daemon=True)
        self.acc_thread.start()

        self.notifier = ThreadedNotifier(self.wm, handler)
        self.notifier.start()
        self.watch = self.wm.add_watch(self._root,
                                       mask,
                                       rec=True,
                                       auto_add=True)
        self.modification_handlers = []
Beispiel #4
0
def start_watching():
    class OnEvent(ProcessEvent):
        def __init__(self):
            ProcessEvent(self)
            self.timer = None

        def process_default(self, event):
            accepted = [
                pyinotify.IN_MODIFY, pyinotify.IN_MOVE_SELF,
                pyinotify.IN_MOVED_FROM, pyinotify.IN_MOVED_TO
            ]
            x = [x for x in accepted if event.mask & x == event.mask]
            if len(x) > 0:
                print "default: %-20s %s" % (os.path.join(
                    event.path, event.name), event.maskname)
                if self.timer:
                    self.timer.cancel()
                    self.timer = None
                self.timer = threading.Timer(0.2, do_post)
                self.timer.start()

    wm = WatchManager()
    mask = pyinotify.ALL_EVENTS
    proc = OnEvent()
    notifier = ThreadedNotifier(wm, proc)
    notifier.start()
    wdd = wm.add_watch('.git', mask, rec=True, auto_add=True)
Beispiel #5
0
def watch_files(paths, mask):
    """
    Vigila los ficheros de path y encola en queue los eventos producidos.

    """
    watcher = WatchManager()
    mask = (EventsCodes.ALL_FLAGS.get('IN_MODIFY', 0))

    @asyncio.coroutine
    def send_event(event):
        """Encola un evento en la cola."""
        yield from event_queue.put(event)

    notifier = ThreadedNotifier(
        watcher,
        lambda e: asyncio.get_event_loop().call_soon_threadsafe(
            asyncio.async, send_event(e)))

    for path in paths:
        watcher.add_watch(path, mask, rec=True)

    while True:
        notifier.process_events()
        event_present = yield from asyncio.get_event_loop().run_in_executor(
            None, notifier.check_events)
        if event_present:
            notifier.read_events()
Beispiel #6
0
	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()
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)
Beispiel #8
0
    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)
Beispiel #9
0
    def __watch_thread(self, root_lst, sync_list, cond, eventq):
        """
        初始化客户端监控文件变化的同步线程,根据同步的根目录列表和
        需要同步的文件目录白名单,获取需要监控的目录列表以及监控排除的文件列表添加到INotifier中

        @param root_lst: 监控的根目录列表
        @type root_lst: tuple
        @param sync_list: 需要同步的文件和目录的列表
        @type sync_list: tuple
        @param cond: 线程同步条件变量
        @type cond: threading.Condition
        @param eventq: 保存文件变化的事件队列
        @type eventq: pyinotify.Event
        @return: 初始化后的监控线程
        @rtype: pyinotify.ThreadedNotifier
        """
        wm = WatchManager()
        mask = IN_DELETE | IN_CLOSE_WRITE | IN_CREATE | IN_MOVED_FROM | IN_MOVED_TO
        thread_notifier = ThreadedNotifier(wm,
                        EventHandler(cond=cond, eventq=eventq,
                                     sync_list=sync_list),
                        read_freq=10, timeout=9)
        thread_notifier.coalesce_events() # Enable coalescing of events
        watch_lst = [] # INotifier watch direcory list
        exclude_lst = [] # INotifier exclude directory list
        LOGGER.debug('root:%s', str(root_lst))
        LOGGER.debug('sublist:%s', str(sync_list))
        for root_path in root_lst:
            # add root directory to watch list
            watch_lst.append(root_path['name'])
            if not root_path['is_all']:
                # get exclude sub direcory list
                for dirpath, _, _ in os.walk(root_path['name']):
                    if dirpath != root_path['name']:
                        for file_path in sync_list:
                            is_exclude = True
                            if file_path.startswith(dirpath) \
                            or dirpath.startswith(file_path):
                                # 遍历的目录为同步列表文件的父目录,
                                # 或者同步文件列表下的子目录,都不添加到排除目录列表
                                LOGGER.debug('dirpath:%s', dirpath)
                                LOGGER.debug('file_path:%s', file_path)
                                is_exclude = False
                                break
                        if is_exclude:
                            exclude_lst.append(dirpath)

        LOGGER.debug('watchlist:%s', str(watch_lst))
        LOGGER.debug('excludelist:%s', str(exclude_lst))
        excl = ExcludeFilter(exclude_lst)
        # 设置受监视的事件,(rec=True, auto_add=True)为递归处理
        wm_dict = wm.add_watch(watch_lst, mask, rec=True, auto_add=True,
                     exclude_filter=excl)
        LOGGER.debug('client monitor lst:%s', str(wm_dict))
        return thread_notifier
Beispiel #10
0
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)
Beispiel #11
0
    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()
Beispiel #12
0
 def watch_posix_start(self): 
     '''os-specific command to watch'''
     
     # test to see if we already have a notifier object, if not, make it, otherwise we are already watching a set of folders
     if self.notifier1 == None and self.notifier2 == None:
         
         try:
             pyinotify.compatibility_mode()
             print 'pyinotify running in compatibility mode'
         except:
             print 'pyinotify running in standard mode'
         try:
             #mask = EventsCodes.IN_CREATE |EventsCodes.IN_MOVED_TO 
             mask = pyinotify.ALL_EVENTS
             #ECJ20100831 Reason why we have two threads: it never returns control ever to the main loop if only one thread, so no ctrl+c
             #The second thread is a dummy, so it performs switching/relinquishing control
             #Eventually, we want to watch many folders, so that is why we are using the ThreadedNotifier, versus the recommended Notifier.
             #Even then, Notifier is still probably the way to go, but we'll use this as long as it works, because then you don't have to poll/While loop
             
             # Thread #1
             watch_manager1 = WatchManager()
             self.notifier1 = ThreadedNotifier(watch_manager1, EventHandler(self.queue))
             self.notifier1.start()
             print 'Starting the threaded notifier on ', self.dir_to_watch
             watch_manager1.add_watch(self.dir_to_watch, mask)
             # Thread #2
             watch_manager2 = WatchManager()
             self.notifier2 = ThreadedNotifier(watch_manager2, EventHandlerDummy(self.queue))
             self.notifier2.start()
             #just watch any place, but don't remove this or Ctrl+C will not work
             watch_manager2.add_watch(settings.BASE_PATH, mask)
             if settings.DEBUG:
                 print "both notifiers started"
         
         except KeyboardInterrupt:
             print "Keyboard Interrupt in notifier"
             self.notifier1.stop()
             self.notifier2.stop()
             
             return
         except NameError:
             self.notifier1.stop()
             self.notifier2.stop()
             return ['POSIX Watch Error']
         except:
             print "General exception caught within notifier while loop, stopping both notifiers now"
             self.notifier1.stop()
             self.notifier2.stop()
             
             # SBB20090903 Turn on verbose mode
             self.notifier1.VERBOSE = settings.DEBUG
             print "returning to calling function"
             return True
Beispiel #13
0
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
Beispiel #14
0
 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_watch_loop(self):
        wm = WatchManager()
        process = self.Process(self.folderpath, self.event_callback)  #options)
        self.notifier = ThreadedNotifier(wm, process)  #Notifier(wm, process)

        #notifier = Notifier(wm)
        mask = IN_DELETE | IN_CREATE | IN_CLOSE_WRITE
        #wdd = wm.add_watch(options.directory, mask, rec=True)
        #wm.add_watch('./excelsrc', mask, rec=True)
        wm.add_watch('./' + self.folderpath, mask, rec=True)

        self.notifier.start()
        """	
Beispiel #16
0
 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)
Beispiel #17
0
    def test_gutils_netcdf_to_erddap_watch(self):

        wm = WatchManager()
        mask = IN_MOVED_TO | IN_CLOSE_WRITE

        # Convert ASCII data to NetCDF
        processor = Netcdf2ErddapProcessor(
            deployments_path=resource('slocum'),
            erddap_content_path=erddap_content_path,
            erddap_flag_path=erddap_flag_path
        )
        notifier = ThreadedNotifier(wm, processor, read_freq=5)
        notifier.coalesce_events()
        notifier.start()

        wdd = wm.add_watch(
            netcdf_path,
            mask,
            rec=True,
            auto_add=True
        )

        # Wait 5 seconds for the watch to start
        time.sleep(5)

        orig_netcdf = resource('profile.nc')
        dummy_netcdf = os.path.join(netcdf_path, 'profile.nc')
        shutil.copy(orig_netcdf, dummy_netcdf)

        wait_for_files(erddap_content_path, 1)
        wait_for_files(erddap_flag_path, 1)

        wm.rm_watch(wdd.values(), rec=True)
        notifier.stop()
Beispiel #18
0
    def test_gutils_ascii_to_netcdf_watch(self):

        wm = WatchManager()
        mask = IN_MOVED_TO | IN_CLOSE_WRITE

        # Convert ASCII data to NetCDF
        processor = Slocum2NetcdfProcessor(deployments_path=resource('slocum'),
                                           subset=False,
                                           template='trajectory',
                                           profile_id_type=2,
                                           tsint=10,
                                           filter_distance=1,
                                           filter_points=5,
                                           filter_time=10,
                                           filter_z=1)
        notifier = ThreadedNotifier(wm, processor)
        notifier.coalesce_events()
        notifier.start()

        wdd = wm.add_watch(ascii_path, mask, rec=True, auto_add=True)

        # Wait 5 seconds for the watch to start
        time.sleep(5)

        # Make the ASCII we are watching for
        merger = SlocumMerger(original_binary,
                              ascii_path,
                              globs=['*.tbd', '*.sbd'])
        merger.convert()

        wait_for_files(netcdf_path, 230)

        wm.rm_watch(wdd.values(), rec=True)
        notifier.stop()
    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
Beispiel #20
0
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)
Beispiel #21
0
    def test_gutils_binary_to_ascii_watch(self):

        wm = WatchManager()
        mask = IN_MOVED_TO | IN_CLOSE_WRITE

        # Convert binary data to ASCII
        processor = Slocum2AsciiProcessor(
            deployments_path=resource('slocum'),
        )
        notifier = ThreadedNotifier(wm, processor)
        notifier.coalesce_events()
        notifier.start()

        wdd = wm.add_watch(
            binary_path,
            mask,
            rec=True,
            auto_add=True
        )

        # Wait 5 seconds for the watch to start
        time.sleep(5)

        gpath = os.path.join(original_binary, '*.*bd')
        # Sort the files so the .cac files are generated in the right order
        for g in sorted(glob(gpath)):
            shutil.copy2(g, binary_path)

        wait_for_files(ascii_path, 32)

        wm.rm_watch(wdd.values(), rec=True)
        notifier.stop()
Beispiel #22
0
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)
Beispiel #23
0
        def __init__(self, path, exclude=None):
            class _EH(ProcessEvent):
                def process_default(self, event):
                    _handleEvent(event)

            Queue.__init__(self)
            self._path = path
            self.exclude = exclude or []
            _handleEvent = self.put
            self._wm = WatchManager()
            self._iNotifier = ThreadedNotifier(self._wm, _EH(), timeout=10)
            self._iNotifier.start()
            self.started = False
            self._watch = []
 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()
def get_threaded_notifier(paths,db_file,flush_interval,verbose,fs_encodings=[]):

	wm = WatchManager()
	eventhandler = FileStatEventHandler(wm,db_file,flush_interval,verbose,fs_encodings)
	
	notifier = ThreadedNotifier(wm, eventhandler)
	notifier.start()
	for p in paths:
		if verbose:
			print '  Monitoring "%s" ... ' % p,
		wdd = wm.add_watch(p, mask, rec=True,auto_add=False)
		if verbose:
			print '[done]'
	
	return eventhandler,notifier
Beispiel #26
0
 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 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
Beispiel #28
0
    def enabled(self):
        if not self.running:
            wm = WatchManager()
            self.event_handler = LibraryEvent(app.library)

            # Choose event types to watch for
            # FIXME: watch for IN_CREATE or for some reason folder copies
            # are missed,  --nickb
            FLAGS = [
                'IN_DELETE',
                'IN_CLOSE_WRITE',  # 'IN_MODIFY',
                'IN_MOVED_FROM',
                'IN_MOVED_TO',
                'IN_CREATE'
            ]
            mask = reduce(lambda x, s: x | EventsCodes.ALL_FLAGS[s], FLAGS, 0)

            if self.USE_THREADS:
                print_d("Using threaded notifier")
                self.notifier = ThreadedNotifier(wm, self.event_handler)
                # Daemonize to ensure thread dies on exit
                self.notifier.daemon = True
                self.notifier.start()
            else:
                self.notifier = Notifier(wm, self.event_handler, timeout=100)
                GLib.timeout_add(1000, self.unthreaded_callback)

            for path in get_scan_dirs():
                print_d('Watching directory %s for %s' % (path, FLAGS))
                # See https://github.com/seb-m/pyinotify/wiki/
                # Frequently-Asked-Questions
                wm.add_watch(path, mask, rec=True, auto_add=True)

            self.running = True
Beispiel #29
0
	def persy_start(self):
		"""
		initializes the worker thread and notifier
		"""
		self.log.info("start working")
		self.log.setStart()
		self.running = True
		FLAGS=EventsCodes.ALL_FLAGS
		mask = FLAGS['IN_MODIFY'] | FLAGS['IN_DELETE_SELF']|FLAGS['IN_DELETE'] | FLAGS['IN_CREATE'] | FLAGS['IN_CLOSE_WRITE'] | FLAGS['IN_MOVE_SELF'] | FLAGS['IN_MOVED_TO'] | FLAGS['IN_MOVED_FROM'] # watched events

		wm = WatchManager()
		#addin the watched directories
		for watch in self.config['local']['watched']:
			wdd = wm.add_watch("%s"%(watch), mask, rec=True, auto_add=True)

		#watch for changes of the configurationfile
		if self.config['general']['autoshare']:
			wdd = wm.add_watch(self.config.getAttribute('CONFIGFILE'), mask, rec=True, auto_add=True)

		self.log.debug("init the syncer")
		self.worker = TheSyncer(self, self.config, self.log, self.config['remote']['sleep'], self.config['local']['sleep'])
		self.log.debug("init the filesystem notifier")
		self.notifier = ThreadedNotifier(wm, FileChangeHandler(self.log, self.worker.newEvent))
		self.log.resetError()
		self.log.debug("starting syncer")
		self.worker.start()
		self.notifier.start()
Beispiel #30
0
    def enabled(self):
        if not self.running:
            wm = WatchManager()
            self.event_handler = LibraryEvent(library=app.library)

            FLAGS = ['IN_DELETE', 'IN_CLOSE_WRITE', # 'IN_MODIFY',
                     'IN_MOVED_FROM', 'IN_MOVED_TO', 'IN_CREATE']

            masks = [EventsCodes.FLAG_COLLECTIONS['OP_FLAGS'][s]
                     for s in FLAGS]
            mask = reduce(operator.or_, masks, 0)

            if self.USE_THREADS:
                print_d("Using threaded notifier")
                self.notifier = ThreadedNotifier(wm, self.event_handler)
                # Daemonize to ensure thread dies on exit
                self.notifier.daemon = True
                self.notifier.start()
            else:
                self.notifier = Notifier(wm, self.event_handler, timeout=100)
                GLib.timeout_add(1000, self.unthreaded_callback)

            for path in get_scan_dirs():
                real_path = os.path.realpath(path)
                print_d('Watching directory %s for %s (mask: %x)'
                        % (real_path, FLAGS, mask))
                # See https://github.com/seb-m/pyinotify/wiki/
                # Frequently-Asked-Questions
                wm.add_watch(real_path, mask, rec=True, auto_add=True)

            self.running = True
Beispiel #31
0
    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)
Beispiel #32
0
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
Beispiel #33
0
    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
Beispiel #34
0
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)
Beispiel #35
0
    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)
Beispiel #36
0
    class _PathWatcher(Queue):  # iNotify watcher for directory
        '''
    iNotify watcher object for monitor of changes in directory.
    '''
        FLAGS = IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVED_FROM | IN_MOVED_TO | IN_ATTRIB

        def __init__(self, path, exclude=None):
            class _EH(ProcessEvent):
                def process_default(self, event):
                    _handleEvent(event)

            Queue.__init__(self)
            self._path = path
            self.exclude = exclude or []
            _handleEvent = self.put
            self._wm = WatchManager()
            self._iNotifier = ThreadedNotifier(self._wm, _EH(), timeout=10)
            self._iNotifier.start()
            self.started = False
            self._watch = []

        def start(self, exclude=None):
            if not self.started:
                # Add watch and start watching
                # Update exclude filter if it provided in call of start method
                self.exclude = exclude or self.exclude
                self._watch = self._wm.add_watch(self._path,
                                                 self.FLAGS,
                                                 exclude_filter=ExcludeFilter(
                                                     self.exclude),
                                                 auto_add=True,
                                                 rec=True,
                                                 do_glob=False)
                self.started = True

        def stop(self):
            if self.started:
                # Remove watch and stop watching
                self._wm.rm_watch(self._watch[self._path], rec=True)
                self.started = False

        def exit(self):
            self.stop()
            self._iNotifier.stop()
Beispiel #37
0
def start_daemon(path, dbpath, md_queue, fd_queue, condition):
   """ installs a subtree listener and wait for events """
   os.nice(19)

   wm_auto = WatchManager()
   subtreemask = IN_CLOSE_WRITE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO | IN_CREATE | IN_ISDIR
   excludefilter = ExcludeFilter(["(.*)sqlite"])
   notifier_sb = ThreadedNotifier(wm_auto, SubtreeListener(dbpath, md_queue, fd_queue, condition))
   notifier_sb.start()
   THREADS.append(notifier_sb)

   wdd_sb = wm_auto.add_watch(path, subtreemask, auto_add=True, rec=True, exclude_filter=excludefilter)

   THREADS.append(PollAnalyzer(condition, dbpath))
   THREADS[-1].start()
#   THREADS.append(CatalogThreadingTCPServer(("localhost", 8080), CatalogHTTPRequestHandler, dbpath))
#   THREADS[-1].serve_forever()

   THREADS[-1].join()
Beispiel #38
0
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
Beispiel #39
0
    def run(self):
        # Setup. Ensure that this isn't interleaved with any other thread, so
        # that the DB setup continues as expected.
        self.lock.acquire()
        FSMonitor.setup(self)
        self.process_event = FSMonitorInotifyProcessEvent(self)
        self.lock.release()

        # Set up inotify.
        self.wm = WatchManager()
        self.notifier = ThreadedNotifier(self.wm, self.process_event)

        self.notifier.start()

        while not self.die:
            self.__process_queues()
            time.sleep(0.5)

        self.notifier.stop()
Beispiel #40
0
def create_watcher():
    from pyinotify import WatchManager, Notifier, ThreadedNotifier, \
                          EventsCodes, ProcessEvent, IN_CLOSE_WRITE
    wm = WatchManager()
    mask = IN_CLOSE_WRITE #| EventsCodes.IN_CREATE  # watched events

    class PTmp(ProcessEvent):
        def process_IN_CLOSE_WRITE(self, event):
            def inner(): on_reload_event(event)
            gdb.post_event(inner)

    notifier = ThreadedNotifier(wm, PTmp())
    wdd = wm.add_watch(WORKING_DIR, mask, rec=True)
    notifier.daemon = True # Then our atexit function will work
    notifier.start()
    def on_exited(*e): notifier.stop()
    import atexit
    atexit.register(on_exited)
    return (notifier, wdd)
Beispiel #41
0
class FilesystemWatcher:

    # Mask for FS events we are interested in - currently only care about
    # writable file streams that have been closed (i.e. a pdf has finished
    # uploading)

    mask = EventsCodes.ALL_FLAGS['IN_CLOSE_WRITE']

    # This is the main watch manager provided by pyinotify
    # we use this to manage subscriptions
    _wm = WatchManager()

    # List of watched directories
    wdd = {}

    # create a thread-safe queue for papers that must be processed.
    paper_queue = Queue()

    def __init__(self, logger):
        self.logger = logger
        self.notifier = ThreadedNotifier(
            self._wm, PaperProcesser(self.logger, self.paper_queue))

    def watch_directory(self, path):
        """set up threaded directory watcher at given path"""

        self._wm.add_watch(path, self.mask, rec=True)

        #add all files in the given directory to queue
        for root, dirs, files in os.walk(path):

            for file in files:
                if file.endswith("pdf") or file.endswith("xml"):
                    self.logger.info("Adding %s to queue", file)

                    self.paper_queue.put(("QUEUE", os.path.join(root, file)))

    def start(self):
        self.notifier.start()

    def stop(self):
        self.notifier.stop()
Beispiel #42
0
        def __init__(self, serverhandler):
            self.wm = WatchManager()
            self.notifier = ThreadedNotifier(self.wm, self)
            self.moduleMap = {}
            self.watchDescriptorMap = {}
            self.serverhandler = serverhandler
            self.shuttingDown = False

            flags = EventsCodes.ALL_FLAGS
            path, watchDescriptor = list(self.wm.add_watch('commands/', flags['IN_CREATE'] | flags['IN_DELETE']).items())[0]
            self.watchDescriptorMap[path] = watchDescriptor
Beispiel #43
0
	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))
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()
    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()
Beispiel #46
0
 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))
Beispiel #47
0
    def __init__(self, path):
        """
        Initialisation.

        @param   path (str)   Full path to watch.
        """
        self.path = path

        if os.path.isdir(self.path):
            self.path_dir = self.path
            self.path_file = None
        else:
            self.path_dir = os.path.dirname(self.path)
            self.path_file = os.path.basename(self.path)

        self.callbacks = {}

        wm = WatchManager()
        wm.add_watch(self.path_dir, pyinotify.ALL_EVENTS)
        self.inotifier = ThreadedNotifier(wm, self.__processINotify)
        self.inotifier.start()
Beispiel #48
0
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
 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)
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
Beispiel #51
0
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()
Beispiel #52
0
def monitor(filename, server):
    """Monitor the config file for changes and update the server's values when they do.

    Using pyinotify, it checks the config file for changes and tells the
    server to make changes when they occur. Starts and returns the
    ThreadedNotifier that is created.

    Keyword arguments:
    filename -- the name of the file you want to monitor. Note that it won't actually monitor this file, but the directory it resides in.
    server -- the EmailServer currently running, to pass the new values to when they're changed.

    """
    logging.info('Monitoring {0} for changes'.format(filename))

    wm = WatchManager()
    notifier = ThreadedNotifier(wm, PClose(server, filename))
    notifier.name = 'MonitorThread'
    # we actually watch the folder to the file, otherwise the handle is lost every time the file is modified.
    wm.add_watch(os.path.split(filename)[0], IN_CLOSE_WRITE, rec=True)

    notifier.start()
    return notifier
Beispiel #53
0
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()
Beispiel #54
0
    def __init__(self, db_wrapper, root, config):
        self._file_count = 0
        self._db_wrapper = db_wrapper
        self._root = os.path.realpath(root)
        self._walk_thread = None
        self._config = config
        self._ignore_regexs = []
        self._set_ignore_list()

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

        # initial walk
        self.add_dir(self._root)
Beispiel #55
0
    def showDialogSetDatadir(self):
        #        print "foo"
        #fname = QtGui.QFileDialog.getOpenFileName(None,'Open file', self.parentDataDir)
        fname = str(
            QtGui.QFileDialog.getExistingDirectory(
                None, "Set directory for input data"))
        self.pars['dataDir'] = fname + '/'
        self.notifier.stop()
        wm = WatchManager()
        notifier = ThreadedNotifier(wm, self.process_IN_CREATE)
        self.notifier = notifier

        print "input data directory is now: " + str(self.pars['dataDir'])
        self.ui.lineEditDataDir.setText(self.pars['dataDir'])
        self.notifier.start()
        mask = EventsCodes.ALL_FLAGS['IN_CREATE']
        wdd = wm.add_watch(self.pars['dataDir'], mask, rec=False)
Beispiel #56
0
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
Beispiel #57
0
 def __init__(self, logger):
     self.logger = logger
     self.notifier = ThreadedNotifier(
         self._wm, PaperProcesser(self.logger, self.paper_queue))
class FileRsyncWatcher(ProcessEvent):
    _redis = redis.Redis(host='localhost', port=6379, db=0)
    #TODO: put into config file
    _queue_name = "rsync_files_changed"

    def process_IN_MOVED_TO(self, event):
        if os.path.basename(event.name)[0] != ".":
            self._redis.lpush(self._queue_name,
                              os.path.join(event.path, event.name))


path = "."
wm = WatchManager()
mask = IN_MOVED_TO
notifier = ThreadedNotifier(wm, FileRsyncWatcher())
wm.add_watch(path, mask, auto_add=True, rec=True)
notifier.start()


def fun_quit(a, b):
    global flag_run
    flag_run = False
    notifier.stop()


signal.signal(signal.SIGINT, fun_quit)
signal.signal(signal.SIGTERM, fun_quit)

while flag_run:
    time.sleep(1)
Beispiel #59
0
    def __init__(self, parent = None):
        QtGui.QWidget.__init__(self, parent)
        self.canvas = MplCanvas()
        self.vbl = QtGui.QVBoxLayout()
        self.vbl.addWidget(self.canvas)
        #--
        self.mpl_toolbar = NavigationToolbar(self.canvas, None) 
        self.vbl.addWidget(self.mpl_toolbar)
        #--
        self.setLayout(self.vbl)

        
        
        
        
        
        
        
        
        
        
        self.extractWin_x0=self.extractWinSlider.lowerValue
        self.extractWin_x1=self.extractWinSlider.upperValue
        self.SB1_x0=self.SB1Slider.lowerValue
        self.SB1_x1=self.SB1Slider.upperValue
        self.SB2_x0=self.SB2Slider.lowerValue
        self.SB2_x1=self.SB2Slider.upperValue
 

        
        
        
        
        
        
        
        
        
        
        
        
        
        
        self.autoExtraction=True
        self.lamp=None
        self.grating=None

#        self.raw2DGraph = QtGui.QGraphicsView(self.centralWidget)
#        self.raw2DGraph = QtGui.QWidget(self.centralWidget)
        self.raw2DGraph = matplotlibWidget(self.centralWidget)
        self.raw2DGraph.setGeometry(QtCore.QRect(20, 40, 1061, 81))
        self.raw2DGraph.setObjectName(_fromUtf8("raw2DGraph"))

        
        self.skysub2DView = matplotlibWidget(self.centralWidget)
        self.skysub2DView.setGeometry(QtCore.QRect(20, 160, 1061, 81))
        self.skysub2DView.setObjectName(_fromUtf8("skysub2DView"))

        self.useSB1Check = QtGui.QCheckBox(self.centralWidget)
        self.useSB1Check.setGeometry(QtCore.QRect(1110, 560, 85, 21))
        self.useSB1Check.setChecked(True)
        self.useSB1Check.setObjectName(_fromUtf8("useSB1Check"))
        self.useSB2Check = QtGui.QCheckBox(self.centralWidget)
        self.useSB2Check.setGeometry(QtCore.QRect(1260, 560, 85, 21))
        self.useSB2Check.setChecked(True)
        self.useSB2Check.setObjectName(_fromUtf8("useSB2Check"))
        
        
        # ----
        
        # ---- 1D extracted spec
        
        self.spec1DView = matplotlibWidgetwBar(self.centralWidget)
        self.spec1DView.setGeometry(QtCore.QRect(20, 290, 1061, 381))
        self.spec1DView.setObjectName(_fromUtf8("spec1DView"))

        # ----

        # ---- 2D spec related stuff
        self.z0Fill = QtGui.QLineEdit(self.centralWidget)
        self.z0Fill.setGeometry(QtCore.QRect(1140, 50, 113, 23))
        self.z0Fill.setObjectName(_fromUtf8("z0Fill"))
        self.z1Fill = QtGui.QLineEdit(self.centralWidget)
        self.z1Fill.setGeometry(QtCore.QRect(1290, 50, 113, 23))
        self.z1Fill.setObjectName(_fromUtf8("z1Fill"))
        self.ScalingCombo = QtGui.QComboBox(self.centralWidget)
        self.ScalingCombo.setGeometry(QtCore.QRect(1160, 80, 78, 24))
        self.ScalingCombo.setObjectName(_fromUtf8("ScalingCombo"))
        self.ScalingCombo.addItem(_fromUtf8(""))
        self.ScalingCombo.addItem(_fromUtf8(""))
        self.ScalingCombo.addItem(_fromUtf8(""))
        self.zScaleUpdateBut = QtGui.QPushButton(self.centralWidget)
        self.zScaleUpdateBut.setGeometry(QtCore.QRect(1280, 80, 99, 24))
        self.zScaleUpdateBut.setObjectName(_fromUtf8("zScaleUpdateBut"))

        # ----



        # ---- log window and file loaders

#        self.logView = QtGui.QListView(self.centralWidget)
        self.logView = QtGui.QTextEdit(self.centralWidget)
        self.logView.setReadOnly(True)
#        self.logView.setGeometry(QtCore.QRect(20, 710, 531, 192))
        self.logView.setGeometry(QtCore.QRect(20, 710, 731, 192))
        self.logView.setObjectName(_fromUtf8("logView"))
        self.CurrFrameBut = QtGui.QPushButton(self.centralWidget)
        #self.CurrFrameBut.setGeometry(QtCore.QRect(740, 720, 99, 24))
        self.CurrFrameBut.setGeometry(QtCore.QRect(940, 720, 99, 24))
        self.CurrFrameBut.setObjectName(_fromUtf8("CurrFrameBut"))
        self.currFrameFill = QtGui.QLineEdit(self.centralWidget)
        #self.currFrameFill.setGeometry(QtCore.QRect(600, 720, 131, 23))
        self.currFrameFill.setGeometry(QtCore.QRect(800, 720, 131, 23))
        self.currFrameFill.setObjectName(_fromUtf8("currFrameFill"))
        self.curArcBut = QtGui.QPushButton(self.centralWidget)
        self.curArcBut.setEnabled(False)
        self.curArcBut.setGeometry(QtCore.QRect(940, 770, 99, 24))
        self.curArcBut.setObjectName(_fromUtf8("curArcBut"))
        self.currArcFill = QtGui.QLineEdit(self.centralWidget)
        self.currArcFill.setGeometry(QtCore.QRect(800, 770, 131, 23))
        self.currArcFill.setObjectName(_fromUtf8("currArcFill"))
        self.curFlatBut = QtGui.QPushButton(self.centralWidget)
        self.curFlatBut.setEnabled(False)
        self.curFlatBut.setGeometry(QtCore.QRect(940, 820, 99, 24))
        self.curFlatBut.setObjectName(_fromUtf8("curFlatBut"))
        self.currFlatFill = QtGui.QLineEdit(self.centralWidget)
        self.currFlatFill.setGeometry(QtCore.QRect(800, 820, 131, 23))
        self.currFlatFill.setObjectName(_fromUtf8("currFlatFill"))
        self.curFluxCalBut = QtGui.QPushButton(self.centralWidget)
        self.curFluxCalBut.setEnabled(False)
        self.curFluxCalBut.setGeometry(QtCore.QRect(940, 870, 99, 24))
        self.curFluxCalBut.setObjectName(_fromUtf8("curFluxCalBut"))
        self.currFluxCalFill = QtGui.QLineEdit(self.centralWidget)
        self.currFluxCalFill.setGeometry(QtCore.QRect(800, 870, 131, 23))
        self.currFluxCalFill.setObjectName(_fromUtf8("currFluxCalFill"))
        
        
        # -- temp stuff fold old spectrograph only (no grating keyword in header)
        self.gratingCombo = QtGui.QComboBox(self.centralWidget)
        self.gratingCombo.setGeometry(QtCore.QRect(1150, 790, 171, 24))
        self.gratingCombo.setObjectName(_fromUtf8("gratingCombo"))
        self.gratingCombo.addItem(_fromUtf8(""))
        self.gratingCombo.addItem(_fromUtf8(""))
        self.gratingCombo.addItem(_fromUtf8(""))
        self.label_15 = QtGui.QLabel(self.centralWidget)
        self.label_15.setGeometry(QtCore.QRect(1130, 760, 141, 16))
        self.label_15.setObjectName(_fromUtf8("label_15"))
        # --
        
        
        
        
        self.parentDataDir=None #'/home/gilbank/Proj/CassSpect/data/Deatrick/'
        self.imagetype=""
        self.lastWLCFile=None
        self.wlc=False
        self.latestFrame=None ##self.parentDataDir+'a3000142.fits'
        #self.ReadOutDelay = 2.0 # seconds # not used now
        
        # ----
        
        
        self.widget = QtGui.QWidget(self.centralWidget)

        """
        self.widget.setGeometry(QtCore.QRect(740, 130, 333, 23))
        self.widget.setObjectName(_fromUtf8("widget"))
        """
        
        self.horizontalLayout = QtGui.QHBoxLayout(self.widget)
        self.horizontalLayout.setMargin(0)
        self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
        self.showSBCheck = QtGui.QCheckBox(self.widget)
        self.showSBCheck.setChecked(True)
        self.showSBCheck.setObjectName(_fromUtf8("showSBCheck"))
        self.horizontalLayout.addWidget(self.showSBCheck)
        self.showEWCheck = QtGui.QCheckBox(self.widget)
        self.showEWCheck.setChecked(True)
        self.showEWCheck.setObjectName(_fromUtf8("showEWCheck"))
        self.horizontalLayout.addWidget(self.showEWCheck)
        MainWindow.setCentralWidget(self.centralWidget)
        self.menuBar = QtGui.QMenuBar(MainWindow)
        self.menuBar.setGeometry(QtCore.QRect(0, 0, 1437, 21))
        self.menuBar.setObjectName(_fromUtf8("menuBar"))
        self.menuFile = QtGui.QMenu(self.menuBar)
        self.menuFile.setObjectName(_fromUtf8("menuFile"))
        MainWindow.setMenuBar(self.menuBar)
        self.mainToolBar = QtGui.QToolBar(MainWindow)
        self.mainToolBar.setObjectName(_fromUtf8("mainToolBar"))
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
        self.statusBar = QtGui.QStatusBar(MainWindow)
        self.statusBar.setObjectName(_fromUtf8("statusBar"))
        MainWindow.setStatusBar(self.statusBar)
        self.actionSet_data_dir = QtGui.QAction(MainWindow)
        self.actionSet_data_dir.setObjectName(_fromUtf8("actionSet_data_dir"))
        self.actionQuit = QtGui.QAction(MainWindow)
        self.actionQuit.setObjectName(_fromUtf8("actionQuit"))
        self.actionLoadData = QtGui.QAction(MainWindow)
        self.actionLoadData.setObjectName(_fromUtf8("actionLoadData"))
        self.menuFile.addAction(self.actionSet_data_dir)
        self.menuFile.addAction(self.actionLoadData)
        self.menuFile.addAction(self.actionQuit)
        self.menuBar.addAction(self.menuFile.menuAction())

        self.scaledImage=None

        self.retranslateUi(MainWindow)
        QtCore.QObject.connect(self.showEWCheck, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.displayRaw2D)
        QtCore.QObject.connect(self.showSBCheck, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.displayRaw2D)
        QtCore.QObject.connect(self.zScaleUpdateBut, QtCore.SIGNAL(_fromUtf8("clicked()")), self.updatezScaling)
        QtCore.QObject.connect(self.autoExtractBut, QtCore.SIGNAL(_fromUtf8("clicked()")), self.updateAutoExtraction)
        #QtCore.QObject.connect(self.showSBCheck, QtCore.SIGNAL(_fromUtf8("clicked()")), MainWindow.show)
        QtCore.QObject.connect(self.SB1Slider, QtCore.SIGNAL(_fromUtf8("sliderReleased()")), self.readExtractionSliders)
        QtCore.QObject.connect(self.SB2Slider, QtCore.SIGNAL(_fromUtf8("sliderReleased()")), self.readExtractionSliders)
        QtCore.QObject.connect(self.extractWinSlider, QtCore.SIGNAL(_fromUtf8("sliderReleased()")), self.readExtractionSliders)
        QtCore.QObject.connect(self.useSB1Check, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.updateAll)
        QtCore.QObject.connect(self.useSB2Check, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.updateAll)
        
        QtCore.QObject.connect(self.actionLoadData, QtCore.SIGNAL(_fromUtf8("activated()")), self.showDialog)
#        QtCore.QObject.connect(self.CurrFrameBut, QtCore.SIGNAL(_fromUtf8("clicked()")), self.showDialog)
        
        QtCore.QObject.connect(self.actionSet_data_dir, QtCore.SIGNAL(_fromUtf8("activated()")), self.showDialogSetDatadir)        
        QtCore.QObject.connect(self.actionQuit, QtCore.SIGNAL(_fromUtf8("activated()")), self.closeEvent)        
        
        QtCore.QMetaObject.connectSlotsByName(MainWindow)        


        if(self.parentDataDir==None):
            self.showDialogSetDatadir()

        # -- pyinotify code for monitoring dir for new files:
        wm = WatchManager()
#        notifier = ThreadedNotifier(wm, PTmp())
        notifier = ThreadedNotifier(wm, self.process_IN_CREATE)
#        notifier = ThreadedNotifier(wm, self.processMonitorData)
#        notifier = Notifier(wm, PTmp())
        notifier.start()
        mask = EventsCodes.ALL_FLAGS['IN_CREATE']
        wdd = wm.add_watch(self.parentDataDir, mask, rec=False)