这是一个管理C工程的python脚本,添加了C程序打印文件编译的时间的功能,避免使用时候版本的混乱
1 #! /usr/bin/env python 2 import subprocess, os, sys 3 import fileinput 4 import datetime 5 6 - 7 def script(cmd): | 8 subprocess.call(cmd, shell=True) | 9 - 10 - 11 def changeBuildTime(): | 12 fname = "./src/main.cpp" | 13 match_string = "#define BUILD_TIME" | 14 for line in fileinput.input(fname, inplace=1): | 15 if line.find(match_string)>=0: | 16 line = """{0} "{1}" """.format(match_string, datetime.datetime.now()) | 17 print line | 18 else: | 19 print line, 20 # fhandle = open(fname, "r") 21 # while True: 22 # line = fhandle.readline() 23 # if not line: 24 # break 25 # if line.find(match_string) >= 0: 26 27 28 changeBuildTime() 29 os.chdir("./build") 30 script("rm -rf *") 31 script("cmake ..") 32 script("make -j 4")