Exemple #1
0
 def _format_link(self, formatter, ns, target, label):
    m = self.date_re.match(target)
    if not m:
        return system_message('Invalid IRC Log Link: '
                  'Must be of the format channel-UTCYYYY-MM-DDTHH:MM:SS %s')
    if not m.group('datetime'):
        return html.a(label, title=label, href=formatter.href.irclogs(
            m.group('channel')))
    else:
        ch_mgr = IRCChannelManager(self.env)
        t = strptime(m.group('datetime'), self.date_format)
        dt = UTC.localize(datetime(*t[:6]))
        dt = ch_mgr.to_user_tz(formatter.req, dt)
        timestr = dt.strftime(self.time_format)
        return html.a(label, title=label, href=formatter.href.irclogs(
                  m.group('channel'), '%02d'%dt.year, '%02d'%dt.month, 
                  '%02d'%dt.day,) + '#%s'%timestr)
    def expand_macro(self, formatter, name, content):
        _, kw = parse_args(content)
        channel_name = kw.get('channel')
        utc_dt = kw.get('datetime')
        if not utc_dt:
            return system_message('IrcLogQuote: arguments required '\
                '(channel=channel, datetime=timestamp(UTCYYYY-MM-DDTHH:MM:SS), '\
                'offset=seonds)')
        d = self.date_re.match(utc_dt.strip())
        if not d:
            return system_message('IrcLogQuote: Invalid timestamp format')
        offset = int(kw.get('offset', 10))

        irclogs = IrcLogsView(self.env)        
        ch_mgr = IRCChannelManager(self.env)
        start = datetime(*strptime(utc_dt, self.date_format)[:6])
        start = UTC.localize(start)
        start = ch_mgr.to_user_tz(formatter.req, start)
        end = start + timedelta(seconds=offset)
        channel = ch_mgr.channel(channel_name)
        formatter.req.perm.assert_permission(channel.perm())
        lines = channel.events_in_range(start, end)
        lines = filter(lambda x: not x.get('hidden'), 
                map(irclogs._map_lines, lines))
        rows = map(irclogs._render_line, lines)

        add_stylesheet(formatter.req, 'irclogs/css/irclogs.css')
        data = Chrome(self.env).populate_data(
            formatter.req, 
            {
                'channel': channel_name,
                'lines': lines,
                'year': '%04d'%(start.year),
                'month': '%02d'%(start.month),
                'day': '%02d'%(start.day),
                'time': start.strftime("%H:%M:%S"),
                'rows': rows
            }
        )
        return Chrome(self.env).load_template('macro_quote.html') \
                                    .generate(**data)
Exemple #3
0
    def expand_macro(self, formatter, name, content):
        _, kw = parse_args(content)
        channel_name = kw.get('channel')
        utc_dt = kw.get('datetime')
        if not utc_dt:
            return system_message('IrcLogQuote: arguments required '\
                '(channel=channel, datetime=timestamp(UTCYYYY-MM-DDTHH:MM:SS), '\
                'offset=seonds)')
        d = self.date_re.match(utc_dt.strip())
        if not d:
            return system_message('IrcLogQuote: Invalid timestamp format')
        offset = int(kw.get('offset', 10))

        irclogs = IrcLogsView(self.env)
        ch_mgr = IRCChannelManager(self.env)
        start = datetime(*strptime(utc_dt, self.date_format)[:6])
        start = UTC.localize(start)
        start = ch_mgr.to_user_tz(formatter.req, start)
        end = start + timedelta(seconds=offset)
        channel = ch_mgr.channel(channel_name)
        formatter.req.perm.assert_permission(channel.perm())
        lines = channel.events_in_range(start, end)
        lines = filter(lambda x: not x.get('hidden'),
                       map(irclogs._map_lines, lines))
        rows = map(irclogs._render_line, lines)

        add_stylesheet(formatter.req, 'irclogs/css/irclogs.css')
        data = Chrome(self.env).populate_data(
            formatter.req, {
                'channel': channel_name,
                'lines': lines,
                'year': '%04d' % (start.year),
                'month': '%02d' % (start.month),
                'day': '%02d' % (start.day),
                'time': start.strftime("%H:%M:%S"),
                'rows': rows
            })
        return Chrome(self.env).load_template('macro_quote.html') \
                                    .generate(**data)
