import re
import os
import copy
import stat
curPath = os.path.split(__file__)[0] + "/"
def readAppStarterVersion(appStartRcPath):
appStartRcFileData = open(appStartRcPath, 'r', encoding='utf-16');
rcDatas = appStartRcFileData.readlines()
retVersionInfo=[]
pattern = re.compile(' FILEVERSION ([0-9]*),([0-9]*),([0-9]*),([0-9]*)')
for express in rcDatas:
res = re.search(pattern, express)
if res == None:
continue
retVersionInfo.append(res.group(1))
retVersionInfo.append(res.group(2))
retVersionInfo.append(res.group(3))
retVersionInfo.append(res.group(4))
return retVersionInfo
appStartRcFileData.close()
return retVersionInfo;
def UpdateVersion(appStartRcPath, oldVersion, newVersion):
# ��ȡ�ļ�����
appStartRcFileData = open(appStartRcPath, 'r', encoding='utf-16');
rcDatas = appStartRcFileData.readlines()
appStartRcFileData.close()
# ������滻�ĸ�ʽ
oldData1 = '.'.join(oldVersion)
oldData2 = ','.join(oldVersion)
fmt1 = '.'.join(newVersion)
fmt2 = ','.join(newVersion)
newrcData = []
for express in rcDatas:
express = express.replace(oldData1, fmt1).replace(oldData2, fmt2)
newrcData.append(express)
appStartRcFileData.close()
# ���
os.chmod(appStartRcPath, stat.S_IWRITE)
appStartRcFileData = open(appStartRcPath, 'w', encoding='ANSI');
appStartRcFileData.writelines(newrcData)
appStartRcFileData.close()
def replaceISSVersion(srcFilePath, verStr):
issFile = open(srcFilePath, 'r', encoding='gbk')
issContext = issFile.read(1024*300)
issContext = issContext.replace("[version]", verStr)
issFile.close()
issFile = open(srcFilePath, 'w', encoding='gbk')
issFile.write(issContext)
issFile.close()
if __name__=='__main__':
try:
# ����appStarter.exe��rc
rcFilePath = curPath+'../Project/GenerateZip/GenerateZip.rc'
# rcFilePath = 'D:\\GenerateZip\\Project\\GenerateZip\\GenerateZip.rc'
info = readAppStarterVersion(rcFilePath)
oldVersion = '.'.join(info)
print("old verion is "+ oldVersion)
newInfo = copy.copy(info)
newInfo[-1] = str(int(newInfo[-1])+1)
newVersion = '.'.join(newInfo)
print("new verion is "+ newVersion)
UpdateVersion(rcFilePath, info, newInfo)
except Exception as e:
i = 0
i+=1
评论0