【tool】动态注释LOG_NDEBUG宏定义
前言
需要动态打开代码中最前端定义的LOG_NDEBUG,关闭注释则log文件中可以看到该code中的等级为v的log。
可是有时候需要git pull代码,就需要退回去,很麻烦,所以编写了一个python脚本,动态修改dynamic_log_file_path.txt中列出来code路径文件的宏定义,取消掉注释。
根据该dynamic_log_file_path.txt文件中第一个cpp文件,然后决定后续文件是打开log还是关闭log。
如果第一个文件中该宏定义为注释掉,则后续会将所有的code文件都取消掉该注释(打开log)。第二次运行该python脚本则再加上注释(关闭log)。
PS:不用担心执行两次打开或执行两次关闭。
代码
存储需要修改的code路径放入dynamic_log_file_path.txt中
代码:dynamic_log_open_v.py
# file ---- dynamic_log_open_v.py# replay "#define LOG_NDEBUG 0" to "define LOG_NDEBUG 0"import osdef open_logNDEBUG (filename_code):# deal with code# filename_code = line_codepathfilename_code = filename_code.strip()print(filename_code)file_code = open(filename_code, 'r+')line_code = file_code.readline()lineseek_num = 0status_in_define=Falsewhile line_code:# print(line_code)# print("lineseek_num",lineseek_num)status_define_in_codeline = Falsestatus_define_in_codeline = "LOG_NDEBUG" in line_codeif status_define_in_codeline == True:line_code = line_code.replace('//#define LOG_NDEBUG 0','#define LOG_NDEBUG 0 ')line_code = line_code.replace('\n','')# linenum=lineseek_num-1# print(file_code.tell())file_code.seek(lineseek_num)file_code.write(line_code)# print("lineseek_num---",lineseek_num)# print(line_code)status_in_define = Truebreakstatus_include_in_codeline = "include" in line_codeif status_include_in_codeline == True:if status_in_define == True:break# print("last seek",file_code.tell())lineseek_num = file_code.tell()line_code = file_code.readline()file_code.closeprint("-leave open_logNDEBUG")returndef close_logNDEBUG (filename_code):# deal with code# filename_code = line_codepathfilename_code = filename_code.strip()file_code = open(filename_code, 'r+')line_code = file_code.readline()lineseek_num = 0status_in_define=Falsewhile line_code:# print(line_code)# print("lineseek_num",lineseek_num)status_define_in_codeline = Falsestatus_define_in_codeline = "LOG_NDEBUG" in line_codeif status_define_in_codeline == True:line_code = line_code.replace('#define LOG_NDEBUG 0 ','//#define LOG_NDEBUG 0')# line_code = line_code.replace('\n','')# linenum=lineseek_num-1# print(file_code.tell())file_code.seek(lineseek_num)file_code.write(line_code)# print("lineseek_num---",lineseek_num)# print(line_code)status_in_define = Truebreakstatus_include_in_codeline = "include" in line_codeif status_include_in_codeline == True:if status_in_define == True:break# print("last seek",file_code.tell())lineseek_num = file_code.tell()line_code = file_code.readline()file_code.closeprint("-leave open_logNDEBUG")returndef judge_open_close_log(line_codepath_temp):status_o_c_log_temp = Falseline_codepath_temp = line_codepath.strip()file_first_code = open(line_codepath_temp)line_first_code = file_first_code.readline()while line_first_code:status_judge_log = "LOG_NDEBUG" in line_first_codeif status_judge_log == True:status_o_c_log_temp = '//#define LOG_NDEBUG 0' in line_first_codeif status_o_c_log_temp == True:breakline_first_code = file_first_code.readline()return status_o_c_log_templog_file_path = "dynamic_log_filepath.txt"file_logcode_path = open(log_file_path)
line_codepath=file_logcode_path.readline()status_o_c_log = False
status_o_c_log = judge_open_close_log(line_codepath)
file_logcode_path.closewhile line_codepath:print(line_codepath)if status_o_c_log == True:open_logNDEBUG(line_codepath)print("open log")else:close_logNDEBUG(line_codepath)print("close log")# deal with code# open/close 2 no error# open_logNDEBUG(line_codepath)# close_logNDEBUG(line_codepath)line_codepath=file_logcode_path.readline()print("close file_logcode_path")
file_logcode_path.close
测试
在android路径下,执行repo status > a.text
该脚本打开log后关闭,不会影响到当前git状态,即不会提示需要git add .添加修改。
【tool】动态注释LOG_NDEBUG宏定义相关推荐
- 【C 语言】编译过程 分析 ( 预处理 | 编译 | 汇编 | 链接 | 宏定义 | 条件编译 | 编译器指示字 )
相关文章链接 : 1.[嵌入式开发]C语言 指针数组 多维数组 2.[嵌入式开发]C语言 命令行参数 函数指针 gdb调试 3.[嵌入式开发]C语言 结构体相关 的 函数 指针 数组 4.[嵌入式开发 ...
- 巧用c语言宏定义实现自动注释调试代码,C语言宏定义中的特殊用法
C宏定义中的特殊用法 在分析一些C源码时,经常会遇到各种宏定义操作,本文即总结一下C语言宏定义中常见的预定义宏.调试宏:宏的条件编译用法及特殊的宏关键字用法. #undef 限定宏的作用域 一般来讲宏 ...
- 宏定义与预处理、函数和函数库
以下内容源于朱有鹏嵌入式课程的学习,如有侵权,请告知删除. 一.C语言预处理理论 1.由源码到可执行程序的过程 源码.c->(编译)->elf可执行程序 源码.c->(编译)-> ...
- 6、宏定义与预处理、函数与函数库
C语言预处理理论 由源码到可执行程序的过程 源码.c->(编译)->elf可执行程序 源码.c->(编译)->目标文件.o->(链接)->elf可执行程序 源码.c ...
- VC预处理指令与宏定义的妙用
VC中预处理指令与宏定义的妙用 刚接触到MFC编程的人往往会被MFC 向导生成的各种宏定义和预处理指令所吓倒,但是预处理和宏定义又是C语言的一个强大工具.使用它们可以进行简单的源代码控制,版本控制,预 ...
- GetLastErr返回值ErrCode的宏定义以及含义
参考链接:https://docs.microsoft.com/en-us/previous-versions/aa911366(v=msdn.10)?redirectedfrom=MSDN 十进制 ...
- python怎么宏定义符号变量_python中定义宏
广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 什么是宏? 宏类似python中的函数,可以传参数进去,但不能有返回值! 在实际 ...
- VC宏定义 及常用宏定义说明
1. 宏定义的格式 宏定义的一般格式是: #define 标识符 字符串 其中,标识符和字符串之间用空格隔开.标识符又称宏名,为了区别于一般变量,通常用英文大写字母表示:字符串又称宏体,可以是常 ...
- 如何用C语言改变宏定义的大小,C语言中宏定义使用的小细节
C语言中宏定义使用的小细节 #pragma#pragma 预处理指令详解 在所有的预处理指令中,#Pragma 指令可能是最复杂的了,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作.#p ...
最新文章
- 接口也可以创建对象吗_面试时,一个小小的设计模式可以把你虐成渣
- ebs和java哪个前景好_EBS与实例存储的好处(反之亦然)[关闭]
- NEFU705(数论+DP)
- c语言编2048,c语言编写的2048游戏代码,大家可以参考一下这些
- netcore 内存限制_.NET Core 和 Serverless 构建飞速发展的架构
- IT人的好习惯和不良习惯总结
- asp.net 浏览服务器文件
- SLAM GMapping(8)重采样
- NOIP 2013 货车运输
- ora-01031:insufficient privileges解决方法总结
- 谷歌应用程序无法启动,因为应用程序的并行配置不正确的问题解决方案
- linux里面ping地址停不下来解决方法
- MpAndroidChart Y轴显示整数
- 图数据库HugeGraph简介与快速入门
- 读论文——MoCo(何恺明 CV中的无监督)
- 三、SpringSecurity 动态权限访问控制
- 【两天搞定小米商城】【第三步】小米商城之导航部分
- 容器云虚拟主机云服务器,对比容器云和虚拟主机、云服务器
- java 反射练习_JAVA反射的基础学习
- PostgreSQL 优化器逻辑推理能力 源码解析