python 打印程序编译的时间

本文介绍了一个Python脚本,该脚本用于管理C语言工程,并添加功能在编译时自动更新源代码中定义的BUILD_TIME为当前日期时间,确保版本信息清晰。脚本首先查找并替换源文件中特定字符串,然后切换到构建目录,清除旧文件,执行cmake和make命令进行编译。
摘要由CSDN通过智能技术生成
这是一个管理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")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值