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

Source Code for Module cxf_pyxmaker

  1  #!/usr/bin/env python 
  2  #-*- coding:utf-8 -* 
  3   
  4   
  5  """ 
  6          Manage the interface with cx_freeze 
  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 shutil 
 34  import subprocess 
 35   
 36   
 37   
 38   
 39  #=======================================================================# 
 40  #                               classe gérant la connexion avec cx_freeze                              # 
 41  #=======================================================================# 
42 -class CxfPyxmaker():
43 """ 44 Class whichinterface Pyxmaker and cx_freeze 45 46 G{classtree} 47 """ 48 49 50 #===================================================# 51 # Fenetre Confirmation # 52 #===================================================#
53 - def __init__(self):
54 None
55 56 57 58 59 #===================================================# 60 # Procedure de creation de la structure # 61 #===================================================#
62 - def p_struct_creation(self, dict_param):
63 """ 64 Allow to create the setup directory in the output repertory 65 66 PARAMETERS 67 ========== 68 dict_param 69 ---------- 70 A dictionnary with all needed parameters 71 72 RETURNS 73 ======= 74 None 75 """ 76 src = dict_param["DIR_PJ"] 77 dst = dict_param["PJ_PATH"] 78 shutil.rmtree(dict_param["STRUCT_PATH"], True) 79 shutil.copytree(src, dst)
80 81 82 83 84 #===================================================# 85 # Procedure de creation du script cx_freeze # 86 #===================================================#
87 - def p_script_creation(self, dict_param):
88 """ 89 Allow to create the setup directory in the output repertory 90 91 PARAMETERS 92 ========== 93 dict_param 94 ---------- 95 A dictionnary with all needed parameters 96 97 RETURNS 98 ======= 99 None 100 """ 101 path = os.path.join(dict_param["SCRIPTS_PATH"], "script_cxf.py") 102 with open(path, 'r') as fichier: 103 script = fichier.read() 104 fichier.close() 105 106 script = script.replace("$$INCLUDES$$", dict_param["CXF_INCLUDE"]) 107 script = script.replace("$$EXCLUDES$$", dict_param["CXF_EXCLUDE"]) 108 script = script.replace("$$PACKAGES$$", dict_param["CXF_PACKAGE"]) 109 script = script.replace("$$INCLUDE_FILES$$", dict_param["CXF_INCLUDE_FILE"]) 110 script = script.replace("$$NAME_EXEC$$",dict_param["EXECUTABLE"]) 111 script = script.replace("$$NAME$$",dict_param["NAME"]) 112 script = script.replace("$$VERSION$$",dict_param["VERSION"]) 113 script = script.replace("$$DESCRIPTION$$",dict_param["DESCRIPTION"]) 114 script = script.replace("$$AUTHOR$$",dict_param["AUTHOR"]) 115 script = script.replace("$$AUTHOR_MAIL$$",dict_param["AUTHOR_MAIL"]) 116 script = script.replace("$$MAINTAINER$$",dict_param["MAINTAINER"]) 117 script = script.replace("$$MAINTAINER_MAIL$$",dict_param["MAINTAINER_MAIL"]) 118 script = script.replace("$$WEBSITE$$",dict_param["WEBSITE"]) 119 script = script.replace("$$WINCONS$$",dict_param["WINCONS"]) 120 121 if dict_param["ICON_EXEC"] <> "": 122 script = script.replace("$$ICON_EXEC$$",dict_param["ICON_EXEC"]) 123 else: 124 script = script.replace("\n icon = \"$$ICON_EXEC$$\",","") 125 126 if dict_param["ICON"] <> "": 127 script = script.replace("$$ICON$$",dict_param["ICON"]) 128 else: 129 script = script.replace("\n icon = \"$$ICON$$\",","") 130 131 path = os.path.join(dict_param["PJ_PATH"], "script.py") 132 with open(path, "w") as fichier: 133 fichier.write(script) 134 fichier.close()
135 136 137 138 139 #===================================================# 140 # Fonction générant l'executable # 141 #===================================================#
142 - def f_exe_creation(self, dict_param):
143 """ 144 Allow to create the setup directory in the output repertory 145 146 PARAMETERS 147 ========== 148 dict_param 149 ---------- 150 A dictionnary with all needed parameters 151 152 RETURNS 153 ======= 154 None 155 """ 156 cmd0 = dict_param["PJ_PATH"] 157 cmd0 = r"%s"%(cmd0,) 158 cmd1 = "python script.py build & exit\n" 159 stdout_file = open(os.path.join(dict_param["STRUCT_PATH"],"cxf_log.log"), "w+") 160 proc = subprocess.Popen(cmd1, shell=True, cwd=cmd0, stdout=stdout_file, stderr=subprocess.STDOUT) 161 proc.communicate() 162 stdout_file.seek(0) 163 stdout = stdout_file.read() 164 #cwd indique le chemin ou s'execute la commande 165 proc.wait() 166 #on attend la fin de l'execution de la commande 167 168 with open(os.path.join(dict_param["STRUCT_PATH"],"cxf_log.log"), "r") as log: 169 contenu = log.read().lower() 170 if contenu.find("cannot") <> -1 or contenu.find("problem") <> -1 or \ 171 contenu.find("error") <> -1: 172 return 2 173 elif contenu.count("warning") > 2: 174 return 2 175 else: 176 return 0 177 178 log.close()
179 180 181 #===================================================# 182 # Procedure generant le zip du standalone # 183 #===================================================#
184 - def p_zip_standalone(self, dict_param):
185 """ 186 Allow to generate the zip that contains the standalone version 187 188 PARAMETERS 189 ========== 190 dict_param 191 ---------- 192 A dictionnary with all needed parameters 193 194 RETURNS 195 ======= 196 None 197 """ 198 path_dir = os.path.join(dict_param["PJ_PATH"],"build") 199 exe = os.listdir(path_dir)[0] 200 path_zip = os.path.join(dict_param["STRUCT_PATH"], dict_param["NAME"] + "_" + dict_param["VERSION"] + "_" + "standalone") 201 shutil.make_archive(path_zip, "zip", path_dir + exe)
202 203 204 205 206 #===================================================# 207 # Procedure effaçant la partie cxf de la structure # 208 #===================================================#
209 - def p_struct_del(self, dict_param):
210 """ 211 Allow to create the setup directory in the output repertory 212 213 PARAMETERS 214 ========== 215 dict_param 216 ---------- 217 A dictionnary with all needed parameters 218 219 RETURNS 220 ======= 221 None 222 """ 223 shutil.rmtree(dict_param["PJ_PATH"], True)
224 225 226 227 228 #=======================================================================# 229 # Main de la classe # 230 #=======================================================================# 231 if __name__ == "__main__": 232 None 233