# -*-coding:utf-8 -*- import shutil, os import time inspurPath = os.path.abspath('.') + '\party-web' inspurInnerPath = os.path.abspath('.') + '\party-webZip' inspurZipPath = os.path.abspath('.') + '\party-web.zip' distPath = os.path.abspath('.') + '\party-web' zipPath = 'D:\Project\Zip' isOnLine = True def deleteFile(isDelete): if os.path.exists(distPath): shutil.rmtree(distPath) if os.path.exists(inspurPath): shutil.rmtree(inspurPath) if isDelete: if os.path.exists(inspurZipPath): os.remove(inspurZipPath) if os.path.exists(inspurInnerPath): shutil.rmtree(inspurInnerPath) def buildModel(): rootPath = os.path.abspath('.') print('########### run build ############') # 打包命令 cmd = 'npm run build:prod' # 切换到需要项目目录 os.chdir(rootPath) # 当前项目目录下执行打包命令 if os.system(cmd) == 0: # 打包完成 print('########### build complete ############') # 判断文件是否存在 def isExitFile(pathString): if os.path.exists(pathString): return True; else: return False; # 创建文件夹 def isCreateFile(pathStrring): if isExitFile(pathStrring) == False: os.makedirs(pathStrring) def moveFile(zipName): if os.path.exists(distPath): isCreateFile(inspurInnerPath) if isExitFile(distPath): shutil.move(distPath, inspurInnerPath) # for filename in os.listdir(distPath): # if filename.endswith('static'): # shutil.copytree(os.path.join(distPath, filename), os.path.join(inspurInnerPath, filename)) # elif filename == 'html': # shutil.copytree(os.path.join(distPath, filename), os.path.join(inspurInnerPath, filename)) # else: # shutil.copy(os.path.join(distPath, filename), os.path.join(inspurInnerPath, filename)) print('*************zip*************') # zipName = time.strftime("%Y-%m-%d-%H%M%S") shutil.make_archive(zipPath + '\party-web'+ zipName, 'zip', inspurInnerPath); deleteFile(True) buildModel() zipName = 'party-web' if isOnLine: zipName = time.strftime("%Y-%m-%d-%H%M%S") moveFile(zipName) deleteFile(True) print('cd /usr/local/tomcat/webapps') print('unzip party-web' + zipName + '.zip') print('*************finished*************') os.startfile(zipPath)