# HG changeset patch
# User Tero Marttila
# Date 1234227436 -7200
# Node ID 43ac75054d5c73dfbd3be53be42aec2d326a4280
# Parent 85345abbd46ac57cd404ce74f787fb89d5b94c10
image formatting \o/
diff -r 85345abbd46a -r 43ac75054d5c config.py
--- a/config.py Tue Feb 10 01:24:59 2009 +0200
+++ b/config.py Tue Feb 10 02:57:16 2009 +0200
@@ -13,23 +13,27 @@
# build relative paths
relpath = lambda path : os.path.join(os.path.dirname(__file__), path)
+### ###
+### Configuration ###
+### ###
+
# timezone to use for logs
-LOG_TIMEZONE = pytz.timezone('Europe/Helsinki')
+LOG_TIMEZONE = pytz.timezone('Europe/Helsinki')
# timestamp format for logfiles
-LOG_TIMESTAMP_FMT = '%H:%M:%S'
+LOG_TIMESTAMP_FMT = '%H:%M:%S'
# character set used for logfiles
-LOG_CHARSET = 'utf-8'
+LOG_CHARSET = 'utf-8'
# log filename format
-LOG_FILENAME_FMT = '%Y-%m-%d'
+LOG_FILENAME_FMT = '%Y-%m-%d'
# the log parser that we use
-LOG_PARSER = IrssiParser(LOG_TIMEZONE, LOG_TIMESTAMP_FMT)
+LOG_PARSER = IrssiParser(LOG_TIMEZONE, LOG_TIMESTAMP_FMT)
# the statically defined channel list
-LOG_CHANNELS = ChannelList([
+LOG_CHANNELS = ChannelList([
LogChannel('tycoon', "OFTC", "#tycoon",
LogDirectory(relpath('logs/tycoon'), LOG_TIMEZONE, LOG_PARSER, LOG_CHARSET, LOG_FILENAME_FMT)
),
@@ -40,27 +44,39 @@
])
# date format for URLs
-URL_DATE_FMT = '%Y-%m-%d'
+URL_DATE_FMT = '%Y-%m-%d'
# month name format
-MONTH_FMT = '%B %Y'
+MONTH_FMT = '%B %Y'
# timezone name format
-TIMEZONE_FMT = '%Z %z'
+TIMEZONE_FMT = '%Z %z'
+
+# TTF fonts to use for drawing images
+FORMATTER_IMAGE_FONTS = {
+ 'default': (None, "Ugly default font" ),
+ 'ttf-dejavu-mono': ("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf", "DejaVu Sans Mono" ),
+ 'ttf-liberation-mono': ("/usr/share/fonts/truetype/ttf-liberation/LiberationMono-Regular.ttf", "Liberation Mono Regular" )
+}
# available formatters
-LOG_FORMATTERS = log_formatter.FORMATTERS
+LOG_FORMATTERS = {
+ 'irssi': IrssiFormatter,
+}
# default preferences
-PREF_TIME_FMT_DEFAULT = '%H:%M:%S'
-PREF_DATE_FMT_DEFAULT = '%Y-%m-%d'
-PREF_TIMEZONE_DEFAULT = pytz.utc
-PREF_FORMATTER_DEFAULT = IrssiFormatter
-PREF_COUNT_DEFAULT = 200
-PREF_COUNT_MAX = None
+PREF_TIME_FMT_DEFAULT = '%H:%M:%S'
+PREF_DATE_FMT_DEFAULT = '%Y-%m-%d'
+PREF_TIMEZONE_DEFAULT = pytz.utc
+PREF_FORMATTER_DEFAULT = IrssiFormatter
+PREF_COUNT_DEFAULT = 200
+PREF_COUNT_MAX = None
+PREF_IMAGE_FONT_DEFAULT = 'default'
+PREF_IMAGE_FONT_SIZE_DEFAULT = 10
+PREF_IMAGE_FONT_SIZE_MAX = 32
# search line count options
-SEARCH_LINE_COUNT_OPTIONS = (
+SEARCH_LINE_COUNT_OPTIONS = (
(50, 50),
(100, 100),
(200, 200),
diff -r 85345abbd46a -r 43ac75054d5c handlers.py
--- a/handlers.py Tue Feb 10 01:24:59 2009 +0200
+++ b/handlers.py Tue Feb 10 02:57:16 2009 +0200
@@ -68,24 +68,44 @@
return http.Redirect(urls.channel.build(request, channel=channel))
@preferences.handler(prefs.formatter)
-def channel_last (request, channel, count, formatter) :
+def channel_last (request, channel, count, formatter, type=None) :
"""
The main channel view page, displaying the most recent lines
"""
-
+
# get latest events
lines = channel.source.get_latest(count)
-
- # lines
- lines = formatter.format_html(lines)
+
+ # we can render in various modes...
+ if not type :
+ # normal HTML
+ lines = formatter.format_html(lines)
- return templates.render_to_response("channel_last",
- req = request,
- prefs = request.prefs,
- channel = channel,
- count = count,
- lines = lines,
- )
+ return templates.render_to_response("channel_last",
+ req = request,
+ prefs = request.prefs,
+ channel = channel,
+ count = count,
+ lines = lines,
+ )
+
+ elif type == 'txt' :
+ # plaintext
+ lines = formatter.format_txt(lines)
+
+ # build data
+ data = '\n'.join(data for line, data in lines)
+
+ return http.Response(data, 'text/plain')
+
+ elif type == 'png' :
+ # PNG image
+ png_data = formatter.format_png(lines)
+
+ return http.Response(png_data, 'image/png', charset=None)
+
+ else :
+ raise http.ResponseError("Unrecognized type: %r" % (type, ))
@preferences.handler(prefs.formatter, prefs.timezone, prefs.count)
def channel_link (request, channel, timestamp, formatter, timezone, count) :
diff -r 85345abbd46a -r 43ac75054d5c helpers.py
--- a/helpers.py Tue Feb 10 01:24:59 2009 +0200
+++ b/helpers.py Tue Feb 10 02:57:16 2009 +0200
@@ -187,4 +187,17 @@
"""
return max(values)
+
+ def select_options (self, key_values, selected_key) :
+ """
+ Render a series of
+
+
diff -r 85345abbd46a -r 43ac75054d5c urls.py
--- a/urls.py Tue Feb 10 01:24:59 2009 +0200
+++ b/urls.py Tue Feb 10 02:57:16 2009 +0200
@@ -35,7 +35,7 @@
preferences = url('/preferences', handlers.preferences_ )
channel_select = url('/channel_select/?channel:cid', handlers.channel_select )
channel = url('/channels/{channel:cid}', handlers.channel_last, count=20 )
-channel_last = url('/channels/{channel:cid}/last/{count:int=100}', handlers.channel_last )
+channel_last = url('/channels/{channel:cid}/last/{count:int=100}/{type=}', handlers.channel_last )
channel_link = url('/channels/{channel:cid}/link/{timestamp:ts}', handlers.channel_link )
channel_calendar = url('/channels/{channel:cid}/calendar/{year:int=0}/{month:int=0}', handlers.channel_calendar )
channel_date = url('/channels/{channel:cid}/date/{date:date}/?page:int=1', handlers.channel_date )