1
2
3
4
5 """
6 Manage the database connection
7
8 G{importgraph}
9 """
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 import sqlite3
32 import sys
33 import os
34
35
36
37
38
39
40
42 """
43 Allow to access to the SQLite dataBase of Pyxmaker
44
45 G{classtree}
46 """
47
48
49
50
51
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
78
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
109
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
139
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
169
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
202
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
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