Module bdd_pyxmaker
[hide private]
[frames] | no frames]

Source Code for Module bdd_pyxmaker

  1  #!/usr/bin/env python 
  2  #-*- coding:utf-8 -* 
  3   
  4   
  5  """ 
  6          Manage the database connection 
  7           
  8          G{importgraph} 
  9  """ 
 10   
 11   
 12  #       Pyxmaker 
 13  #       Copyright (C) 2013 GALODE A. 
 14  # 
 15  #       This file is part of Expymaker. 
 16  #  
 17  #       Pyxmaker is free software: you can redistribute it and/or modify 
 18  #       it under the terms of the GNU General Public License as published by 
 19  #       the Free Software Foundation, either version 3 of the License, or 
 20  #       (at your option) any later version. 
 21  #  
 22  #       Pyxmaker is distributed in the hope that it will be useful, 
 23  #       but WITHOUT ANY WARRANTY; without even the implied warranty of 
 24  #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 25  #       GNU General Public License for more details. 
 26  # 
 27  #       You should have received a copy of the GNU General Public License 
 28  #       along with Pyxmaker.  If not, see <http://www.gnu.org/licenses/> 
 29   
 30   
 31  import sqlite3 
 32  import sys 
 33  import os 
 34   
 35   
 36   
 37   
 38  #=======================================================================# 
 39  #                               classe gérant la BDD                                           # 
 40  #=======================================================================# 
41 -class BddPyxmaker:
42 """ 43 Allow to access to the SQLite dataBase of Pyxmaker 44 45 G{classtree} 46 """ 47 48 49 #===================================================# 50 # Init # 51 #===================================================#
52 - def __init__(self, path_base) :
53 """ 54 Init of BddPyxmaker object 55 56 PARAMETERS 57 ========== 58 path_base 59 --------- 60 the path of software execution 61 62 RETURNS 63 ======= 64 None 65 """ 66 path = path_base 67 bdd_path = os.path.join(path, "03-BDD/pyxmaker.sqlite") 68 69 self.bdd_pyxmaker = sqlite3.connect(bdd_path) 70 self.bdd_pyxmaker.text_factory = str 71 self.bdd_pyxmaker.row_factory = sqlite3.Row
72 73 74 75 76 #===================================================# 77 # Lecture de la table about # 78 #===================================================#
79 - def f_read_about(self):
80 """ 81 Allow to read the about window information 82 83 PARAMETERS 84 ========== 85 None 86 87 RETURNS 88 ======= 89 A dictionary that contains the needed informations 90 91 """ 92 bdd_cursor = self.bdd_pyxmaker.cursor() 93 bdd_cursor.execute("SELECT PARAM, VALUE \ 94 FROM ABOUT") 95 dict_about = {} 96 for r in bdd_cursor: 97 dict_about[r[0]] = r[1] 98 99 bdd_cursor.close() 100 101 102 return dict_about
103 104 105 106 107 #===================================================# 108 # Lecture de la table config # 109 #===================================================#
110 - def f_read_config(self):
111 """ 112 Allow to read the config information 113 114 PARAMETERS 115 ========== 116 None 117 118 RETURNS 119 ======= 120 A dictionnary that contains the config information 121 122 """ 123 bdd_cursor = self.bdd_pyxmaker.cursor() 124 bdd_cursor.execute("SELECT PARAM, VALUE \ 125 FROM CONFIG") 126 config_dict = {} 127 for r in bdd_cursor: 128 config_dict[r[0]] = r[1] 129 130 bdd_cursor.close() 131 132 return config_dict
133 134 135 136 137 #===================================================# 138 # MAJ de la table config # 139 #===================================================#
140 - def p_upd_config(self, param, new_value):
141 """ 142 Update config table 143 144 PARAMETERS 145 ========== 146 param 147 ----- 148 The parameter to update 149 new_value 150 --------- 151 the new value to assign to parameter 152 153 RETURNS 154 ======= 155 None 156 """ 157 bdd_cursor = self.bdd_pyxmaker.cursor() 158 bdd_cursor.execute("UPDATE CONFIG \ 159 SET VALUE = ? \ 160 WHERE PARAM = ?",(new_value, param)) 161 bdd_cursor.close() 162 self.bdd_pyxmaker.commit()
163 164 165 166 167 #===================================================# 168 # lecture du texte pour les menus # 169 #===================================================#
170 - def f_read_menu(self, language = "FRANCAIS"):
171 """ 172 Allow to read the text for the software's menu 173 174 PARAMETERS 175 ========== 176 language 177 -------- 178 The language selected by user. "FRANCAIS" by default 179 180 RETURNS 181 ======= 182 A list that contains all the menu text 183 184 """ 185 bdd_cursor = self.bdd_pyxmaker.cursor() 186 bdd_cursor.execute("SELECT SCREEN, PARAM, VALUE \ 187 FROM MENU \ 188 WHERE LANG = ?", (language,)) 189 menu_list = [] 190 for r in bdd_cursor: 191 menu_list.append(r) 192 193 bdd_cursor.close() 194 195 return menu_list
196 197 198 199 200 #===================================================# 201 # Lecture des differentes langues disponible # 202 #===================================================#
203 - def f_read_lang(self):
204 """ 205 Allow to read the different allowed languages 206 207 PARAMETERS 208 ========== 209 None 210 211 RETURNS 212 ======= 213 A list that contains the different allowed languages 214 215 """ 216 bdd_cursor = self.bdd_pyxmaker.cursor() 217 bdd_cursor.execute("SELECT DISTINCT LANG \ 218 FROM MENU") 219 lang_list = [] 220 for r in bdd_cursor: 221 lang_list.append(r) 222 223 bdd_cursor.close() 224 225 return lang_list
226 227 228 229 230 #=======================================================================# 231 # Main de la classe # 232 #=======================================================================# 233 if __name__ == '__main__': 234 try: 235 path = "" 236 bdd = BddPyxmaker(path) 237 config = bdd.f_read_config() 238 menu = bdd.f_read_menu() 239 about = bdd.f_read_about() 240 lang = bdd.f_read_lang() 241 print config 242 a = raw_input("ALL OK") 243 except: 244 print "erreur0:", sys.exc_info() 245 a = raw_input("\nKO") 246