自动以jenkins的build-number作为版本号
#!/usr/bin/python# -*- coding: UTF-8 -*-import sysimport stringimport reimport timeimport os## resource file#rc_list = [os.getcwd() + "/../aaa/aaa.rc",os.getcwd() + "/../bbb/bbb.rc",os.getcwd() + "/..
·
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import string
import re
import time
import os
#
# resource file
#
rc_list = [
os.getcwd() + "/../aaa/aaa.rc",
os.getcwd() + "/../bbb/bbb.rc",
os.getcwd() + "/../ccc/ccc.rc"
]
#
# get yday
#
yday = time.localtime(time.time())[7]
#
# get jenkins BUILD_NUMBER
#
build_number = os.environ.get('BUILD_NUMBER')
if not build_number:
build_number = str(yday)
#
# change rivision & build_number only
# FILEVERSION 3,6,0,6
# PRODUCTVERSION 3,6,0,6
#
def make_new_version(line_str):
idx1 = line_str.find(',')
idx2 = line_str.find(',', idx1+1)
prefix_str = line_str[:idx2+1]
new_ver = prefix_str + str(yday) + "," + build_number + "\n"
return new_ver
#
# change rivision & build_number only
# " VALUE \"FileVersion\", \"3.6.0.6\""
# " VALUE \"ProductVersion\", \"3.6.0.6\""
#
def make_new_string_version(line_str):
idx1 = line_str.find('.')
idx2 = line_str.find('.', idx1+1)
prefix_str = line_str[:idx2+1]
new_ver = prefix_str + str(yday) + "." + build_number + "\"\n"
return new_ver
#
# main
#
if __name__ == "__main__":
for rc in rc_list:
f = open(rc, 'r+', encoding='utf-8')
lines = f.readlines()
content = []
for line in lines:
tmp = re.split('\s+', line)
if re.search('FILEVERSION ', line) or re.search('PRODUCTVERSION ', line):
new_ver = make_new_version(line)
content.append(new_ver)
print("rc file : ", rc_file)
print(new_ver)
elif re.search('VALUE \"FileVersion\", \"', line) or re.search('VALUE \"ProductVersion\", \"', line):
new_ver = make_new_string_version(line)
content.append(new_ver)
print("rc file : ", rc_file)
print(new_ver)
else:
content.append(line)
f.seek(0)
f.writelines(content)
f.close()
更多推荐
已为社区贡献1条内容
所有评论(0)