config.py
author Tero Marttila <terom@fixme.fi>
Wed, 11 Feb 2009 04:04:55 +0200
changeset 102 e396613bc873
parent 86 645cf9c4441e
child 119 df859bfdd3be
permissions -rw-r--r--
have LogDirectory use utils.mtime instead of os.stat
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
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
# build relative paths
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
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    16
###                     ###
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    17
###    Configuration    ###
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    18
###                     ###
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    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
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    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
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    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
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    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
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    36
LOG_PARSER                      = IrssiParser(LOG_TIMEZONE, LOG_TIMESTAMP_FMT)
81
745032a57803 add #test logfile, improve handling of low-logfile situations
Tero Marttila <terom@fixme.fi>
parents: 79
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
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    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", 
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
    42
        LogDirectory(relpath('logs/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", 
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
    46
        LogDirectory(relpath('logs/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
745032a57803 add #test logfile, improve handling of low-logfile situations
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    49
    LogChannel('test',      "TEST",     "#test",
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
    50
        LogDirectory(relpath('/home/terom/irclogs/test'),  LOG_TIMEZONE, LOG_PARSER_FULLTS, LOG_DECODER, LOG_FILENAME_FMT)
81
745032a57803 add #test logfile, improve handling of low-logfile situations
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    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
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
    54
# 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
    55
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
    56
73
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
# date format for URLs
79
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    58
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
    59
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    60
# month name format
79
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    61
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
    62
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    63
# timezone name format
79
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    64
TIMEZONE_FMT                    = '%Z %z'
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    65
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    66
# TTF fonts to use for drawing images
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    67
FORMATTER_IMAGE_FONTS =         {
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    68
    'default':              (None,                                                                  "Ugly default font"         ),
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    69
    'ttf-dejavu-mono':      ("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf",             "DejaVu Sans Mono"          ),
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    70
    'ttf-liberation-mono':  ("/usr/share/fonts/truetype/ttf-liberation/LiberationMono-Regular.ttf", "Liberation Mono Regular"   )
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    71
}
73
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    72
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    73
# available formatters
79
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    74
LOG_FORMATTERS =                {
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    75
    'irssi':        IrssiFormatter,
86
645cf9c4441e implement full parser+formatter for irssi
Tero Marttila <terom@fixme.fi>
parents: 82
diff changeset
    76
    'debug':        DebugFormatter,
79
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    77
}
73
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    78
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    79
# default preferences
79
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    80
PREF_TIME_FMT_DEFAULT           = '%H:%M:%S'
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    81
PREF_DATE_FMT_DEFAULT           = '%Y-%m-%d'
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    82
PREF_TIMEZONE_DEFAULT           = pytz.utc
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    83
PREF_FORMATTER_DEFAULT          = IrssiFormatter
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    84
PREF_COUNT_DEFAULT              = 200
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    85
PREF_COUNT_MAX                  = None
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    86
PREF_IMAGE_FONT_DEFAULT         = 'default'
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    87
PREF_IMAGE_FONT_SIZE_DEFAULT    = 10
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
    88
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
    89
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    90
# 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
    91
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
    92
    (50,    50), 
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    93
    (100,   100), 
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    94
    (200,   200), 
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    95
    (None,  "&#8734;"),
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    96
)
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    97
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
    98
# search index database path
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
    99
SEARCH_INDEX_PATH               = 'logs/index'
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
   100