author | terom |
Wed, 30 Mar 2016 01:29:22 +0300 | |
changeset 153 | 47dbaa6b13b0 |
parent 144 | 35c4c56f1376 |
permissions | -rw-r--r-- |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
""" |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
Configureable defaults |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
""" |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
import os.path, pytz |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
from log_parser import IrssiParser |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
from log_channel import LogChannel |
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
81
diff
changeset
|
8 |
from log_source import LogSourceDecoder, LogDirectory |
86
645cf9c4441e
implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
9 |
from log_formatter import IrssiFormatter, DebugFormatter |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
from channels import ChannelList |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
11 |
import log_formatter |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
|
128
2a8a190f8aee
fix config.VERSION_LINK to use relpath('.')
Tero Marttila <terom@fixme.fi>
parents:
124
diff
changeset
|
13 |
# build relative paths to the dir containing this file |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
relpath = lambda path : os.path.join(os.path.dirname(__file__), path) |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
|
79 | 16 |
### ### |
17 |
### Configuration ### |
|
18 |
### ### |
|
19 |
||
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
20 |
# timezone to use for logs |
79 | 21 |
LOG_TIMEZONE = pytz.timezone('Europe/Helsinki') |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
22 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
23 |
# timestamp format for logfiles |
79 | 24 |
LOG_TIMESTAMP_FMT = '%H:%M:%S' |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
25 |
|
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
81
diff
changeset
|
26 |
# the decoder used for logfiles |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
81
diff
changeset
|
27 |
LOG_DECODER = LogSourceDecoder(( |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
81
diff
changeset
|
28 |
('utf-8', 'strict'), |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
81
diff
changeset
|
29 |
('latin-1', 'replace'), |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
81
diff
changeset
|
30 |
)) |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
31 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
32 |
# log filename format |
79 | 33 |
LOG_FILENAME_FMT = '%Y-%m-%d' |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
34 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
35 |
# the log parser that we use |
79 | 36 |
LOG_PARSER = IrssiParser(LOG_TIMEZONE, LOG_TIMESTAMP_FMT) |
121
86aebc9cb60b
some quickfixes to fix deployment errors
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
37 |
#LOG_PARSER_FULLTS = IrssiParser(LOG_TIMEZONE, '%Y%m%d%H%M%S') |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
38 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
39 |
# the statically defined channel list |
79 | 40 |
LOG_CHANNELS = ChannelList([ |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
41 |
LogChannel('tycoon', "OFTC", "#tycoon", |
121
86aebc9cb60b
some quickfixes to fix deployment errors
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
42 |
LogDirectory(relpath('/home/spbot/irclogs/tycoon'), LOG_TIMEZONE, LOG_PARSER, LOG_DECODER, LOG_FILENAME_FMT) |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
43 |
), |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
44 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
45 |
LogChannel('openttd', "OFTC", "#openttd", |
121
86aebc9cb60b
some quickfixes to fix deployment errors
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
46 |
LogDirectory(relpath('/home/spbot/irclogs/openttd'), LOG_TIMEZONE, LOG_PARSER, LOG_DECODER, LOG_FILENAME_FMT) |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
47 |
), |
81
745032a57803
add #test logfile, improve handling of low-logfile situations
Tero Marttila <terom@fixme.fi>
parents:
79
diff
changeset
|
48 |
|
153 | 49 |
LogChannel('tempire', "OFTC", "#transportempire", |
50 |
LogDirectory(relpath('/home/spbot/irclogs/tempire'), LOG_TIMEZONE, LOG_PARSER, LOG_DECODER, LOG_FILENAME_FMT) |
|
51 |
), |
|
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
52 |
]) |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
53 |
|
131
67f5d2fdca1d
rename config.PREF_TIMEZONE_FALLBACK, add Cookie expire/path info, and move the hg version stuff into the template/helpers
Tero Marttila <terom@fixme.fi>
parents:
128
diff
changeset
|
54 |
# URL to the hgweb installation for this code |
144 | 55 |
HGWEB_URL = "http://hg.qmsk.net/qmsk.irclogs" |
119 | 56 |
|
140
6db2527b67cf
restructure into package format - the qmsk.* stuff doesn't work so well though, requires a symlink for qmsk.web to work...
Tero Marttila <terom@fixme.fi>
parents:
131
diff
changeset
|
57 |
# path to the mercurial working copy |
6db2527b67cf
restructure into package format - the qmsk.* stuff doesn't work so well though, requires a symlink for qmsk.web to work...
Tero Marttila <terom@fixme.fi>
parents:
131
diff
changeset
|
58 |
HG_WC_PATH = "." |
119 | 59 |
|
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
81
diff
changeset
|
60 |
# how to handle decode() errors for logfile lines |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
81
diff
changeset
|
61 |
LOG_SOURCE_DECODE_ERRORS = 'replace' |
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
81
diff
changeset
|
62 |
|
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
63 |
# date format for URLs |
79 | 64 |
URL_DATE_FMT = '%Y-%m-%d' |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
65 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
66 |
# month name format |
79 | 67 |
MONTH_FMT = '%B %Y' |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
68 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
69 |
# timezone name format |
79 | 70 |
TIMEZONE_FMT = '%Z %z' |
71 |
||
72 |
# TTF fonts to use for drawing images |
|
73 |
FORMATTER_IMAGE_FONTS = { |
|
124
4bc4de14f006
remove support for default font, as it doesn't support unicode, and implement a 1px line spacing for format_png
Tero Marttila <terom@fixme.fi>
parents:
121
diff
changeset
|
74 |
# XXX: no unicode support |
4bc4de14f006
remove support for default font, as it doesn't support unicode, and implement a 1px line spacing for format_png
Tero Marttila <terom@fixme.fi>
parents:
121
diff
changeset
|
75 |
# 'default': (None, "Ugly default font" ), |
79 | 76 |
'ttf-dejavu-mono': ("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf", "DejaVu Sans Mono" ), |
77 |
'ttf-liberation-mono': ("/usr/share/fonts/truetype/ttf-liberation/LiberationMono-Regular.ttf", "Liberation Mono Regular" ) |
|
78 |
} |
|
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
79 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
80 |
# available formatters |
79 | 81 |
LOG_FORMATTERS = { |
82 |
'irssi': IrssiFormatter, |
|
86
645cf9c4441e
implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents:
82
diff
changeset
|
83 |
'debug': DebugFormatter, |
79 | 84 |
} |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
85 |
|
131
67f5d2fdca1d
rename config.PREF_TIMEZONE_FALLBACK, add Cookie expire/path info, and move the hg version stuff into the template/helpers
Tero Marttila <terom@fixme.fi>
parents:
128
diff
changeset
|
86 |
# Cookie settings |
67f5d2fdca1d
rename config.PREF_TIMEZONE_FALLBACK, add Cookie expire/path info, and move the hg version stuff into the template/helpers
Tero Marttila <terom@fixme.fi>
parents:
128
diff
changeset
|
87 |
PREF_COOKIE_PATH = '/' |
67f5d2fdca1d
rename config.PREF_TIMEZONE_FALLBACK, add Cookie expire/path info, and move the hg version stuff into the template/helpers
Tero Marttila <terom@fixme.fi>
parents:
128
diff
changeset
|
88 |
PREF_COOKIE_EXPIRE_SECONDS = 1 * 365 * 24 * 60 * 60 # one year |
67f5d2fdca1d
rename config.PREF_TIMEZONE_FALLBACK, add Cookie expire/path info, and move the hg version stuff into the template/helpers
Tero Marttila <terom@fixme.fi>
parents:
128
diff
changeset
|
89 |
|
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
90 |
# default preferences |
79 | 91 |
PREF_TIME_FMT_DEFAULT = '%H:%M:%S' |
92 |
PREF_DATE_FMT_DEFAULT = '%Y-%m-%d' |
|
131
67f5d2fdca1d
rename config.PREF_TIMEZONE_FALLBACK, add Cookie expire/path info, and move the hg version stuff into the template/helpers
Tero Marttila <terom@fixme.fi>
parents:
128
diff
changeset
|
93 |
PREF_TIMEZONE_FALLBACK = pytz.utc |
79 | 94 |
PREF_FORMATTER_DEFAULT = IrssiFormatter |
95 |
PREF_COUNT_DEFAULT = 200 |
|
96 |
PREF_COUNT_MAX = None |
|
124
4bc4de14f006
remove support for default font, as it doesn't support unicode, and implement a 1px line spacing for format_png
Tero Marttila <terom@fixme.fi>
parents:
121
diff
changeset
|
97 |
PREF_IMAGE_FONT_DEFAULT = 'ttf-dejavu-mono' |
4bc4de14f006
remove support for default font, as it doesn't support unicode, and implement a 1px line spacing for format_png
Tero Marttila <terom@fixme.fi>
parents:
121
diff
changeset
|
98 |
PREF_IMAGE_FONT_SIZE_DEFAULT = 12 |
79 | 99 |
PREF_IMAGE_FONT_SIZE_MAX = 32 |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
100 |
|
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
101 |
# search line count options |
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
81
diff
changeset
|
102 |
SEARCH_LINE_COUNT_OPTIONS = ( |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
103 |
(50, 50), |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
104 |
(100, 100), |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
105 |
(200, 200), |
141
65c98c9e1716
improved search - separate q=/nick= fields
Tero Marttila <terom@fixme.fi>
parents:
140
diff
changeset
|
106 |
|
65c98c9e1716
improved search - separate q=/nick= fields
Tero Marttila <terom@fixme.fi>
parents:
140
diff
changeset
|
107 |
# infinity, not supported |
65c98c9e1716
improved search - separate q=/nick= fields
Tero Marttila <terom@fixme.fi>
parents:
140
diff
changeset
|
108 |
# (0, "∞"), |
73
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
109 |
) |
5a7188bf2894
split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
110 |
|
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
81
diff
changeset
|
111 |
# search index database path |
121
86aebc9cb60b
some quickfixes to fix deployment errors
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
112 |
SEARCH_INDEX_PATH = '/home/spbot/irclogs/search-index' |
86aebc9cb60b
some quickfixes to fix deployment errors
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
113 |
SEARCH_AUTOINDEX_PATH = '/home/spbot/irclogs/search-autoindex' |
82
afd3120ec71e
add a LogSourceDecoder to fallback from utf-8 to latin-1, and improve scripts/search-index.py
Tero Marttila <terom@fixme.fi>
parents:
81
diff
changeset
|
114 |