#!/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()    



Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