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:
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
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() print "pending: ", ret if ret > 0: ret = mon.handle_one_event() ; print "processed %d event" % (ret) ; if ret == 1 : print "alteracoes:" s = f.readline() ; while s : print s ; s = f.readline() ; ret = mon.handle_events() print "processed %d remaining events" % (ret) print file ; print '--------------------------------------------------------------------------' finally: f.close() ; #log.close() ; del mon ; print 'fim'