6 this file is part of the project scolasync
8 Copyright (C) 2010 Georges Khaznadar <georgesk@ofset.org>
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 import os.path, sqlite3, subprocess
26 from globaldef
import userShareDir
37 global database, cursor
38 dir=os.path.expanduser(userShareDir)
39 if not os.path.isdir(dir):
40 subprocess.call(
"mkdir %s" %dir, shell=
True)
41 database = sqlite3.connect(os.path.join(dir,
"db"))
42 cursor=database.cursor()
43 cursor.execute(
'''create table if not exists owners (stickid text, uuid text, tatoo text, student text)''')
44 cursor.execute(
'''create table if not exists version (major text, minor text)''')
45 cursor.execute(
'''create table if not exists preferences (checkable int, mv int, schoolfile text, workdir text, manfile text)''')
57 cursor.execute(
'''select * from version''')
58 values=cursor.fetchone()
61 cursor.execute(
'''insert into version values (?,?)''', (version.major(), version.minor()))
64 if major < version.major():
65 raise KeyError(
"The database version is too old!")
66 elif minor < version.minor():
67 cursor.execute(
"""update version
69 where major=?""", (version.minor(), version.major()))
80 cursor.execute(
"select * from owners where student=?", (student,))
81 return cursor.fetchone() !=
None
93 cursor.execute(
"select * from owners where stickid=? and uuid=? and tatoo=?", (stickid, uuid,tattoo))
94 return cursor.fetchone() !=
None
102 cursor.execute(
"select tatoo from owners")
103 return cursor.fetchmany()
112 cursor.execute(
"select student from owners where stickid=? and uuid=? and tatoo=?", (stickid, uuid,tattoo))
113 s = cursor.fetchone()
126 cursor.execute(
"select checkable, mv, schoolfile,workdir, manfile from preferences")
127 s = cursor.fetchone()
134 return {
"checkable" : checkable,
136 "schoolFile" : schoolFile,
142 return {
"checkable" :
True,
144 "schoolFile" :
"/usr/share/scolasync/exemple/SCONET_test.xml",
145 "workdir" :
"Travail",
146 "manfile" :
"/usr/share/scolasync/help/manualPage_fr_FR.html",
154 cursor.execute(
"""update preferences set workdir=?""",
164 global database, cursor
165 if knowsId(stickid, uuid, tattoo):
166 cursor.execute(
"""update owners
168 where stickid=? and uuid=? and tatoo=?""", (student, stickid, uuid, tattoo))
170 cursor.execute(
"""insert into owners
171 values (?,?,?,?)""", (stickid, uuid, tattoo, student))
180 global database, cursor
186 cursor.execute(
"select checkable from preferences")
187 s = cursor.fetchone()
188 newValues=(1, mv, prefs[
"schoolFile"], prefs[
"workdir"], prefs[
"manfile"])
190 cursor.execute(
"""update preferences
191 set checkable=?, mv=?, schoolfile=?, workdir=?, manfile=?""",
194 cursor.execute(
"""insert into preferences
195 values (?,?,?,?,?)""",
def writeStudent(stickid, uuid, tattoo, student)
inscrit un étudiant comme propriétaire d'une clé USB
def knowsId(stickid, uuid, tattoo)
dit si une clé USB est déjà connue
def checkVersion(major, minor)
Vérifie si la base de données reste compatible.
def setWd(newDir)
définit le nouveau nom du répertoire de travail préféré.
def tattooList()
Renvoie la liste des tatouages connus de la base de données.
def openDb()
Ouverture de la base de données de l'application, et création si nécessaire.
def writePrefs(prefs)
inscrit les préférences
def hasStudent(student)
vérifie qu'un étudiant est déjà connu
def readStudent(stickid, uuid, tattoo)
renvoie l'étudiant qui possède une clé USB
def readPrefs()
renvoie les préférences de ScolaSync