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 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
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()
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 = []
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()
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)
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
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 __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
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 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 __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() """
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)
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 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
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)
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
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)
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)
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()
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()
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)
def __init__(self, parent=None, infile=None): QtGui.QWidget.__init__(self, parent) #set up the main UI self.ui = Ui_MainWindow() self.ui.setupUi(self) self.dbglvl = dbglvl # self.libdir='/home/gilbank/Proj/spup/GUI/libs/' # self.libdir='libs/' self.libdir = '/usr/local/lib/qlgui/' self.settingsdir = '/home/ccd/.spup/' self.spup = True # else work with old spectrograph data self.ui.logView.setReadOnly(True) # Install the custom output stream sys.stdout = EmittingStream(textWritten=self.normalOutputWritten) # set some default size values. use to try to set sliders, etc. to sensible ranges: if (self.spup): self.sx = 2148 self.sy = 256 # self.sy = 128 # 1x2 binning else: self.sx = 2098 self.sy = 512 self.xbin = 1 # self.ybin=1 self.ybin = 2 self.sx = self.sx / self.xbin self.xy = self.sy / self.ybin # -- update sliders to double sliders: geom = self.ui.SB1Slider.geometry() self.ui.SB1Slider = QxtSpanSlider(self.ui.centralWidget) self.ui.SB1Slider.setGeometry(geom) #self.ui.SB1Slider.setOrientation(QtCore.Qt.Horizontal) """ self.SB1Slider = QxtSpanSlider(self.centralWidget) self.SB1Slider.setGeometry(QtCore.QRect(1100, 520, 160, 23)) self.SB1Slider.setOrientation(QtCore.Qt.Horizontal) self.SB1Slider.setObjectName(_fromUtf8("SB1Slider")) """ if (self.spup): self.ui.SB1Slider.setRange(0, 132) #*** self.ui.SB1Slider.setSpan(80, 120) #*** else: self.ui.SB1Slider.setRange(0, 132) self.ui.SB1Slider.setSpan(80, 120) # -- geom = self.ui.SB2Slider.geometry() self.ui.SB2Slider = QxtSpanSlider(self.ui.centralWidget) self.ui.SB2Slider.setGeometry(geom) #self.ui.SB1Slider.setOrientation(QtCore.Qt.Horizontal) """ self.SB1Slider = QxtSpanSlider(self.centralWidget) self.SB1Slider.setGeometry(QtCore.QRect(1100, 520, 160, 23)) self.SB1Slider.setOrientation(QtCore.Qt.Horizontal) self.SB1Slider.setObjectName(_fromUtf8("SB1Slider")) """ if (self.spup): self.ui.SB2Slider.setRange(0, 132) #*** self.ui.SB2Slider.setSpan(50, 10) #*** else: self.ui.SB2Slider.setRange(0, 132) self.ui.SB2Slider.setSpan(50, 10) geom = self.ui.extractWinSlider.geometry() self.ui.extractWinSlider = QxtSpanSlider(self.ui.centralWidget) self.ui.extractWinSlider.setGeometry(geom) """ self.extractWin_x0=self.ui.extractWinSlider.lowerValue self.extractWin_x1=self.ui.extractWinSlider.upperValue self.SB1_x0=self.ui.SB1Slider.lowerValue self.SB1_x1=self.ui.SB1Slider.upperValue self.SB2_x0=self.ui.SB2Slider.lowerValue self.SB2_x1=self.ui.SB2Slider.upperValue """ # self.mklog() self.ui.lineEditz0.setText('0.') self.ui.lineEditz1.setText('10000.') self.extractionUnits = '' # header keyword: if (self.spup): self.imtype = 'EXPTYPE' self.sciKW = 'SCIENCE' # keyword for science # self.arcKW='arc' self.arcKW = 'ARC' else: self.imtype = 'IMAGETYP' self.sciKW = 'object' # keyword for science self.arcKW = 'COMPARISON' pars = {} pars['smoothPix'] = 0 pars['SkySub'] = False pars['useSB1'] = True pars['useSB2'] = True pars['LockDisplays'] = False # pars['showExtWin'] = True # pars['showSideBands'] = True # pars['dataDir'] = '/home/gilbank/Proj/CassSpect/data/Deatrick/' # pars['dataDir'] = '/home/ccd/cassspectr/cassspectr/' try: f = open('/home/ccd/.spup/datadir.json', 'r') datadir = json.load(f) pars['dataDir'] = datadir f.close() except ValueError as V: print '%s\ncould not open datadir.json' % V self.showDialogSetDatadir() except: self.showDialogSetDatadir() # pars['outDataDir'] = '/home/ccd/cassspectr/cassspectr/' pars['outDataDir'] = pars['dataDir'] pars['currFrame'] = 'none' pars['obsType'] = 'none' pars['currArc'] = 'none' pars['currFlat'] = 'none' pars['currFluxCal'] = 'none' pars['currBias'] = 'none' pars['scaling'] = 'ZScale' pars['z0'] = np.NAN pars['z1'] = np.NAN if (self.spup): pars['extractWin_x0'] = 120.0 #** pars['extractWin_x1'] = 140.0 #** else: pars['extractWin_x0'] = 50.0 pars['extractWin_x1'] = 70.0 pars['SBoffset'] = 5 pars['SBwidth'] = 15 self.extractWin_x0 = pars['extractWin_x0'] self.extractWin_x1 = pars['extractWin_x1'] pars['autoExtraction'] = True # pars['isScience']=True self.pars = pars # check if qlsettings.json exists and, if so, reload: self.loadPars() # Decide extraction type: self.ui.lineEditDataDir.setText(self.pars['dataDir']) self.ui.lineEditOutDataDir.setText(self.pars['outDataDir']) # self.imagetype='science' self.imagetype = 'none' self.wlc = False # -- Initialise values: self.autoExtraction = True self.lamp = None self.grating = None 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.scaledImage = None # disable unimplemented options: # self.ui.useSB1Check.setEnabled(False) # self.ui.useSB2Check.setEnabled(False) self.ui.checkBoxLockDisplays.setEnabled(False) self.ui.checkBoxWrite1DFITS.setEnabled(False) self.ui.pushButCurrArc.setEnabled(False) # -- Connect signals and slots QtCore.QObject.connect(self.ui.actionQuit, QtCore.SIGNAL(_fromUtf8("activated()")), self.closeEvent) QtCore.QObject.connect(self.ui.pushButPan, QtCore.SIGNAL(_fromUtf8("pressed()")), self.doPanAll) QtCore.QObject.connect(self.ui.pushButZoom, QtCore.SIGNAL(_fromUtf8("pressed()")), self.doZoomAll) QtCore.QObject.connect(self.ui.pushButResetView, QtCore.SIGNAL(_fromUtf8("pressed()")), self.resetZoomAll) QtCore.QObject.connect(self.ui.pushButSmoothObj, QtCore.SIGNAL(_fromUtf8("pressed()")), self.display1D) QtCore.QObject.connect(self.ui.pushButNoSmooth, QtCore.SIGNAL(_fromUtf8("pressed()")), self.noSmoothing) QtCore.QObject.connect(self.ui.pushButCurrFrame, QtCore.SIGNAL(_fromUtf8("pressed()")), self.loadFrame) # QtCore.QObject.connect(self.ui.pushButCurrFrame, QtCore.SIGNAL(_fromUtf8("pressed()")), self.loadAndUpdate) QtCore.QObject.connect(self.ui.checkBoxShowExtractWin, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.display2D) QtCore.QObject.connect(self.ui.checkBoxShowSB, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.display2D) QtCore.QObject.connect(self.ui.zScaleUpdateBut, QtCore.SIGNAL(_fromUtf8("clicked()")), self.updatezScaling) QtCore.QObject.connect(self.ui.pushButAutoExtract, QtCore.SIGNAL(_fromUtf8("clicked()")), self.updateAutoExtraction) # QtCore.QObject.connect(self.ui.useSB1Check, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.updateAll) QtCore.QObject.connect(self.ui.useSB1Check, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.sideBandToggled) QtCore.QObject.connect(self.ui.useSB2Check, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.sideBandToggled) # QtCore.QObject.connect(self.ui.useSB2Check, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.updateAll) QtCore.QObject.connect(self.ui.SB1Slider, QtCore.SIGNAL(_fromUtf8("sliderReleased()")), self.readExtractionSliders) QtCore.QObject.connect(self.ui.SB2Slider, QtCore.SIGNAL(_fromUtf8("sliderReleased()")), self.readExtractionSliders) QtCore.QObject.connect(self.ui.extractWinSlider, QtCore.SIGNAL(_fromUtf8("sliderReleased()")), self.readExtractionSliders) QtCore.QObject.connect( self.ui.comboBoxColorMap, QtCore.SIGNAL(_fromUtf8("currentIndexChanged(int)")), self.display2D) QtCore.QObject.connect(self.ui.pushButChooseDataDir, QtCore.SIGNAL(_fromUtf8("clicked()")), self.showDialogSetDatadir) QtCore.QObject.connect(self.ui.pushButChooseOutDataDir, QtCore.SIGNAL(_fromUtf8("pressed()")), self.showDialogSetOutDatadir) QtCore.QObject.connect(self.ui.pushButCurrFrameBrowse, QtCore.SIGNAL(_fromUtf8("pressed()")), self.showDialogSetCurrFrame) QtCore.QObject.connect(self.ui.pushButIgnoreWLC, QtCore.SIGNAL(_fromUtf8("clicked()")), self.ignoreWLC) # QtCore.QObject.connect(self.ui.pushButIgnoreWLC, QtCore.SIGNAL(_fromUtf8("clicked()")), self.ignoreWLC) QtCore.QObject.connect(self.ui.pushButIgnoreWLClibArc, QtCore.SIGNAL(_fromUtf8("clicked()")), self.useLibArc) QtCore.QObject.connect(self.ui.useSB1Check, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.updateAll) QtCore.QObject.connect(self.ui.useSB2Check, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.updateAll) # QtCore.QObject.connect(self.ui.raw2DGraph,QtCore.SIGNAL("MOUSE_MOVED"),self.display2Dlabel) QtCore.QObject.connect(self.ui.raw2DGraph, QtCore.SIGNAL(_fromUtf8("enterEvent()")), self.display2Dlabel) # ---- Set up logging # see: https://docs.python.org/2/howto/logging-cookbook.html logfile = 'QL%s.log' % (time.strftime("%Y%m%d", time.gmtime())) logging.basicConfig(filename=logfile, level=logging.DEBUG, format='%(asctime)s %(message)s') # logFormatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s', datefmt='%m-%d %H:%M:%S') logFormatter = logging.Formatter( '%(asctime)s %(levelname)-8s %(message)s', datefmt='%H:%M:%S') self.logBuffer = logBuffer() self.logBuffer.bufferMessage.connect(self.on_logBuffer_bufferMessage) ### logFormatter = logging.Formatter('%(levelname)s: %(message)s') logHandler = logging.StreamHandler(self.logBuffer) logHandler.setFormatter(logFormatter) # add some colours: # logging.addLevelName( logging.WARNING, "\033[1;31m%s\033[1;0m" % logging.getLevelName(logging.WARNING)) # logging.addLevelName( logging.ERROR, "\033[1;41m%s\033[1;0m" % logging.getLevelName(logging.ERROR)) # logging.addLevelName( logging.INFO, "\x1b[31m%s" % logging.getLevelName(logging.INFO)) #** self.logger = logging.getLogger() self.logger.setLevel(logging.INFO) self.logger.addHandler(logHandler) self.logtext = '' #self.ui.scrollAreaWidgetContents = QtGui.QTextEdit() self.logger.info('GUI started') self.makeDummy() #-- Monitor data directory for new images wm = WatchManager() notifier = ThreadedNotifier(wm, self.process_IN_CREATE) notifier.start() self.notifier = notifier mask = EventsCodes.ALL_FLAGS['IN_CREATE'] wdd = wm.add_watch(self.pars['dataDir'], mask, rec=False) #-- # read values from GUI: self.pars['showSideBands'] = self.ui.checkBoxShowSB.isChecked() self.pars['smoothPix'] = self.ui.spinBoxSmoothWidth.value() self.logger.debug(self.ui.checkBoxShowSB.isChecked()) # self.profileGraph = matplotlibWidgetwBar(self.centralWidget) # self.profPlot = matplotlibWidget(self.ui.centralWidget) ### sc = matplotlibWidgetwBar(self.ui.profileGraph) # **** clunky, but effective! #profWin = matplotlibWidgetwBar(self.ui.centralWidget) profWin = matplotlibWidget(self.ui.centralWidget) #self.profPlot.setGeometry(QtCore.QRect(1100, 140, 330, 271)) self.profWin = profWin # imname = 'a3000134.fits' # self.logger.info(imname) # self.image = self.pars['dataDir']+imname # data2D,hdr = fits.getdata(self.image, header=True) # self.data2D = data2D # self.pars['currFrame'] = imname # self.pars['obsType'] = hdr[self.imtype] # print self.pars['obsType'] # self.ui.lineEditCurrFrame.setText(pars['currFrame']) self.plotProfile() #self.profWin.mpl_toolbar.zoom() #graph2D = matplotlibWidget(self.ui.centralWidget) graph2D = matplotlibWidgetwBar(self.ui.centralWidget) self.graph2D = graph2D self.display2D() specWin = matplotlibWidget(self.ui.centralWidget) self.specWin = specWin # self.logger.debug('**',self.sky1d) self.display1D() """
def run(): if not client_status.is_registered: print 'Sending info about new client...' status, content = api.hi(platform.uname()) print content if status == 200: client_status.is_registered = True client_status.save() else: exit('Aborted') if os.path.exists(CRASH_PATH): crash = os.stat(CRASH_PATH) if crash.st_size: with open(CRASH_PATH) as f: crash_info = f.read() status = api.report_crash(crash_info, crash.st_mtime) if status == 200: log.info('Crash reported') os.remove(CRASH_PATH) context = DaemonContext(pidfile=PIDLockFile(PIDFILE_PATH), signal_map={signal.SIGTERM: on_stop}, stderr=open(CRASH_PATH, 'w')) context.files_preserve = map( lambda h: h.stream, filter(lambda h: isinstance(h, FileHandler), log.logger.handlers)) print 'Starting daemon' with context: log.info('Daemon started') log.info('Build filesystem image') basepath = '/' root = FSNode(basepath, ignore=IGNORE_PATHS) root_d = root.as_dict() root_str = json.dumps(root_d) h = sha(root_str).hexdigest() if not client_status.fshash or client_status.fshash != h: status, content = api.set_fs(root_str) if status == 200: client_status.fshash = h client_status.save() log.info('Filesystem image updated') else: log.error('Filesystem image update failed') log.info('Create watch manager') wm = WatchManager() changelog = [] global notifier notifier = ThreadedNotifier(wm, FSEvent(changelog=changelog)) notifier.start() mask = IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO log.info('Start watching filesystem changes') for item in os.listdir(basepath): path = os.path.join(basepath, item) if item in IGNORE_PATHS or os.path.islink(path): continue wm.add_watch(path, mask, rec=True) actions = [ Action(FS_UPLOAD_PERIOD, upload_fs, changelog), Action(LOG_UPLOAD_PERIOD, upload_log), Action(RESTORE_CHECK_PERIOD, restore) ] backup_action = lambda: Action(backup.get_next(), make_backup) def on_schedule_update(actions=actions): actions[-1] = backup_action() update_schedule_action = lambda: Action(SCHEDULE_UPDATE_PERIOD, update_schedule, on_update=on_schedule_update) if update_schedule() or client_status.schedule: actions.append(update_schedule_action()) actions.append(backup_action()) else: def on_schedule_download(actions=actions): actions[-1] = update_schedule_action() actions.append(backup_action()) actions.append( Action(SCHEDULE_UPDATE_PERIOD, update_schedule, on_update=on_schedule_download, on_404=True)) log.info('Start main loop') while True: action = min(actions) log.info('Next action is %s' % action) time.sleep(action.time_left()) action()
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)
inputDir, outputDir, passphrase, watch, remove) print '===================' else: print 'ERROR: input/output directory or key file does not exist!' exit(1) logging.basicConfig(filename=os.path.join(outputDir, 'fswalk_anonymizer.log'), level=logging.DEBUG) if threads == None: threads = 1 if watch: # set up a directory watch wm = WatchManager() mask = pyinotify.IN_CLOSE_WRITE notifier = ThreadedNotifier(wm, FileCloseCb()) notifier.start() wdd = wm.add_watch(inputDir, mask, rec=False) # process user input run = True print 'Type "QUIT" to exit' while (run): command = raw_input("> ") if command == 'QUIT': run = False notifier.stop() else: # anonymize all files in the inputDir for f in os.listdir(inputDir): if f.endswith(".ds"): while threading.active_count() > threads:
def watch(self): if wm is not None: self.notifier = ThreadedNotifier(wm, ProcessEvents(self)) self.notifier.start() self.wdd = wm.add_watch(os.path.abspath('src'), mask, rec=True)
def __init__(self, logger): self.logger = logger self.notifier = ThreadedNotifier( self._wm, PaperProcesser(self.logger, self.paper_queue))
# -*- coding: utf-8 -*- # ThreadedNotifier example from tutorial # # See: http://trac.dbzteam.org/pyinotify/wiki/Tutorial # from pyinotify import WatchManager, Notifier, \ ThreadedNotifier, ProcessEvent, IN_DELETE, \ IN_CREATE, log, IN_MODIFY wm = WatchManager() # Watch Manager # mask = IN_DELETE | IN_CREATE # watched events mask = IN_MODIFY class PTmp(ProcessEvent): def process_IN_MODIFY(self, event): print "Modified:", event.pathname # def process_IN_DELETE(self, event): # print "Removing:", event.pathname # log.setLevel(10) notifier = ThreadedNotifier(wm, PTmp()) notifier.start() wdd = wm.add_watch('/tmp', mask, rec=True) # wm.rm_watch(wdd.values()) # notifier.stop()