author | Mikael Berthe <mikael@lilotux.net> |
Sun, 20 May 2007 12:33:55 +0200 | |
changeset 41 | ca6e989ca850 |
parent 35 | 8daaa0b29b71 |
permissions | -rw-r--r-- |
0
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
1 |
#$ neutron_plugin 01 |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
2 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
3 |
import re |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
4 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
5 |
LOG_CACHE_FILE = 'dynamic/logcache.txt' |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
6 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
7 |
initialize_file(LOG_CACHE_FILE, '{}') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
8 |
LOG_FILENAME_CACHE = eval(read_file(LOG_CACHE_FILE)) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
9 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
10 |
def log_write_header(fp, source, (year, month, day, hour, minute, second, weekday, yearday, daylightsavings)): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
11 |
fp.write("""<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
12 |
<head> |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
13 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
14 |
<style type="text/css"> |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
15 |
<!-- |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
16 |
.timestamp {color: #AAAAAA;} |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
17 |
.system {color: #009900; font-weight: bold;} |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
18 |
.emote {color: #AA0099;} |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
19 |
.self {color: #CC0000;} |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
20 |
.normal {color: #0000AA;} |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
21 |
h1 { color: #336699; font-family: sans-serif; border-bottom: #224466 solid 3pt; letter-spacing: 3px; margin-left: 20pt; } |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
22 |
h2 { color: #663399; font-family: sans-serif; letter-spacing: 2px; text-align: center } |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
23 |
//--> |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
24 |
</style> |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
25 |
</head> |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
26 |
<body> |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
27 |
<div style="color: #AAAAAA; text-align: right; font-family: monospace; letter-spacing: 3px">neutron log</div> |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
28 |
<h1>""" + source + """</h1> |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
29 |
<h2>""" + time.strftime('%A, %B %d, %Y', (year, month, day, hour, minute, second, weekday, yearday, daylightsavings)) + """</h2> |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
30 |
<br /> |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
31 |
<tt> |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
32 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
33 |
""") |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
34 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
35 |
def log_write_footer(fp): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
36 |
fp.write('\n</tt>\n</body>\n</html>') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
37 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
38 |
def log_get_fp(type, source, (year, month, day, hour, minute, second, weekday, yearday, daylightsavings)): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
39 |
if type == 'public': |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
40 |
logdir = PUBLIC_LOG_DIR |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
41 |
else: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
42 |
logdir = PRIVATE_LOG_DIR |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
43 |
if logdir[-1] == '/': |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
44 |
logdir = LOGDIR[:-1] |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
45 |
str_year = str(year) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
46 |
str_month = str(month) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
47 |
str_day = str(day) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
48 |
filename = logdir + '/' + source + '/' + str_year + '/' + str_month + '/' + str_day + '.html' |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
49 |
alt_filename = logdir + '/' + source + '/' + str_year + '/' + str_month + '/' + str_day + '_alt.html' |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
50 |
if not os.path.exists(logdir): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
51 |
os.mkdir(logdir) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
52 |
if not os.path.exists(logdir + '/' + source): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
53 |
os.mkdir(logdir + '/' + source) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
54 |
if not os.path.exists(logdir + '/' + source + '/' + str_year): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
55 |
os.mkdir(logdir + '/' + source + '/' + str_year) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
56 |
if not os.path.exists(logdir + '/' + source + '/' + str_year + '/' + str_month): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
57 |
os.mkdir(logdir + '/' + source + '/' + str_year + '/' + str_month) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
58 |
if LOG_FILENAME_CACHE.has_key(source): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
59 |
if LOG_FILENAME_CACHE[source] != filename: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
60 |
fp_old = file(LOG_FILENAME_CACHE[source], 'a') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
61 |
log_write_footer(fp_old) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
62 |
fp_old.close() |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
63 |
if os.path.exists(filename): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
64 |
fp = file(filename, 'a') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
65 |
return fp |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
66 |
else: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
67 |
LOG_FILENAME_CACHE[source] = filename |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
68 |
write_file(LOG_CACHE_FILE, str(LOG_FILENAME_CACHE)) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
69 |
fp = file(filename, 'w') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
70 |
log_write_header(fp, source, (year, month, day, hour, minute, second, weekday, yearday, daylightsavings)) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
71 |
return fp |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
72 |
else: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
73 |
if os.path.exists(filename): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
74 |
LOG_FILENAME_CACHE[source] = filename |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
75 |
write_file(LOG_CACHE_FILE, str(LOG_FILENAME_CACHE)) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
76 |
fp = file(alt_filename, 'a') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
77 |
# log_write_header(fp, source, (year, month, day, hour, minute, second, weekday, yearday, daylightsavings)) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
78 |
return fp |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
79 |
else: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
80 |
LOG_FILENAME_CACHE[source] = filename |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
81 |
write_file(LOG_CACHE_FILE, str(LOG_FILENAME_CACHE)) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
82 |
fp = file(filename, 'w') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
83 |
log_write_header(fp, source, (year, month, day, hour, minute, second, weekday, yearday, daylightsavings)) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
84 |
return fp |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
85 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
86 |
def log_get_timestamp(hour, minute): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
87 |
timestamp = '[' |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
88 |
if hour < 10: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
89 |
timestamp += '0' |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
90 |
timestamp += str(hour) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
91 |
timestamp += ':' |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
92 |
if minute < 10: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
93 |
timestamp += '0' |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
94 |
timestamp += str(minute) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
95 |
timestamp += ']' |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
96 |
return timestamp |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
97 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
98 |
def log_regex_url(matchobj): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
99 |
# 06.03.05(Sun) slipstream@yandex.ru urls parser |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
100 |
return '<a href="' + matchobj.group(0) + '">' + matchobj.group(0) + '</a>' |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
101 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
102 |
def log_handler_message(type, source, body): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
103 |
if not body: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
104 |
return |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
105 |
(year, month, day, hour, minute, second, weekday, yearday, daylightsavings) = time.gmtime() |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
106 |
if type == 'public' and PUBLIC_LOG_DIR: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
107 |
groupchat = source[1] |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
108 |
nick = source[2] |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
109 |
# 06.03.05(Sun) slipstream@yandex.ru urls parser & line ends |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
110 |
body = body.replace('&', '&').replace('"', '"').replace('<', '<').replace('>', '>') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
111 |
body = re.sub('(http|ftp)(\:\/\/[^\s<]+)', log_regex_url, body) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
112 |
body = body.replace('\n', '<br />') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
113 |
body = body.encode('utf-8'); |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
114 |
nick = nick.encode('utf-8'); |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
115 |
timestamp = log_get_timestamp(hour, minute) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
116 |
fp = log_get_fp('public', groupchat, (year, month, day, hour, minute, second, weekday, yearday, daylightsavings)) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
117 |
fp.write('<font class="timestamp">' + timestamp + '</font> ') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
118 |
if not nick: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
119 |
fp.write('<font class="system">' + body + '</font><br />\n') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
120 |
elif body[:3].lower() == '/me': |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
121 |
fp.write('<font class="emote">* ' + nick + body[3:] + '</font><br />\n') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
122 |
else: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
123 |
# 08.03.05(Tue) slipstream@yandex.ru encoding |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
124 |
if nick == get_nick(groupchat).encode('utf-8'): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
125 |
fp.write('<font class="self"><' + nick + '></font> ') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
126 |
else: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
127 |
fp.write('<font class="normal"><' + nick + '></font> ') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
128 |
fp.write(body + '<br />\n') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
129 |
fp.close() |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
130 |
elif type == 'private' and PRIVATE_LOG_DIR: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
131 |
jid = get_true_jid(source) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
132 |
nick = string.split(jid, '@')[0] |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
133 |
# 06.03.05(Sun) slipstream@yandex.ru urls parser, line ends & encoding |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
134 |
body = body.replace('&', '&').replace('"', '"').replace('<', '<').replace('>', '>') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
135 |
body = re.sub('(http|ftp)(\:\/\/[^\s<]+)', log_regex_url, body) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
136 |
body = body.replace('\n', '<br />') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
137 |
body = body.encode('utf-8'); |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
138 |
nick = nick.encode('utf-8'); |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
139 |
timestamp = log_get_timestamp(hour, minute) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
140 |
fp = log_get_fp('private', jid, (year, month, day, hour, minute, second, weekday, yearday, daylightsavings)) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
141 |
fp.write('<font class="timestamp">' + timestamp + '</font> ') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
142 |
if body[:3].lower() == '/me': |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
143 |
fp.write('<font class="emote">* ' + nick + body[3:] + '</font><br />\n') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
144 |
else: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
145 |
fp.write('<font class="normal"><' + nick + '></font> ' + body + '<br />\n') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
146 |
fp.close() |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
147 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
148 |
def log_handler_outgoing_message(target, body): |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
149 |
if GROUPCHATS.has_key(target) or not body: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
150 |
return |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
151 |
(year, month, day, hour, minute, second, weekday, yearday, daylightsavings) = time.gmtime() |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
152 |
jid = get_true_jid(target) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
153 |
nick = 'neutron' |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
154 |
# 06.03.05(Sun) slipstream@yandex.ru urls parser, line ends & encoding |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
155 |
body = body.replace('&', '&').replace('"', '"').replace('<', '<').replace('>', '>') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
156 |
body = re.sub('(http|ftp)(\:\/\/[^\s<]+)', log_regex_url, body) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
157 |
body = body.replace('\n', '<br />') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
158 |
body = body.encode('utf-8'); |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
159 |
nick = nick.encode('utf-8'); |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
160 |
timestamp = log_get_timestamp(hour, minute) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
161 |
fp = log_get_fp('private', jid, (year, month, day, hour, minute, second, weekday, yearday, daylightsavings)) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
162 |
fp.write('<font class="timestamp">' + timestamp + '</font> ') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
163 |
if body[:3].lower() == '/me': |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
164 |
fp.write('<font class="emote">* ' + nick + body[3:] + '</font><br />\n') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
165 |
else: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
166 |
fp.write('<font class="self"><' + nick + '></font> ' + body + '<br />\n') |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
167 |
fp.close() |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
168 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
169 |
if PUBLIC_LOG_DIR or PRIVATE_LOG_DIR: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
170 |
register_message_handler(log_handler_message) |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
171 |
if PRIVATE_LOG_DIR: |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
172 |
register_outgoing_message_handler(log_handler_outgoing_message) |