From 7a6cf5a98d75c16c67d5e2194feabf5ca02c36f0 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Mon, 21 Nov 2005 23:19:31 +0000 Subject: [PATCH] add script that migrates plain old files to db logs --- scripts/migrate_to_dot9_logs.py | 131 ++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 scripts/migrate_to_dot9_logs.py diff --git a/scripts/migrate_to_dot9_logs.py b/scripts/migrate_to_dot9_logs.py new file mode 100644 index 000000000..ad4769df4 --- /dev/null +++ b/scripts/migrate_to_dot9_logs.py @@ -0,0 +1,131 @@ +import os +import sre + +from pysqlite2 import dbapi2 as sqlite + +PATH_TO_LOGS_BASE_DIR = os.path.expanduser('~/.gajim/logs') + +path_to_db = os.path.expanduser('~/.gajim/logs.db') # database is called logs.db +con = sqlite.connect(path_to_db) +cur = con.cursor() +# create the tables +# type can be 'gc', 'gcstatus', 'recv', 'sent', 'status' +# logs --> jids.jid_id but Sqlite doesn't do FK etc so it's done in python code +cur.executescript( + ''' + CREATE TABLE jids( + jid_id INTEGER PRIMARY KEY AUTOINCREMENT, + jid TEXT UNIQUE + ); + + CREATE TABLE logs( + log_line_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, + jid_id INTEGER, + contact_name TEXT, + time INTEGER, + type TEXT, + show TEXT, + message TEXT + ); + + + CREATE UNIQUE INDEX JID_Index ON jids (jid); + CREATE INDEX JID_ID_Index ON logs (jid_id); + ''' + ) + +con.commit() + +def from_one_line(msg): + # (? 2: + # line[0] is date, + tim = int(float(splitted_line[0])) + + sql = 'INSERT INTO logs (jid_id, contact_name, time, type, show, message) '\ + 'VALUES (?, ?, ?, ?, ?, ?)' + + contact_name = None + show = None + if type == 'gc': + contact_name = message_data[0] + message = ':'.join(message_data[1:]) + elif type == 'gcstatus': + contact_name = message_data[0] + show = message_data[1] + message = ':'.join(message_data[2:]) # status msg + elif type in ('recv', 'sent'): + message = ':'.join(message_data[0:]) + else: # status + type = 'status' + show = message_data[0] + message = ':'.join(message_data[1:]) # status msg + + values = (JID_ID, contact_name, tim, type, show, message) + cur.execute(sql, values) + con.commit() + +if __name__ == '__main__': + os.path.walk(PATH_TO_LOGS_BASE_DIR, visit, None) + f = open(os.path.join(PATH_TO_LOGS_BASE_DIR, 'README'), 'w') + f.write('We do not use plain-text files anymore, because they do not scale.\n') + f.write('Those files here are logs for Gajim up until 0.8.2\n') + f.write('We now use an sqlite database called logs.db found in ~/.gajim\n') + f.write('You can always run the migration script to import you old logs to the database\n') + f.write('Thank you\n') + f.close()