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

Source Code for Module save_load_pyxmaker

  1  #!/usr/bin/env python 
  2  #-*- coding:utf-8 -* 
  3   
  4   
  5  """ 
  6          Manage the project configuration file 
  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   
 34   
 35   
 36   
 37  #=======================================================================# 
 38  #                classe gérant le fichier de sauvegarde                # 
 39  #=======================================================================# 
40 -class FileSaveLoad():
41 """ 42 Class which manage the save file 43 44 G{classtree} 45 """ 46 47 48 #===================================================# 49 # Init # 50 #===================================================#
51 - def __init__(self):
52 None #structure de type text. ex: LANG=FRANCAIS
53 54 55 56 57 #===================================================# 58 # Sauvegarde # 59 #===================================================#
60 - def p_file_save(self, path, dict_param):
61 """ 62 Init of BddPyxmaker object 63 64 PARAMETERS 65 ========== 66 path_base 67 --------- 68 the path of software execution 69 70 RETURNS 71 ======= 72 None 73 """ 74 with open(path, 'w') as f_config: 75 for key, value in dict_param.items(): 76 f_config.write(key + "=" + value + "\n") 77 f_config.close()
78 79 80 81 82 #===================================================# 83 # Chargement # 84 #===================================================#
85 - def f_file_load(self, path):
86 """ 87 Init of BddPyxmaker object 88 89 PARAMETERS 90 ========== 91 path_base 92 --------- 93 the path of software execution 94 95 RETURNS 96 ======= 97 None 98 """ 99 dict_param = {} 100 101 with open(path, 'r') as f_config: 102 f_line = f_config.readline() 103 while f_line <> "": 104 out = f_line.split('=') 105 dict_param[out[0]] = out[1].replace("\n","") 106 f_line = f_config.readline() 107 108 return dict_param
109 110 111 112 #=======================================================================# 113 # Main de la classe # 114 #=======================================================================# 115 if __name__ == "__main__": 116 obj = FileSaveLoad() 117 path = "" 118 print obj.f_file_load(path) 119