gajim-plural/plugins/logger/logger.py

105 lines
2.8 KiB
Python
Raw Normal View History

2003-11-30 17:02:00 +01:00
#!/usr/bin/env python
## plugins/logger.py
##
## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org>
##
## Copyright (C) 2003 Gajim Team
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 2 only.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
import os
import string
import time
import common.optparser
2004-01-18 23:56:28 +01:00
CONFPATH = "~/.gajim/config"
2003-11-30 17:02:00 +01:00
LOGPATH = os.path.expanduser("~/.gajim/logs/")
class plugin:
def read_queue(self):
while 1:
while self.queueIN.empty() == 0:
if self.config.has_key('lognotsep'):
lognotsep = self.config['lognotsep']
2003-11-30 17:02:00 +01:00
else:
lognotsep = 1
if self.config.has_key('lognotusr'):
lognotusr = self.config['lognotusr']
2003-11-30 17:02:00 +01:00
else:
lognotusr = 1
# tim = time.strftime("%d%m%y%H%M%S")
2003-12-04 20:57:06 +01:00
tim = "%d" % time.time()
2003-11-30 17:02:00 +01:00
ev = self.queueIN.get()
if ev[0] == 'QUIT':
return
elif ev[0] == 'NOTIFY':
status = ev[1][2]
2003-12-20 14:22:37 +01:00
jid = string.split(ev[1][0], '/')[0]
2003-11-30 17:02:00 +01:00
if not status:
status = ""
if lognotsep == 1:
fic = open(LOGPATH + "notify.log", "a")
fic.write("%s:%s:%s:%s\n" % (tim, ev[1][0], \
ev[1][1], status))
fic.close()
if lognotusr == 1:
2003-12-20 14:22:37 +01:00
fic = open(LOGPATH + jid, "a")
fic.write("%s:%s:%s:%s\n" % (tim, jid, \
2003-11-30 17:02:00 +01:00
ev[1][1], status))
fic.close()
elif ev[0] == 'MSG':
2003-12-20 14:22:37 +01:00
jid = string.split(ev[1][0], '/')[0]
fic = open(LOGPATH + jid, "a")
2003-11-30 17:02:00 +01:00
fic.write("%s:recv:%s\n" % (tim, ev[1][1]))
fic.close()
elif ev[0] == 'MSGSENT':
2003-12-20 14:22:37 +01:00
jid = string.split(ev[1][0], '/')[0]
fic = open(LOGPATH + jid, "a")
2003-11-30 17:02:00 +01:00
fic.write("%s:sent:%s\n" % (tim, ev[1][1]))
fic.close()
time.sleep(0.5)
def wait(self, what):
"""Wait for a message from Core"""
#TODO: timeout, save messages that don't fit
while 1:
if not self.queueIN.empty():
ev = self.queueIN.get()
if ev[0] == what:
return ev[1]
time.sleep(0.1)
2003-11-30 17:02:00 +01:00
def __init__(self, quIN, quOUT):
self.queueIN = quIN
self.queueOUT = quOUT
quOUT.put(('ASK_CONFIG', 'Logger'))
self.config = self.wait('CONFIG')
#create ~/.gajim/logs/ if it doesn't exist
2003-11-30 17:02:00 +01:00
try:
os.stat(os.path.expanduser("~/.gajim"))
except OSError:
os.mkdir(os.path.expanduser("~/.gajim"))
print "creating ~/.gajim/"
try:
os.stat(LOGPATH)
except OSError:
os.mkdir(LOGPATH)
print "creating ~/.gajim/logs/"
self.read_queue()
if __name__ == "__main__":
plugin(None, None)
print "plugin logger loaded"