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/>.
26 import os.path, sqlite3, subprocess
28 from globaldef
import userShareDir
39 global database, cursor
40 dir=os.path.expanduser(userShareDir)
41 if not os.path.isdir(dir):
42 subprocess.call(
"mkdir %s" %dir, shell=
True)
43 database = sqlite3.connect(os.path.join(dir,
"db"))
44 cursor=database.cursor()
45 cursor.execute(
'''create table if not exists owners (stickid text, uuid text, tatoo text, student text)''')
46 cursor.execute(
'''create table if not exists version (major text, minor text)''')
47 cursor.execute(
'''create table if not exists preferences (checkable int, mv int, schoolfile text, workdir text, manfile text, refresh_enabled int, refresh_delay int)''')
59 cursor.execute(
'''select * from version''')
60 values=cursor.fetchone()
63 cursor.execute(
'''insert into version values (?,?)''', (version.major(), version.minor()))
66 if major < version.major():
67 raise KeyError(
"The database version is too old!")
68 elif minor < version.minor():
69 cursor.execute(
"""update version
71 where major=?""", (version.minor(), version.major()))
82 cursor.execute(
"select * from owners where student=?", (student,))
83 return cursor.fetchone() !=
None
95 cursor.execute(
"select * from owners where stickid=? and uuid=? and tatoo=?", (stickid, uuid,tattoo))
96 return cursor.fetchone() !=
None
104 cursor.execute(
"select tatoo from owners")
105 return cursor.fetchmany()
114 cursor.execute(
"select student from owners where stickid=? and uuid=? and tatoo=?", (stickid, uuid,tattoo))
115 s = cursor.fetchone()
128 cursor.execute(
"select checkable, mv, schoolfile,workdir, manfile, refresh_enabled, refresh_delay from preferences")
129 s = cursor.fetchone()
136 refreshEnabled = s[5]==1
138 return {
"checkable" : checkable,
140 "schoolFile" : schoolFile,
143 "refreshEnabled": refreshEnabled,
144 "refreshDelay" : refreshDelay
148 return {
"checkable" :
True,
150 "schoolFile" :
"/usr/share/scolasync/exemple/SCONET_test.xml",
151 "workdir" :
"Travail",
152 "manfile" :
"/usr/share/scolasync/help/manualPage_fr_FR.html",
153 "refreshEnabled":
False,
162 cursor.execute(
"""update preferences set workdir=?""",
172 global database, cursor
173 if knowsId(stickid, uuid, tattoo):
174 cursor.execute(
"""update owners
176 where stickid=? and uuid=? and tatoo=?""", (student, stickid, uuid, tattoo))
178 cursor.execute(
"""insert into owners
179 values (?,?,?,?)""", (stickid, uuid, tattoo, student))
188 global database, cursor
194 if prefs[
"refreshEnabled"]:
198 cursor.execute(
"select checkable from preferences")
199 s = cursor.fetchone()
200 newValues=(1, mv, prefs[
"schoolFile"], prefs[
"workdir"], prefs[
"manfile"], refreshEnabled, prefs[
"refreshDelay"])
202 cursor.execute(
"""update preferences
203 set checkable=?, mv=?, schoolfile=?, workdir=?, manfile=?, refresh_enabled=?, refresh_delay=?""",
206 cursor.execute(
"""insert into preferences
207 values (?,?,?,?,?,?,?)""",
def tattooList
Renvoie la liste des tatouages connus de la base de données.
def writePrefs
inscrit les préférences
def writeStudent
inscrit un étudiant comme propriétaire d'une clé USB
def hasStudent
vérifie qu'un étudiant est déjà connu
def readPrefs
renvoie les préférences de ScolaSync
def openDb
Ouverture de la base de données de l'application, et création si nécessaire.
def setWd
définit le nouveau nom du répertoire de travail préféré.
def readStudent
renvoie l'étudiant qui possède une clé USB
def checkVersion
Vérifie si la base de données reste compatible.
def knowsId
dit si une clé USB est déjà connue