python打包成安装程序_python 自动化打包程序exe安装文件

classPackagePc(object):def __init__(self, args):

self.workPath=WORK_PATH

self.vsDevCmd= "VsDevCmd.bat"self.compileCommand= ""self.compilePath= ""self.issPath= ""self.packConfig= utils.parse_json(os.path.join(self.workPath, "package.json"))

self.projectName= self.packConfig.get("projectName")

self.projectSlnPath= utils.flat_path(os.path.join(self.workPath, '../../../frameworks/runtime-src/proj.win32/'))

self.compilePath= "{}{}".format(self.packConfig.get("compileType"), ".win32")

self.assetsPath= "{}{}{}".format(self.projectSlnPath, "\\", self.compilePath)

self.useLessFileList= ['.pdb', '.ilk', '.lib', '.log', '.obj', '.exp', '.js', '.idb', ".res"]defbuildPcPack(self):#初始化项目Sln

self.initProjectSln()#编译C++工程

self.compileCPlus()#压缩图片资源

self.doPngQuant()#js转化jsc

self.compileJsFile()#删除VS生成多余文件

self.removeUselessFile(self.useLessFileList)#加密

self.doEncrypt()#删除jsc

self.removeUselessFile(['.jsc'])#生成exe安装包

self.setUpISS()#初始化编译命令

definitProjectSln(self):

slnName= self.packConfig.get("sln")if notslnName:

raise_known_error('没有配置项目sln名', KnownError.ERROR_WRONG_CONFIG)

self.compileCommand= "{}{}{}{}{}{}".format("devenv", self.projectSlnPath , "\\" , slnName, ".sln", "/rebuild release")#编译C++工程

defcompileCPlus(self):print(u"----------开始编译C++工程----------")

utils.run_shell("%s & %s" %(self.vsDevCmd, self.compileCommand))#压缩图片资源

defdoPngQuant(self):print(u"----------开始压缩图片资源----------")

excludeDict= {"exclude_files": ["gg_s9_res"], "exclude_folders": ["games", "src/libs/images/native/native_s9_res"]}

quant=png_quant.PngQuant(self.assetsPath, excludeDict)

quant.compress_images_in_path()#压缩js文件

defcompileJsFile(self):print(u"----------开始js转化jsc----------")if notos.path.exists(self.assetsPath):print("compileJsFile path not found =" +self.assetsPath)returncompilePath= utils.flat_path(os.path.join(self.workPath, '../../../frameworks/cocos2d-x/tools/cocos2d-console/bin/cocos'))

compileCmd= "%s jscompile -s %s -d %s" %(compilePath, self.assetsPath, self.assetsPath)

utils.run_shell(compileCmd)#资源加密

defdoEncrypt(self):print(u"----------开始资源加密----------")

ASSETS_ENCRYPT_EXCLUDE_CFG= ["games/mj_common/images/card_packer/*.png"]

encrypt=ResEncrypt(self.assetsPath, self.assetsPath, False, ASSETS_ENCRYPT_EXCLUDE_CFG, True, False)

encrypt.do_encrypt()#删除项目中无用的文件

defremoveUselessFile(self, fileList):print(u"----------开始删除VS生成多余文件----------")for parent, dirNames, fileNames inos.walk(self.assetsPath):for fileFullName infileNames:if os.path.splitext(fileFullName)[1] infileList:print("file %s"%(os.path.join(parent, fileFullName)))

os.remove(os.path.join(parent, fileFullName))#生成exe安装包

defsetUpISS(self):print(u"----------开始生成exe安装包----------")

issPath= utils.flat_path(os.path.join(self.workPath, '../../../tools/hall/PackPC/'))

devCmd= "{}{}".format("cd", os.path.join(issPath, "InnoSetup"))

issCmd= "{}{}".format("iscc", os.path.join(issPath, "build.iss"))

self.issPath= os.path.join(issPath, "build.iss")if notos.path.exists(self.issPath):

raise_known_error("找不到ISS文件", KnownError.ERROR_OTHERS)

self.modifyISS(issPath, False)

utils.run_shell("%s & %s & %s" % (devCmd, "ISCC.exe", issCmd))

self.modifyISS(issPath, True)#修改、还原Inno Setup打包配置

defmodifyISS(self, issPath, isReduction):

with open(self.issPath,"rb") as f:

data=f.read()

f.close()

cfgVersion= self.packConfig.get("version").decode('utf8').encode('gb2312')ifisReduction:

data= data.replace(cfgVersion, "GameVersion")

data= data.replace(self.assetsPath, "PCProjectPath")

data= data.replace(issPath, "IcoPath")

data= data.replace("xxxxxPC" + cfgVersion + "-Setup", "OutputFilename")else:

data= data.replace("GameVersion", cfgVersion)#修改版本号

data = data.replace("PCProjectPath", self.assetsPath)#修改项目路径名

data = data.replace("IcoPath", issPath)#修改ICO路径

data = data.replace("OutputFilename","xxxxxPC" + cfgVersion + "-Setup")

with open(self.issPath,"wb") as f:

f.write(data)

f.close()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值