python生成version.h

原创文章禁止转载 同步发布python生成version.h

代码

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import re
import os


def open_file(name, flag):
    try:
        f = open(name, flag)
        return f
    except BaseException:
        return None
    return None

def run():
    try:
        rd = os.popen("svn info | findstr Revision:")
        revision = rd.read()
        search = re.search("\d+", revision)
        if not search:
            return False
        ver = search.group()
        fver = open_file("version.h", 'w+')
        fver.write("#ifndef __MMM__VERSION_H__\n")
        fver.write("#define __MMM__VERSION_H__\n")
        ver = "1.0.0."+ver
        print("version "+ver)
        fver.write("#define VERSION \""+ver+"\"\n")
        fver.write("#endif //__MMM__VERSION_H__\n")
        fver.close()
        
        return True
    except BaseException:
        return False
    return False



if __name__ == "__main__":
    if not run():
        print('make ver error!')


Logo

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

更多推荐