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

Source Code for Module pyxmaker

  1  #!/usr/bin/env python 
  2  #-*- coding:utf-8 -* 
  3   
  4   
  5  """ 
  6          Manage pyxmaker software 
  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 os 
 32  import sys 
 33  import logging 
 34   
 35  import path_mkr 
 36  import ihm_pyxmaker 
 37  import bdd_pyxmaker 
 38  import cxf_pyxmaker 
 39  import setup_pyxmaker 
 40  import save_load_pyxmaker 
 41   
 42   
 43   
 44   
 45  #=======================================================================# 
 46  #                                               Classe gérant le logiciel                                              # 
 47  #=======================================================================# 
48 -class PyxmakerSoftware():
49 """ 50 Class which manage the Pyxmaker software 51 52 G{classtree} 53 """ 54 55 56 #===================================================# 57 # Init # 58 #===================================================#
59 - def __init__(self):
60 self.path_base = self.f_init_path() 61 logging.basicConfig(filename=os.path.join(self.path_base,"pyxmaker_log.log"), \ 62 level = logging.DEBUG, format="%(asctime)s-%(name)s-%(levelname)s-%(message)s") 63 logging.info("Pyxmaker initialisation") 64 65 self.bdd = self.f_init_bdd() 66 self.cxf = self.f_init_cxf() 67 self.setup = self.f_init_setup() 68 69 self.file_save_load = self.f_init_file_save_load() 70 71 dict_config, dict_about, list_menu, list_lang= self.f_bdd_read_base() 72 73 self.interface = self.f_init_ihm(list_menu, list_lang, dict_config, dict_about) 74 75 self.p_start_software()
76 77 78 79 80 #===================================================# 81 # Fonction d'init de la classe BddPyxmaker # 82 #===================================================#
83 - def f_init_bdd(self):
84 """ 85 Allow to create a BddPyxmaker object 86 87 PARAMETERS 88 ========== 89 None 90 91 RETURNS 92 ======= 93 A BddPyxmaker object 94 """ 95 logging.info("bdd_pyxmaker module initialisation") 96 97 bdd = bdd_pyxmaker.BddPyxmaker(self.path_base) 98 return bdd
99 100 101 102 103 #===================================================# 104 # Fonction d'init de la classe IhmPyxmaker # 105 #===================================================#
106 - def f_init_ihm(self, list_menu, list_lang, dict_config, dict_about):
107 """ 108 Allow to create a IhmPyxmaker object 109 110 PARAMETERS 111 ========== 112 list_menu 113 --------- 114 A list that contains the text of the different menu 115 list_lang 116 --------- 117 A list that contains the different allowed languages 118 dict_config 119 ----------- 120 A dictionnary that contains the software configuration 121 dict_about 122 ---------- 123 A dictionnary that contains the about windows informations 124 125 RETURNS 126 ======= 127 An IhmPyxmaker object 128 """ 129 logging.info("ihm_pyxmaker module initialisation") 130 131 ihm = ihm_pyxmaker.IhmPyxmaker(list_menu, list_lang, dict_config, dict_about, self.path_base, \ 132 self.f_config_save, self.f_config_open, self.f_lang_change, \ 133 self.p_mk_cxf) 134 135 return ihm
136 137 138 139 140 #===================================================# 141 # Fonction d'init pour obtenir le chamin d'exec # 142 #===================================================#
143 - def f_init_path(self):
144 """ 145 Allow to know the execution path 146 147 PARAMETERS 148 ========== 149 None 150 151 RETURNS 152 ======= 153 The execution path 154 """ 155 path_base = path_mkr.cxf_get_path() 156 return path_base
157 158 159 160 161 #===================================================# 162 # Fonction d'init de la classe CxfPyxmaker # 163 #===================================================#
164 - def f_init_cxf(self):
165 """ 166 Allow to create a CxfPyxmaker object 167 168 PARAMETERS 169 ========== 170 None 171 172 RETURNS 173 ======= 174 A CxfPyxmaker object 175 """ 176 logging.info("cxf_pyxmaker module initialisation") 177 178 cxf = cxf_pyxmaker.CxfPyxmaker() 179 return cxf
180 181 182 183 184 #===================================================# 185 # Fonction d'init de la classe SetupPyxmaker # 186 #===================================================#
187 - def f_init_setup(self):
188 """ 189 Allow to create a SetupPyxmaker object 190 191 PARAMETERS 192 ========== 193 None 194 195 RETURNS 196 ======= 197 A SetupPyxmaker object 198 """ 199 logging.info("setup_pyxmaker module initialisation") 200 201 setup = setup_pyxmaker.SetupPyxmaker() 202 return setup
203 204 205 206 207 #===================================================# 208 # Fonction d'init de la classe FileSaveLoad # 209 #===================================================#
210 - def f_init_file_save_load(self):
211 """ 212 Allow to create a FileSaveLoad object 213 214 PARAMETERS 215 ========== 216 None 217 218 RETURNS 219 ======= 220 A FileSaveLoad object 221 """ 222 logging.info("save_load_pyxmaker module initialisation") 223 224 file_save_load = save_load_pyxmaker.FileSaveLoad() 225 return file_save_load
226 227 228 229 230 #===================================================# 231 # Fonction de lecture des tables de la BDD # 232 #===================================================#
233 - def f_bdd_read_base(self):
234 """ 235 Allow to read the database tables 236 237 PARAMETERS 238 ========== 239 None 240 241 RETURNS 242 ======= 243 Two dictionnary for the configuration and about window 244 Two list for the text menu, and the allowed languages 245 """ 246 logging.info("Database reading, config, language, about, menu") 247 248 dict_config = self.bdd.f_read_config() 249 list_lang = self.bdd.f_read_lang() 250 dict_about = self.bdd.f_read_about() 251 list_menu = self.bdd.f_read_menu(dict_config["LANG"]) 252 253 return dict_config, dict_about, list_menu, list_lang
254 255 256 257 258 #===================================================# 259 # Procedure de MAJ de la table config # 260 #===================================================#
261 - def p_bdd_upd_config(self, param, new_value):
262 """ 263 Allow to update the config table 264 265 PARAMETERS 266 ========== 267 param 268 ----- 269 the parameter to update 270 new_value 271 --------- 272 the new value of the parameter 273 274 RETURNS 275 ======= 276 None 277 """ 278 logging.info("Databse update") 279 280 self.bdd.p_upd_config(param, new_value)
281 282 283 284 285 #===================================================# 286 # Fonction permettant la sauvegarde de la config # 287 #===================================================#
288 - def f_config_save(self, path, dict_param):
289 """ 290 Allow to save project configuration 291 292 PARAMETERS 293 ========== 294 path 295 ---- 296 The complete path of save file 297 dict_param 298 ---------- 299 A dictionnary with all needed parameters 300 301 RETURNS 302 ======= 303 None 304 """ 305 logging.info("Project configuration saving") 306 307 self.file_save_load.p_file_save(path, dict_param)
308 309 310 311 312 #===================================================# 313 # Fonction permettant de charger le fichier de save # 314 #===================================================#
315 - def f_config_open(self, path):
316 """ 317 Allow to create the setup directory in the output repertory 318 319 PARAMETERS 320 ========== 321 path 322 ---- 323 The complete path of save file 324 325 RETURNS 326 ======= 327 a dictionnary with all parameters 328 """ 329 logging.info("Project configuration loading") 330 331 dict_param = self.file_save_load.f_file_load(path) 332 return dict_param
333 334 335 336 337 #===================================================# 338 # Fonction gérant le changement de langue # 339 #===================================================#
340 - def f_lang_change(self, lang):
341 """ 342 Allow to change the IHM language 343 344 PARAMETERS 345 ========== 346 lang 347 ---- 348 The selected language 349 350 RETURNS 351 ======= 352 None 353 """ 354 logging.info("Language modification") 355 356 self.bdd.p_upd_config("LANG", lang)
357 358 359 360 361 #===================================================# 362 # Procedure lancant la generation de l'executable # 363 #===================================================#
364 - def p_mk_cxf(self, dict_param):
365 """ 366 Allow to create the windows executable 367 368 PARAMETERS 369 ========== 370 dict_param 371 ---------- 372 A dictionnary with all needed parameters 373 374 RETURNS 375 ======= 376 None 377 """ 378 try: 379 logging.info("cx_freeze structure creation") 380 self.cxf.p_struct_creation(dict_param) 381 382 logging.info("cx_freeze script creation") 383 self.cxf.p_script_creation(dict_param) 384 385 logging.info("executable creation with cx_freeze") 386 cxf = self.cxf.f_exe_creation(dict_param) 387 388 logging.info("standalone(zip) creation") 389 self.cxf.p_zip_standalone(dict_param) 390 391 logging.info("setup install call") 392 setup = self.p_mk_setup(dict_param) 393 394 logging.info("cx_freeze structure delete") 395 self.cxf.p_struct_del(dict_param) 396 397 if (not setup): 398 logging.error("Setup creation KO") 399 rtr == 1 400 else: 401 if cxf == 0: 402 logging.info("Standalone and setup creation successfull") 403 elif cxf == 1: 404 logging.error("executable creation KO") 405 elif cxf == 2: 406 logging.warning("Potentials problems on executable creation") 407 408 rtr = cxf 409 410 with open(os.path.join(self.path_base,"pyxmaker_log.log"), "r") as src: 411 contenu = src.read() 412 src.close() 413 414 with open(os.path.join(dict_param["STRUCT_PATH"],dict_param["NAME"] + "_creation.log"), "w") as dst: 415 dst.write(contenu) 416 dst.close() 417 418 logging.shutdown() 419 420 os.unlink(os.path.join(self.path_base,"pyxmaker_log.log")) 421 422 return rtr 423 424 except: 425 logging.error("standalone and setup creation KO") 426 427 with open(os.path.join(self.path_base,"pyxmaker_log.log"), "r") as src: 428 contenu = src.read() 429 src.close() 430 431 with open(os.path.join(dict_param["STRUCT_PATH"],dict_param["NAME"] + "_creation.log"), "w") as dst: 432 dst.write(contenu) 433 dst.close() 434 435 logging.shutdown() 436 437 return 1
438 439 440 441 442 #===================================================# 443 # Procedure lancant la generation de l'install # 444 #===================================================#
445 - def p_mk_setup(self, dict_param):
446 """ 447 Allow to create the setup install 448 449 PARAMETERS 450 ========== 451 dict_param 452 ---------- 453 A dictionnary with all needed parameters 454 455 RETURNS 456 ======= 457 None 458 """ 459 logging.info("setup structure creation") 460 self.setup.p_struct_creation(dict_param) 461 462 logging.info("setup script creation") 463 self.setup.p_script_creation(dict_param) 464 465 logging.info("setup creation with Inno Setup") 466 setup = self.setup.f_setup_creation(dict_param) 467 468 logging.info("setup moving") 469 self.setup.p_setup_move(dict_param) 470 471 logging.info("setup structure delete") 472 self.setup.p_struct_del(dict_param) 473 474 return setup
475 476 477 478 479 #===================================================# 480 # Procedure démarrant le logiciel # 481 #===================================================#
482 - def p_start_software(self):
483 """ 484 Allow to start the software 485 486 PARAMETERS 487 ========== 488 None 489 490 RETURNS 491 ======= 492 None 493 """ 494 self.interface.start_ihm()
495 496 497 498 499 #=======================================================================# 500 # Main de la classe # 501 #=======================================================================# 502 if __name__ == "__main__": 503 software = PyxmakerSoftware() 504