Exemple #4
0
 def _format_link(self, formatter, ns, target, label):
     m = self.date_re.match(target)
     if not m:
         return system_message(
             'Invalid IRC Log Link: '
             'Must be of the format channel-UTCYYYY-MM-DDTHH:MM:SS %s')
     if not m.group('datetime'):
         return html.a(label,
                       title=label,
                       href=formatter.href.irclogs(m.group('channel')))
     else:
         ch_mgr = IRCChannelManager(self.env)
         t = strptime(m.group('datetime'), self.date_format)
         dt = UTC.localize(datetime(*t[:6]))
         dt = ch_mgr.to_user_tz(formatter.req, dt)
         timestr = dt.strftime(self.time_format)
         return html.a(label,
                       title=label,
                       href=formatter.href.irclogs(
                           m.group('channel'),
                           '%02d' % dt.year,
                           '%02d' % dt.month,
                           '%02d' % dt.day,
                       ) + '#%s' % timestr)
Exemple #5
0
class ApiTestCase(unittest.TestCase):
    def setUp(self):
        self.env = EnvironmentStub()
        self.config = self.env.config

        self.config.set('irclogs', 'provider', 'file1')
        self.config.set('irclogs', 'channel', '#test1')
        self.config.set('irclogs', 'network', 'network1')

        self.config.set('irclogs', 'channel.test2.channel', '#test2')
        self.config.set('irclogs', 'channel.test2.provider', 'file2')
        self.config.set('irclogs', 'channel.test2.network', 'network2')

        self.config.set('irclogs', 'channel.test3.channel', '#test3')

        self.config.set('irclogs', 'channel.test4.blah', 'blah')
        self.out = IRCChannelManager(self.env)

    def test_get_channel_by_name(self):
        c = self.out.channel('crap')
        self.assertEqual('file1', c.provider())
        self.assertEqual('#test1', c.channel())
        self.assertEqual('network1', c.network())
        self.assertEqual(None, c.name())

        c = self.out.channel(None)
        self.assertEqual('file1', c.provider())
        self.assertEqual('#test1', c.channel())
        self.assertEqual('network1', c.network())
        self.assertEqual(None, c.name())

        c = self.out.channel('test2')
        self.assertEqual('file2', c.provider())
        self.assertEqual('#test2', c.channel())
        self.assertEqual('network2', c.network())
        self.assertEqual('test2', c.name())

        c = self.out.channel('test3')
        self.assertEqual('file1', c.provider())
        self.assertEqual('#test3', c.channel())
        self.assertEqual('network1', c.network())
        self.assertEqual('test3', c.name())

        c = self.out.channel('test4')
        self.assertEqual('file1', c.provider())
        self.assertEqual('#test1', c.channel())
        self.assertEqual('network1', c.network())
        self.assertEqual('blah', c.settings()['blah'])
        self.assertEqual('test4', c.name())

    def test_user_tz(self):
        req = Mock(session={'tz': 'America/New_York'})
        self.assertEqual('America/New_York', req.session.get('tz'))
        dt = UTC.localize(datetime.today())
        udt = self.out.to_user_tz(req, dt)
        self.assertEqual('America/New_York', str(udt.tzinfo))

    def test_tz_conversion(self):
        NYC = timezone('America/New_York')
        nydt = NYC.localize(datetime(2009, 8, 15, 12, 0, 0), None)
        udt = UTC.normalize(nydt.astimezone(UTC))
        nydt2 = NYC.normalize(udt.astimezone(NYC))
        self.assertEqual(nydt, nydt2)