7 this file is part of the project scolasync
9 Copyright (C) 2010 Georges Khaznadar <georgesk@ofset.org>
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 import os.path, sqlite3, subprocess
27 from globaldef
import userShareDir
38 global database, cursor
39 dir=os.path.expanduser(userShareDir)
40 if not os.path.isdir(dir):
41 subprocess.call(
"mkdir %s" %dir, shell=
True)
42 database = sqlite3.connect(os.path.join(dir,
"db"))
43 cursor=database.cursor()
44 cursor.execute(
'''create table if not exists owners (stickid text, uuid text, tatoo text, student text)''')
45 cursor.execute(
'''create table if not exists version (major text, minor text)''')
46 cursor.execute(
'''create table if not exists preferences (checkable int, mv int, schoolfile text, workdir text, manfile text, refresh_enabled int, refresh_delay int)''')
58 cursor.execute(
'''select * from version''')
59 values=cursor.fetchone()
62 cursor.execute(
'''insert into version values (?,?)''', (version.major(), version.minor()))
65 if major < version.major():
66 raise KeyError,
"The database version is too old!"
67 elif minor < version.minor():
68 cursor.execute(
"""update version
70 where major=?""", (version.minor(), version.major()))
81 cursor.execute(
"select * from owners where student=?", (student,))
82 return cursor.fetchone() !=
None
94 cursor.execute(
"select * from owners where stickid=? and uuid=? and tatoo=?", (stickid, uuid,tattoo))
95 return cursor.fetchone() !=
None
103 cursor.execute(
"select tatoo from owners")
104 return cursor.fetchmany()
113 cursor.execute(
"select student from owners where stickid=? and uuid=? and tatoo=?", (stickid, uuid,tattoo))
114 s = cursor.fetchone()
127 cursor.execute(
"select checkable, mv, schoolfile,workdir, manfile, refresh_enabled, refresh_delay from preferences")
128 s = cursor.fetchone()
135 refreshEnabled = s[5]==1
137 return {
"checkable" : checkable,
139 "schoolFile" : schoolFile,
142 "refreshEnabled": refreshEnabled,
143 "refreshDelay" : refreshDelay
147 return {
"checkable" :
True,
149 "schoolFile" :
"/usr/share/scolasync/exemple/SCONET_test.xml",
150 "workdir" :
"Travail",
151 "manfile" :
"/usr/share/scolasync/help/manualPage_fr_FR.html",
152 "refreshEnabled":
False,
161 cursor.execute(
"""update preferences set workdir=?""",
171 global database, cursor
172 if knowsId(stickid, uuid, tattoo):
173 cursor.execute(
"""update owners
175 where stickid=? and uuid=? and tatoo=?""", (student, stickid, uuid, tattoo))
177 cursor.execute(
"""insert into owners
178 values (?,?,?,?)""", (stickid, uuid, tattoo, student))
187 global database, cursor
188 if prefs[
"checkable"]:
196 if prefs[
"refreshEnabled"]:
200 cursor.execute(
"select checkable from preferences")
201 s = cursor.fetchone()
202 newValues=(checkable, mv, prefs[
"schoolFile"], prefs[
"workdir"], prefs[
"manfile"], refreshEnabled, prefs[
"refreshDelay"])
204 cursor.execute(
"""update preferences
205 set checkable=?, mv=?, schoolfile=?, workdir=?, manfile=?, refresh_enabled=?, refresh_delay=?""",
208 cursor.execute(
"""insert into preferences
209 values (?,?,?,?,?,?,?)""",