root/branches/gajim_0.9/src/common/check_paths.py

Revision 4700, 3.4 kB (checked in by asterix, 3 years ago)

change copyright from "Gajim Team" to real people

Line 
1## Contributors for this file:
2## - Yann Le Boulanger <asterix@lagaule.org>
3## - Nikos Kouremenos <kourem@gmail.com>
4## - Travis Shirk <travis@pobox.com>
5##
6## Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org>
7##                         Vincent Hanquez <tab@snarc.org>
8## Copyright (C) 2005 Yann Le Boulanger <asterix@lagaule.org>
9##                    Vincent Hanquez <tab@snarc.org>
10##                    Nikos Kouremenos <nkour@jabber.org>
11##                    Dimitur Kirov <dkirov@gmail.com>
12##                    Travis Shirk <travis@pobox.com>
13##                    Norman Rasmussen <norman@rasmussen.co.za>
14##
15## This program is free software; you can redistribute it and/or modify
16## it under the terms of the GNU General Public License as published
17## by the Free Software Foundation; version 2 only.
18##
19## This program is distributed in the hope that it will be useful,
20## but WITHOUT ANY WARRANTY; without even the implied warranty of
21## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22## GNU General Public License for more details.
23##
24
25import os
26import sys
27import stat
28
29from common import gajim
30import logger
31import i18n
32
33_ = i18n._
34Q_ = i18n.Q_
35
36from pysqlite2 import dbapi2 as sqlite # DO NOT MOVE ABOVE OF import gajim
37
38def create_log_db():
39        print _('creating logs database')
40        con = sqlite.connect(logger.LOG_DB_PATH) 
41        os.chmod(logger.LOG_DB_PATH, 0600) # rw only for us
42        cur = con.cursor()
43        # create the tables
44        # kind can be
45        # status, gcstatus, gc_msg, (we only recv for those 3),
46        # single_msg_recv, chat_msg_recv, chat_msg_sent, single_msg_sent
47        # to meet all our needs
48        # logs.jid_id --> jids.jid_id but Sqlite doesn't do FK etc so it's done in python code
49        # jids.jid text column will be JID if TC-related, room_jid if GC-related,
50        # ROOM_JID/nick if pm-related.
51        cur.executescript(
52                '''
53                CREATE TABLE jids(
54                        jid_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
55                        jid TEXT UNIQUE,
56                        type INTEGER
57                );
58               
59                CREATE TABLE logs(
60                        log_line_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
61                        jid_id INTEGER,
62                        contact_name TEXT,
63                        time INTEGER,
64                        kind INTEGER,
65                        show INTEGER,
66                        message TEXT,
67                        subject TEXT
68                );
69                '''
70                )
71
72        con.commit()
73
74def check_and_possibly_create_paths():
75        LOG_DB_PATH = logger.LOG_DB_PATH
76        VCARDPATH = gajim.VCARDPATH
77        dot_gajim = os.path.dirname(VCARDPATH)
78        if os.path.isfile(dot_gajim):
79                print _('%s is file but it should be a directory') % dot_gajim
80                print _('Gajim will now exit')
81                sys.exit()
82        elif os.path.isdir(dot_gajim):
83                s = os.stat(dot_gajim)
84                if s.st_mode & stat.S_IROTH: # others have read permission!
85                        os.chmod(dot_gajim, 0700) # rwx------
86
87                if not os.path.exists(VCARDPATH):
88                        print _('creating %s directory') % VCARDPATH
89                        os.mkdir(VCARDPATH, 0700)
90                elif os.path.isfile(VCARDPATH):
91                        print _('%s is file but it should be a directory') % VCARDPATH
92                        print _('Gajim will now exit')
93                        sys.exit()
94               
95                if not os.path.exists(LOG_DB_PATH):
96                        create_log_db()
97                elif os.path.isdir(LOG_DB_PATH):
98                        print _('%s is directory but should be file') % LOG_DB_PATH
99                        print _('Gajim will now exit')
100                        sys.exit()
101                       
102        else: # dot_gajim doesn't exist
103                if dot_gajim: # is '' on win9x so avoid that
104                        print _('creating %s directory') % dot_gajim
105                        os.mkdir(dot_gajim, 0700)
106                if not os.path.isdir(VCARDPATH):
107                        print _('creating %s directory') % VCARDPATH
108                        os.mkdir(VCARDPATH, 0700)
109                if not os.path.isfile(LOG_DB_PATH):
110                        create_log_db()
Note: See TracBrowser for help on using the browser.