import os import re from datetime import datetime from trac.web.chrome import add_stylesheet, add_script, Chrome from trac.wiki.macros import WikiMacroBase from trac.wiki.formatter import system_message from trac.wiki.api import parse_args from web_ui import IrcLogsView class IrcLogLiveMacro(WikiMacroBase): """Displays a live in-page feed of the current IRC log. Can take 2 parameters: * polling frequency (seconds) default to 60 * number of messages displayed - defaults to 10 """ def expand_macro(self, formatter, name, content): args, kw = parse_args(content) poll_frequency = args and args[0] or 60 count = args and args[1] or 10 if not (0==len(args) or 2==len(args)): return system_message('Incorrect arguments: ' 'Must be of the format (poll frequency, lines to display)') add_stylesheet(formatter.req, 'irclogs/style.css') add_script(formatter.req, 'irclogs/jquery.timer.js') data = Chrome(self.env).populate_data(formatter.req, {'poll_frequency':int(poll_frequency)*1000, 'count':count}) return Chrome(self.env).load_template('macro_live.html') \ .generate(**data) class IrcLogQuoteMacro(WikiMacroBase): """Display contents of a logged IRC chat. Takes parameters of the UTC timestamp of the message and the number of messages to show. `[[IrcLogsQuote(UTCYYYY-MM-DDTHH:MM:SS,message_count]])` To get the UTC timestamp, click on the time displayed in the IRC log view page and copy the anchor from your browsers location bar. """ date_re = re.compile(r'^UTC(?P\d{4})-(?P\d{2})-(?P\d{2})' 'T(?P