美文网首页python
python获取svn log记录到c++文件中

python获取svn log记录到c++文件中

作者: 岁月静好忄 | 来源:发表于2019-11-07 14:13 被阅读0次

c++项目的发布过程中为了记录项目svn的修订号和编译时间

要求

//跟新c++这段代码
string ver = "svn version(x86): 16378; 2019-11-07 14:00:07";

代码

#!/usr/bin/python
import os
import re
import datetime

codeBit = "x64"
def svnLastRevision():
    cmdContent = "svn log -l 1 此处填svn地址"
    print(cmdContent)
    rootLog = os.popen(cmdContent)
    res = rootLog.read()
    searchObj = re.search(r'r(.*?) ', res)
    if searchObj is None:
        print("No match!!")
        return None
    codeVersion = searchObj.group(1)
    if codeVersion is None:
        print("No group!!")
        return None
    else:
        return codeVersion
        
def versionStr():
    svnLR = svnLastRevision()
    if svnLR is None:
        return None
    nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    return "\tstring ver = \"svn version("+codeBit+"): "+svnLR+"; "+nowTime +"\";\n"
    
def updateFile(file):
    file_data = ""
    new_str = versionStr()
    with open(file, "r", encoding="utf-8") as f:
        for line in f:
            if "svn version" in line:
                line = line.replace(line,new_str)
            file_data += line
    with open(file, "w", encoding="utf-8") as f:
        f.write(file_data)

if __name__ == '__main__':
    updateFile("此处填c++文件地址")
    input()

相关文章

网友评论

    本文标题:python获取svn log记录到c++文件中

    本文链接:https://www.haomeiwen.com/subject/gyqvbctx.html