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
 
   36     global database, cursor
 
   37     dir=os.path.expanduser(userShareDir)
 
   38     if not os.path.isdir(dir):
 
   39         subprocess.call(
"mkdir %s" %dir, shell=
True)
 
   40     database = sqlite3.connect(os.path.join(dir,
"db"))
 
   41     cursor=database.cursor()
 
   42     cursor.execute(
'''create table if not exists owners (stickid text, uuid text, tatoo text, student text)''')
 
   43     cursor.execute(
'''create table if not exists version (major text, minor text)''')
 
   44     cursor.execute(
'''create table if not exists preferences (checkable int, mv int, schoolfile text, workdir text, manfile text)''')
 
   55     cursor.execute(
'''select * from version''')
 
   56     values=cursor.fetchone()
 
   59         cursor.execute(
'''insert into version values (?,?)''', (version.major(), version.minor()))
 
   62         if major < version.major():
 
   63             raise KeyError(
"The database version is too old!")
 
   64         elif minor < version.minor():
 
   65             cursor.execute(
"""update version 
   67                           where major=?""", (version.minor(), version.major()))
 
   77     cursor.execute(
"select * from owners where student=?", (student,))
 
   78     return cursor.fetchone() != 
None 
   89     cursor.execute(
"select * from owners where stickid=? and uuid=? and tatoo=?", (stickid, uuid,tattoo))
 
   90     return cursor.fetchone() != 
None 
   97     cursor.execute(
"select tatoo from owners")
 
   98     return cursor.fetchmany()
 
  106     cursor.execute(
"select student from owners where stickid=? and uuid=? and tatoo=?", (stickid, uuid,tattoo))
 
  107     s = cursor.fetchone()
 
  119     cursor.execute(
"select checkable, mv, schoolfile,workdir, manfile from preferences")
 
  120     s = cursor.fetchone()
 
  127         return {
"checkable"     : checkable,
 
  129                 "schoolFile"    : schoolFile,
 
  135         return {
"checkable"     : 
True,
 
  137                 "schoolFile"    : 
"/usr/share/scolasync/exemple/SCONET_test.xml",
 
  138                 "workdir"       : 
"Travail",
 
  139                 "manfile"       : 
"/usr/share/scolasync/help/manualPage_fr_FR.html",
 
  146     cursor.execute(
"""update preferences set workdir=?""",
 
  155     global database, cursor
 
  156     if knowsId(stickid, uuid, tattoo):
 
  157         cursor.execute(
"""update owners 
  159                           where stickid=? and uuid=? and tatoo=?""", (student, stickid, uuid, tattoo))
 
  161         cursor.execute(
"""insert into owners 
  162                           values (?,?,?,?)""", (stickid, uuid, tattoo, student))
 
  170     global database, cursor
 
  176     cursor.execute(
"select checkable from preferences")
 
  177     s = cursor.fetchone()
 
  178     newValues=(1, mv, prefs[
"schoolFile"], prefs[
"workdir"], prefs[
"manfile"])
 
  180         cursor.execute(
"""update preferences 
  181                           set checkable=?, mv=?, schoolfile=?, workdir=?, manfile=?""",
 
  184         cursor.execute(
"""insert into preferences 
  185                           values (?,?,?,?,?)""",