def get_search_results(self, req, terms, filters): # cache perm checks to speed things up permcache = {} chmgr = IRCChannelManager(self.env) if not 'irclogs' in filters: return #logview = web_ui.IrcLogsView(self.env) for result in self.search(terms): dt_str = '' if result.get('timestamp'): dt = chmgr.to_user_tz(req, result['timestamp']) d_str = "%04d/%02d/%02d" % ( dt.year, dt.month, dt.day, ) t_str = "%02d:%02d:%02d" % (dt.hour, dt.minute, dt.second) channel = '' if result.get('channel'): channel = '%s/' % result['channel'] url = '/irclogs/%s%s' % (channel, d_str) if not permcache.has_key(channel): chobj = chmgr.channel(result['channel']) permcache[channel] = req.perm.has_permission(chobj.perm()) if permcache[channel]: yield "%s#%s"%(req.href(url), t_str), \ 'irclogs for %s'%result['channel'], dt, \ 'irclog', result['content']
def get_search_results(self, req, terms, filters): # cache perm checks to speed things up permcache = {} chmgr = IRCChannelManager(self.env) if not 'irclogs' in filters: return #logview = web_ui.IrcLogsView(self.env) for result in self.search(terms): dt_str = '' if result.get('timestamp'): dt = chmgr.to_user_tz(req, result['timestamp']) d_str = "%04d/%02d/%02d"%( dt.year, dt.month, dt.day, ) t_str = "%02d:%02d:%02d"%( dt.hour, dt.minute, dt.second ) channel = '' if result.get('channel'): channel = '%s/'%result['channel'] url = '/irclogs/%s%s'%(channel, d_str) if not permcache.has_key(channel): chobj = chmgr.channel(result['channel']) permcache[channel] = req.perm.has_permission(chobj.perm()) if permcache[channel]: yield "%s#%s"%(req.href(url), t_str), \ 'irclogs for %s'%result['channel'], dt, \ 'irclog', result['content']
def update_index(self): last_index_dt = UTC.localize( datetime(*gmtime(self.last_index)[:6])) now = UTC.localize(datetime.utcnow()) idx = self.get_index() writer = idx.writer() try: chmgr = IRCChannelManager(self.env) for channel in chmgr.channels(): for line in channel.events_in_range(last_index_dt, now): if line['type'] == 'comment': content = "<%s> %s" % (line['nick'], line['comment']) writer.add_document( channel=channel.name(), timestamp=line['timestamp'].strftime( self.TIMESTAMP_FORMAT), content=content) if line['type'] == 'action': content = "* %s %s" % (line['nick'], line['action']) writer.add_document( channel=channel.name(), timestamp=line['timestamp'].strftime( self.TIMESTAMP_FORMAT), content=content) # START BULLSHIT # Python can't turn a nonlocal datetime to a epoch time AFIACT # This pisses me off to no end. Who knows what kind of f****d # up side effects this has. os.environ['TZ'] = 'UTC' tzset() # END BULLSHIT epoch_now = int(mktime(now.timetuple())) self.config['irclogs'].set('last_index', epoch_now) self.config.save() writer.commit() idx.close() except Exception, e: writer.cancel() idx.close() raise e
def update_index(self): last_index_dt = UTC.localize(datetime(*gmtime(self.last_index)[:6])) now = UTC.localize(datetime.utcnow()) idx = self.get_index() writer = idx.writer() try: chmgr = IRCChannelManager(self.env) for channel in chmgr.channels(): for line in channel.events_in_range(last_index_dt, now): if line['type'] == 'comment': content = "<%s> %s"%(line['nick'], line['comment']) writer.add_document( channel=channel.name(), timestamp=line['timestamp'].strftime( self.TIMESTAMP_FORMAT), content=content ) if line['type'] == 'action': content = "* %s %s"%(line['nick'], line['action']) writer.add_document( channel=channel.name(), timestamp=line['timestamp'].strftime( self.TIMESTAMP_FORMAT), content=content ) # START BULLSHIT # Python can't turn a nonlocal datetime to a epoch time AFIACT # This pisses me off to no end. Who knows what kind of f****d # up side effects this has. os.environ['TZ'] = 'UTC' tzset() # END BULLSHIT epoch_now = int(mktime(now.timetuple())) self.config['irclogs'].set('last_index', epoch_now) self.config.save() writer.commit() idx.close() except Exception, e: writer.cancel() idx.close() raise e
def search(self, terms): chmgr = IRCChannelManager(self.env) ix = self.get_index() searcher = ix.searcher() parsed_terms = self.PARSER.parse(' or '.join(terms)) if terms: for f in searcher.search(parsed_terms): timestamp = strptime(f['timestamp'], self.TIMESTAMP_FORMAT) f['timestamp'] = \ UTC.localize(datetime(*timestamp[:6])) yield f
def get_search_filters(self, req): ch_mgr = IRCChannelManager(self.env) for channel in ch_mgr.channels(): if req.perm.has_permission(channel.perm()): return [('irclogs', 'IRC Logs', True)] return []