1.git 获取差异
import os
os.chdir('/Users/xxx/Documents/git/mjjh')
os.system('git diff HEAD 190f4a6 --name-only game/src game/res | xargs zip /Users/xxx/Desktop/update/update.zip')
2.编译luac
# -*- coding: utf-8 -*-
import os
import shutil
os.chdir("/Users/xxx/Desktop/update")
print("-- 清理解压出来打文件夹 game")
if os.path.exists("/Users/xxx/Desktop/update/game"):
shutil.rmtree("/Users/xxx/Desktop/update/game")
print("-- 清理结束 --")
print("-- 解压文件 --")
os.system("unzip update.zip")
print("-- 解压完成 --")
print("-- 清空version目录 ")
if os.path.exists("/Users/xxx/Desktop/update/version"):
shutil.rmtree("/Users/xxx/Desktop/update/version")
os.mkdir("/Users/xxx/Desktop/update/version")
print("-- 清空version目录 end ")
print("-- 编译luac 文件 --")
os.system('cocos luacompile -s /Users/xxx/Desktop/update/game/src -d /Users/xxx/Desktop/update/version/src -e -k xxx -b xxx --disable-compile')
print("-- 编译luac 文件 end--")
print("-- 复制pb文件 ")
if os.path.exists("/Users/xxx/Desktop/update/game/src/app/pb"):
shutil.copytree("/Users/xxx/Desktop/update/game/src/app/pb","/Users/xxx/Desktop/update/version/src/app/pb")
print("-- 复制pb文件 end ")
else:
print("--pb文件夹不存在,跳过复制--")
print("-- 复制res文件 ")
shutil.copytree("/Users/xxx/Desktop/update/game/res","/Users/xxx/Desktop/update/version/res")
print("-- 复制res文件 end ")
3.createManifest
#coding:utf-8
import os
import hashlib
import time
import sys
def getFileMd5(filename):
if not os.path.isfile(filename):
return
myhash = hashlib.md5()# create a md5 object
f = file(filename,'rb')
while True:
b = f.read(8096)# get file content.
if not b :
break
myhash.update(b)#encrypt the file
f.close()
return myhash.hexdigest()
def walk(path, prefix):
global xml
fl = os.listdir(path) # get what we have in the dir.
for f in fl:
if f.find('.') == 0: # for .DS_Store
continue
if os.path.isdir(os.path.join(path,f)): # if is a dir.
if prefix == '':
walk(os.path.join(path,f), f)
else:
walk(os.path.join(path,f), prefix + '/' + f)
else:
md5 = getFileMd5(os.path.join(path,f))
fileInfo = os.path.splitext(f)
print(fileInfo)
if fileInfo[1] == '.zip':
xml += "\n\t\t\"%s\" : {\n\t\t\t\"md5\" : \"%s\"\n\t\t\t\"compressed\" : true\n\t\t}, " % (prefix + '/' + f, md5)
else:
xml += "\n\t\t\"%s\" : {\n\t\t\t\"md5\" : \"%s\"\n\t\t}, " % (prefix + '/' + f, md5) # output to the md5 value to a string in xml format.
if __name__ == "__main__":
timeStr = time.strftime("%Y%m%d%H%M%S",time.localtime(time.time()))
#if not os.path.exists(os.getcwd() + '/manifest'):
#os.mkdir(os.getcwd() + '/manifest')
#generate project.manifest
xml = '{\
\n\t"packageUrl" : "http://xx/update/",\
\n\t"remoteVersionUrl" : "http://xx/update/version.manifest",\
\n\t"remoteManifestUrl" : "http://xx/update/project.manifest",\
\n\t"version" : "0.0.%s",\
\n\t"engineVersion" : "Cocos2d-x v3.10",\
\n\n\t"assets" : {' % timeStr
walk('/Users/xxx/Desktop/update/version', '')
xml = xml[:-2]
xml += '\n\t},\
\n\t"searchPaths" : [\
\n\t]\
\n}'
f = file("/Users/xxx/Desktop/update/version/project.manifest", "w+")
f.write(xml)
print 'generate version.manifest finish.'
#generate version.manifest
xml = '{\
\n\t"packageUrl" : "http://xx/update/",\
\n\t"remoteVersionUrl" : "http://xx/update/version.manifest",\
\n\t"remoteManifestUrl" : "http://xx/update/project.manifest",\
\n\t"version" : "0.0.%s",\
\n\t"engineVersion" : "Cocos2d-x v3.10"\n}' % timeStr
f = file("/Users/xxx/Desktop/update/version/version.manifest", "w+")
f.write(xml)
print 'generate version.manifest finish.'