prevent some TB when converting logs

This commit is contained in:
Yann Leboulanger 2005-11-22 11:06:39 +00:00
parent 3e9b8d6bd2
commit a5f7c01911
1 changed files with 21 additions and 10 deletions

View File

@ -6,6 +6,7 @@ from pysqlite2 import dbapi2 as sqlite
PATH_TO_LOGS_BASE_DIR = os.path.expanduser('~/.gajim/logs')
jid_in = []
path_to_db = os.path.expanduser('~/.gajim/logs.db') # database is called logs.db
con = sqlite.connect(path_to_db)
cur = con.cursor()
@ -52,7 +53,7 @@ def from_one_line(msg):
def get_jid(dirname, filename):
# TABLE NAME will be JID if TC-related, room_jid if GC-related,
# ROOM_JID/nick if pm-related
if dirname.endswith('logs/'): # basename(gajim.LOGPATH)
if dirname.endswith('logs'): # basename(gajim.LOGPATH)
# we have file (not dir) in logs base dir, so it's TC
jid = filename # file is JID
else:
@ -70,11 +71,18 @@ def get_jid(dirname, filename):
def visit(arg, dirname, filenames):
for filename in filenames:
if filename == 'notify.log':
continue
path_to_text_file = os.path.join(dirname, filename)
if os.path.isdir(path_to_text_file):
continue
jid = get_jid(dirname, filename)
print 'Processing', jid
if jid in jid_in:
cur.execute('SELECT jid_id FROM jids WHERE jid="%s"' % jid)
else:
jid_in.append(jid)
cur.execute('INSERT INTO jids (jid) VALUES (?)', (jid,))
con.commit()
@ -86,13 +94,16 @@ def visit(arg, dirname, filenames):
for line in lines:
line = from_one_line(line)
splitted_line = line.split(':')
if len(splitted_line) > 2:
# 'gc', 'gcstatus', 'recv', 'sent' and if nothing of those
# it is status
type = splitted_line[1] # line[1] has type of logged message
message_data = splitted_line[2:] # line[2:] has message data
if len(splitted_line) > 2:
# line[0] is date,
try:
tim = int(float(splitted_line[0]))
except:
continue
sql = 'INSERT INTO logs (jid_id, contact_name, time, type, show, message) '\
'VALUES (?, ?, ?, ?, ?, ?)'