def start(self): """ The Gamin watch monitor in :attr:`mon` must be created by the daemonized process, so is created in ``start()``. Before the :class:`Gamin.WatchMonitor` object is created, monitors are added to :attr:`add_q`, and are created once the watch monitor is created.""" FileMonitor.start(self) self.mon = WatchMonitor() for monitor in self.add_q: self.AddMonitor(*monitor) self.add_q = []
def __init__(self): if GaminAvailable: self.__monitor = WatchMonitor() else: self.__monitor = None self.__pollCntr = 0
class Gamin(FileMonitor): """ File monitor backend with `Gamin <http://people.gnome.org/~veillard/gamin/>`_ support. **Deprecated.** """ #: The Gamin backend is deprecated, but better than pseudo, so it #: has a medium priority. __priority__ = 50 def __init__(self): FileMonitor.__init__(self) #: The :class:`Gamin.WatchMonitor` object for this monitor. self.mon = None #: The counter used to produce monotonically increasing #: monitor handle IDs self.counter = 0 #: The queue used to record monitors that are added before #: :func:`start` has been called and :attr:`mon` is created. self.add_q = [] self.logger.warning("The Gamin file monitor backend is deprecated. " "Please switch to a supported file monitor.") __init__.__doc__ = FileMonitor.__init__.__doc__ def start(self): """ The Gamin watch monitor in :attr:`mon` must be created by the daemonized process, so is created in ``start()``. Before the :class:`Gamin.WatchMonitor` object is created, monitors are added to :attr:`add_q`, and are created once the watch monitor is created.""" FileMonitor.start(self) self.mon = WatchMonitor() for monitor in self.add_q: self.AddMonitor(*monitor) self.add_q = [] def fileno(self): if self.started: return self.mon.get_fd() else: return None fileno.__doc__ = FileMonitor.fileno.__doc__ def queue(self, path, action, request_id): """ Create a new :class:`GaminEvent` and add it to the :attr:`events` queue for later handling. """ self.events.append(GaminEvent(request_id, path, action)) def AddMonitor(self, path, obj, handle=None): if handle is None: handle = self.counter self.counter += 1 if not self.started: self.add_q.append((path, obj, handle)) return handle mode = os.stat(path)[stat.ST_MODE] # Flush queued gamin events while self.mon.event_pending(): self.mon.handle_one_event() if stat.S_ISDIR(mode): self.mon.watch_directory(path, self.queue, handle) else: self.mon.watch_file(path, self.queue, handle) self.handles[handle] = obj return handle AddMonitor.__doc__ = FileMonitor.AddMonitor.__doc__ def pending(self): return FileMonitor.pending(self) or self.mon.event_pending() pending.__doc__ = FileMonitor.pending.__doc__ def get_event(self): if self.mon.event_pending(): self.mon.handle_one_event() return FileMonitor.get_event(self) get_event.__doc__ = FileMonitor.get_event.__doc__
def __init__(self, debug=False): FileMonitor.__init__(self, debug) self.mon = WatchMonitor() self.counter = 0 self.events = []
class Gamin(FileMonitor): """ The fam object is a set of callbacks for file alteration events (Gamin support) """ def __init__(self, debug=False): FileMonitor.__init__(self, debug) self.mon = WatchMonitor() self.counter = 0 self.events = [] def fileno(self): return self.mon.get_fd() def queue(self, path, action, request_id): """queue up the event for later handling""" self.events.append(GaminEvent(request_id, path, action)) def AddMonitor(self, path, obj): """Add a monitor to path, installing a callback to obj.HandleEvent.""" handle = self.counter self.counter += 1 mode = os.stat(path)[stat.ST_MODE] # Flush queued gamin events while self.mon.event_pending(): self.mon.handle_one_event() if stat.S_ISDIR(mode): self.mon.watch_directory(path, self.queue, handle) else: self.mon.watch_file(path, self.queue, handle) self.handles[handle] = obj return handle def pending(self): return len(self.events) > 0 or self.mon.event_pending() def get_event(self): if self.mon.event_pending(): self.mon.handle_one_event() return self.events.pop(0)
def __init__(self, ignore=None, debug=False): FileMonitor.__init__(self, ignore=ignore, debug=debug) self.mon = WatchMonitor() self.counter = 0
class Gamin(FileMonitor): __priority__ = 10 def __init__(self, ignore=None, debug=False): FileMonitor.__init__(self, ignore=ignore, debug=debug) self.mon = WatchMonitor() self.counter = 0 def fileno(self): return self.mon.get_fd() def queue(self, path, action, request_id): """queue up the event for later handling""" self.events.append(GaminEvent(request_id, path, action)) def AddMonitor(self, path, obj): """Add a monitor to path, installing a callback to obj.""" handle = self.counter self.counter += 1 mode = os.stat(path)[stat.ST_MODE] # Flush queued gamin events while self.mon.event_pending(): self.mon.handle_one_event() if stat.S_ISDIR(mode): self.mon.watch_directory(path, self.queue, handle) else: self.mon.watch_file(path, self.queue, handle) self.handles[handle] = obj return handle def pending(self): return FileMonitor.pending(self) or self.mon.event_pending() def get_event(self): if self.mon.event_pending(): self.mon.handle_one_event() return FileMonitor.get_event(self)
def monitor(path, event): if event == GAMExists: g.readlines() if event == GAMChanged: ultimasL=g.readlines() for l in ultimasL: dfields = logfields(l) if logfilter(dfields, dfilters): if opts.filtrables: sys.stderr.write(l[:24]+" "+l.split()[6]+" "+l.split()[8]+" "+l.split()[13]+"\n") elif opts.completo: sys.stderr.write(l) return True mon = WatchMonitor() mon.watch_file(opts.logfile, monitor) time.sleep(1) fd = mon.get_fd() while True: select([fd],[],[]) if mon.event_pending(): mon.handle_events() mon.stop_watch(fichero) del mon #para probarlo abro otra terminal y hago echo "xxxx" >> vsftpd.log #Si quiero meter varias lineas en bloque hago echo "xxxx" >> vsftpd.log && echo "yyyyy" >> vsftpd.log
#INICIO DEL PROGRAMA opts, args = proc_opts() preparaInt(opts.directorio) d = dbm.open(opts.hashfile, "r") def monitor(fichero, event): if event == GAMChanged: if d.has_key(os.path.join(opts.directorio, fichero)): if d[os.path.join(opts.directorio, fichero)] != funcHash( os.path.join(opts.directorio, fichero)): print "Ha cambiado el contenido de " + fichero + " el " + time.strftime( "%d/%b/%Y - %H:%M:%S") else: None return True if __name__ == "__main__": mon = WatchMonitor() mon.watch_directory(opts.directorio, monitor) time.sleep(1) fd = mon.get_fd() while True: select([fd], [], []) if mon.event_pending(): mon.handle_events() mon.stop_watch(fichero) del mon
def start(self): FileMonitor.start(self) self.mon = WatchMonitor() for monitor in self.add_q: self.AddMonitor(*monitor) self.add_q = []
class Gamin(FileMonitor): """ file monitor with gamin support """ __priority__ = 10 def __init__(self, ignore=None, debug=False): FileMonitor.__init__(self, ignore=ignore, debug=debug) self.mon = None self.counter = 0 self.add_q = [] def start(self): FileMonitor.start(self) self.mon = WatchMonitor() for monitor in self.add_q: self.AddMonitor(*monitor) self.add_q = [] def fileno(self): return self.mon.get_fd() def queue(self, path, action, request_id): """queue up the event for later handling""" self.events.append(GaminEvent(request_id, path, action)) def AddMonitor(self, path, obj, handle=None): """Add a monitor to path, installing a callback to obj.""" if handle is None: handle = self.counter self.counter += 1 if not self.started: self.add_q.append((path, obj, handle)) return handle mode = os.stat(path)[stat.ST_MODE] # Flush queued gamin events while self.mon.event_pending(): self.mon.handle_one_event() if stat.S_ISDIR(mode): self.mon.watch_directory(path, self.queue, handle) else: self.mon.watch_file(path, self.queue, handle) self.handles[handle] = obj return handle def pending(self): return FileMonitor.pending(self) or self.mon.event_pending() def get_event(self): if self.mon.event_pending(): self.mon.handle_one_event() return FileMonitor.get_event(self)
class iCalendarBackend: def __init__(self): if GaminAvailable: self.__monitor = WatchMonitor() else: self.__monitor = None self.__pollCntr = 0 def registerChangeCallback(self, func, uri): """ The change callback function takes 2 arguments: path and event. If we can't use gamin, we don't even care about the path - all we can do is report back when it's time to re-read the file and pretend that the file changed (since we don't really know if it did or not). """ if self.__monitor: self.__monitor.watch_file(uri, func) else: self.__changeCallback = func def pollForChanges(self): if self.__monitor: self.__monitor.handle_events() else: self.__pollCntr += 1 if self.__pollCntr == POLL_CYCLES: self.__changeCallback(None, FILE_CHANGED) self.__pollCntr = 0 # This function must be called again forever until it's removed return True def read(self, uri): return Calendar.from_string( open(uri, 'rb').read() ) def new(self, cal, uri, event): if not cal: print "creating new calendar" cal = Calendar() cal['prodid'] = myProduct.prodid cal['version'] = myProduct.version if uri == "" or uri == None: import os uri = os.path.join(os.path.expanduser("~"), ".gdesklets", "gdesklets-calendar" + os.extsep + "ics") print "creating new file %s" % uri # Add the event to the calendar cal.add_component(event) try: tmp_cal_string = cal.as_string() except ValueError, error: print "ValueError in %s: \"%s\"\n" % (uri, error) print "This is a python issue, but could be solved in the icalendar package." print "Work around it by removing the offending dates in %s ." % uri return else:
#!/usr/bin/env python from gamin import WatchMonitor from select import select ret = 'oi' if __name__ == '__main__': def callback(path, event , mon): print "Got callback: %s, %s" % (path, event) ; print mon mon = event mon = WatchMonitor() ; file = raw_input() ; mon.watch_file( file , callback , ret ) ; print ret ; print 'oi2' f = open( file ) ; #log = open("log",'w') ; F_read = mon.get_fd() ; s = f.readline() ; while s : print s ; s = f.readline() ; try: while True : (re, spi, spe) = select( [F_read] , [] , [] ); if re: ret = mon.event_pending()