2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/common/check_paths.py
|
2005-11-23 20:12:52 +01:00
|
|
|
##
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2005-2006 Travis Shirk <travis AT pobox.com>
|
|
|
|
## Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
## Copyright (C) 2005-2008 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
## Copyright (C) 2006 Dimitur Kirov <dkirov AT gmail.com>
|
|
|
|
## Copyright (C) 2007 Tomasz Melcer <liori AT exroot.org>
|
|
|
|
## Copyright (C) 2008 Jean-Marie Traissard <jim AT lapin.org>
|
2005-11-23 20:12:52 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2005-11-23 20:12:52 +01:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2005-11-23 20:12:52 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2005-11-23 20:12:52 +01:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-11-23 20:12:52 +01:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2005-11-23 20:12:52 +01:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import stat
|
|
|
|
|
2008-12-02 16:10:31 +01:00
|
|
|
import exceptions
|
2005-12-05 12:13:08 +01:00
|
|
|
from common import gajim
|
2005-11-23 20:12:52 +01:00
|
|
|
import logger
|
|
|
|
|
2006-10-12 00:31:51 +02:00
|
|
|
# DO NOT MOVE ABOVE OF import gajim
|
|
|
|
try:
|
|
|
|
import sqlite3 as sqlite # python 2.5
|
|
|
|
except ImportError:
|
|
|
|
try:
|
|
|
|
from pysqlite2 import dbapi2 as sqlite
|
|
|
|
except ImportError:
|
|
|
|
raise exceptions.PysqliteNotAvailable
|
2005-11-23 20:12:52 +01:00
|
|
|
|
|
|
|
def create_log_db():
|
|
|
|
print _('creating logs database')
|
2008-12-03 22:56:12 +01:00
|
|
|
con = sqlite.connect(logger.LOG_DB_PATH)
|
2005-11-26 00:23:25 +01:00
|
|
|
os.chmod(logger.LOG_DB_PATH, 0600) # rw only for us
|
2005-11-23 20:12:52 +01:00
|
|
|
cur = con.cursor()
|
|
|
|
# create the tables
|
|
|
|
# kind can be
|
|
|
|
# status, gcstatus, gc_msg, (we only recv for those 3),
|
|
|
|
# single_msg_recv, chat_msg_recv, chat_msg_sent, single_msg_sent
|
|
|
|
# to meet all our needs
|
|
|
|
# logs.jid_id --> jids.jid_id but Sqlite doesn't do FK etc so it's done in python code
|
|
|
|
# jids.jid text column will be JID if TC-related, room_jid if GC-related,
|
|
|
|
# ROOM_JID/nick if pm-related.
|
2007-07-09 23:24:47 +02:00
|
|
|
# also check optparser.py, which updates databases on gajim updates
|
2005-11-23 20:12:52 +01:00
|
|
|
cur.executescript(
|
|
|
|
'''
|
|
|
|
CREATE TABLE jids(
|
|
|
|
jid_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
|
2005-11-26 00:23:25 +01:00
|
|
|
jid TEXT UNIQUE,
|
|
|
|
type INTEGER
|
2005-11-23 20:12:52 +01:00
|
|
|
);
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-04-11 00:08:02 +02:00
|
|
|
CREATE TABLE unread_messages(
|
2006-04-19 10:53:27 +02:00
|
|
|
message_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
|
2009-08-30 22:48:45 +02:00
|
|
|
jid_id INTEGER,
|
|
|
|
shown BOOLEAN default 0
|
2006-04-11 00:08:02 +02:00
|
|
|
);
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-10-07 12:08:38 +02:00
|
|
|
CREATE INDEX idx_unread_messages_jid_id ON unread_messages (jid_id);
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-08-10 08:57:10 +02:00
|
|
|
CREATE TABLE transports_cache (
|
|
|
|
transport TEXT UNIQUE,
|
|
|
|
type INTEGER
|
|
|
|
);
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2005-11-23 20:12:52 +01:00
|
|
|
CREATE TABLE logs(
|
|
|
|
log_line_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
|
|
|
|
jid_id INTEGER,
|
|
|
|
contact_name TEXT,
|
|
|
|
time INTEGER,
|
2005-11-26 00:23:25 +01:00
|
|
|
kind INTEGER,
|
|
|
|
show INTEGER,
|
|
|
|
message TEXT,
|
|
|
|
subject TEXT
|
2005-11-23 20:12:52 +01:00
|
|
|
);
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-10-07 12:08:38 +02:00
|
|
|
CREATE INDEX idx_logs_jid_id_kind ON logs (jid_id, kind);
|
2007-07-09 23:24:47 +02:00
|
|
|
|
|
|
|
CREATE TABLE caps_cache (
|
2008-04-21 00:58:47 +02:00
|
|
|
hash_method TEXT,
|
|
|
|
hash TEXT,
|
2007-07-09 23:24:47 +02:00
|
|
|
data BLOB);
|
2008-04-15 03:52:11 +02:00
|
|
|
|
2009-05-27 09:50:12 +02:00
|
|
|
CREATE TABLE rooms_last_message_time(
|
2008-04-15 03:52:11 +02:00
|
|
|
jid_id INTEGER PRIMARY KEY UNIQUE,
|
|
|
|
time INTEGER
|
2008-04-15 04:05:08 +02:00
|
|
|
);
|
2009-06-02 22:48:32 +02:00
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS roster_entry(
|
2009-06-23 19:29:25 +02:00
|
|
|
account_jid_id INTEGER,
|
2009-06-02 22:48:32 +02:00
|
|
|
jid_id INTEGER,
|
2009-06-23 19:29:25 +02:00
|
|
|
name TEXT,
|
|
|
|
subscription INTEGER,
|
2009-06-27 20:54:49 +02:00
|
|
|
ask BOOLEAN,
|
2009-06-23 19:29:25 +02:00
|
|
|
PRIMARY KEY (account_jid_id, jid_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS roster_group(
|
|
|
|
account_jid_id INTEGER,
|
|
|
|
jid_id INTEGER,
|
|
|
|
group_name TEXT,
|
|
|
|
PRIMARY KEY (account_jid_id, jid_id, group_name)
|
2009-06-02 22:48:32 +02:00
|
|
|
);
|
2005-11-23 20:12:52 +01:00
|
|
|
'''
|
|
|
|
)
|
|
|
|
|
|
|
|
con.commit()
|
2006-04-19 10:53:27 +02:00
|
|
|
con.close()
|
2005-11-23 20:12:52 +01:00
|
|
|
|
2005-11-23 20:21:46 +01:00
|
|
|
def check_and_possibly_create_paths():
|
2005-11-23 20:12:52 +01:00
|
|
|
LOG_DB_PATH = logger.LOG_DB_PATH
|
2006-02-15 11:44:41 +01:00
|
|
|
VCARD_PATH = gajim.VCARD_PATH
|
2006-01-17 15:36:17 +01:00
|
|
|
AVATAR_PATH = gajim.AVATAR_PATH
|
2006-02-15 11:44:41 +01:00
|
|
|
dot_gajim = os.path.dirname(VCARD_PATH)
|
2005-11-23 20:12:52 +01:00
|
|
|
if os.path.isfile(dot_gajim):
|
2007-01-02 14:36:54 +01:00
|
|
|
print _('%s is a file but it should be a directory') % dot_gajim
|
2005-11-23 20:12:52 +01:00
|
|
|
print _('Gajim will now exit')
|
|
|
|
sys.exit()
|
|
|
|
elif os.path.isdir(dot_gajim):
|
|
|
|
s = os.stat(dot_gajim)
|
|
|
|
if s.st_mode & stat.S_IROTH: # others have read permission!
|
|
|
|
os.chmod(dot_gajim, 0700) # rwx------
|
|
|
|
|
2006-02-15 11:44:41 +01:00
|
|
|
if not os.path.exists(VCARD_PATH):
|
2006-02-15 22:45:20 +01:00
|
|
|
create_path(VCARD_PATH)
|
2006-02-15 11:44:41 +01:00
|
|
|
elif os.path.isfile(VCARD_PATH):
|
2007-01-02 14:36:54 +01:00
|
|
|
print _('%s is a file but it should be a directory') % VCARD_PATH
|
2005-11-23 20:12:52 +01:00
|
|
|
print _('Gajim will now exit')
|
|
|
|
sys.exit()
|
2006-04-12 10:38:51 +02:00
|
|
|
|
2006-01-17 12:20:55 +01:00
|
|
|
if not os.path.exists(AVATAR_PATH):
|
2006-02-15 22:45:20 +01:00
|
|
|
create_path(AVATAR_PATH)
|
2006-01-17 12:20:55 +01:00
|
|
|
elif os.path.isfile(AVATAR_PATH):
|
2007-01-02 14:36:54 +01:00
|
|
|
print _('%s is a file but it should be a directory') % AVATAR_PATH
|
2006-01-17 10:01:59 +01:00
|
|
|
print _('Gajim will now exit')
|
|
|
|
sys.exit()
|
2006-04-12 10:38:51 +02:00
|
|
|
|
2005-11-23 20:12:52 +01:00
|
|
|
if not os.path.exists(LOG_DB_PATH):
|
|
|
|
create_log_db()
|
2006-04-19 10:53:27 +02:00
|
|
|
gajim.logger.init_vars()
|
2005-11-23 20:12:52 +01:00
|
|
|
elif os.path.isdir(LOG_DB_PATH):
|
2007-01-02 14:36:54 +01:00
|
|
|
print _('%s is a directory but should be a file') % LOG_DB_PATH
|
2005-11-23 20:12:52 +01:00
|
|
|
print _('Gajim will now exit')
|
|
|
|
sys.exit()
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2005-11-23 20:12:52 +01:00
|
|
|
else: # dot_gajim doesn't exist
|
|
|
|
if dot_gajim: # is '' on win9x so avoid that
|
2006-02-15 22:45:20 +01:00
|
|
|
create_path(dot_gajim)
|
2006-02-15 11:44:41 +01:00
|
|
|
if not os.path.isdir(VCARD_PATH):
|
2006-02-15 22:45:20 +01:00
|
|
|
create_path(VCARD_PATH)
|
2006-02-15 11:35:13 +01:00
|
|
|
if not os.path.exists(AVATAR_PATH):
|
2006-02-15 22:45:20 +01:00
|
|
|
create_path(AVATAR_PATH)
|
2005-11-23 20:12:52 +01:00
|
|
|
if not os.path.isfile(LOG_DB_PATH):
|
2006-01-17 10:01:59 +01:00
|
|
|
create_log_db()
|
2005-12-24 23:33:35 +01:00
|
|
|
gajim.logger.init_vars()
|
2006-02-15 11:42:40 +01:00
|
|
|
|
|
|
|
def create_path(directory):
|
|
|
|
print _('creating %s directory') % directory
|
2006-02-16 09:59:28 +01:00
|
|
|
os.mkdir(directory, 0700)
|
2008-07-29 21:49:31 +02:00
|
|
|
|
2008-08-15 05:20:23 +02:00
|
|
|
# vim: se ts=3:
|