我是靠谱客的博主 感性八宝粥,最近开发中收集的这篇文章主要介绍【sensor-SEE】python脚本更新sensor driver文件放置python代码结果,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
文件放置
在目录下放置py脚本和文件类型的txt。
文件夹来自高通目录:non_hlosadsp_procsscsensorsoem1
参考文章:80-P9301-67
key_file_type.txt中放置需要判断的文件后缀,用于检索这些文件。
//key_file_type.txt
.c
.h
.scons
python代码
import os
def judge_file_type(file_path_name,file_key):
print(file_path_name)
f_search=open(file_key)
log_search_type=f_search.readline()
log_search_type=log_search_type.strip()
while log_search_type:
print("type="+log_search_type)
status_searched=log_search_type in file_path_name
if status_searched==True:
f_search.close()
return True
log_search_type=f_search.readline()
log_search_type=log_search_type.strip()
f_search.close()
return False
def change_file_con (f_name, word_search, word_replace):
f_search=open(f_name)
f_name_replace=f_name.replace(word_search, word_replace)
print(f_name_replace)
f_replace=open(f_name_replace,'w')
log_line=f_search.readline()
while log_line:
word_search_up=word_search.upper()
word_replace_up=word_replace.upper()
status_has_key_1=word_search in log_line
status_has_key_2=word_search_up in log_line
# status_has_key=status_has_key_1+status_has_key_2
if status_has_key_1== True:
log_line=log_line.replace(word_search, word_replace)
if status_has_key_2 == True:
log_line=log_line.replace(word_search_up, word_replace_up)
f_replace.write(log_line)
log_line=f_search.readline()
f_replace.close()
f_search.close()
os.remove(f_name)
return
def replace_file_name(f_name,word_search, word_replace):
f_name_replace=f_name
f_name_replace=f_name_replace.replace(word_search,word_replace)
# print(os.path.isfile(f_name_replace),f_name_replace)
os.rename(f_name, f_name_replace)
# os.remove(file_path)
# print("==="+file_path)
# print("|||"+f_name_replace)
return
# init
def change_file_name(dir_name, file_key, word_search, word_replace):
for root, dirs, files in os.walk(dir_name):
for f in files:
if 'pass' in root:
continue
temp=word_search in f
if temp == True :
file_path=root
file_path_name=os.path.join(root, f) #log_file pathfilename
# print(log_file)
# judge file type (such as .c/.h)
status_f_type_searched=judge_file_type(file_path_name, file_key)
print(file_path_name,status_f_type_searched)
# # change file content
if status_f_type_searched==True:
# change file content & change file name
change_file_con(file_path_name, word_search, word_replace)
# else:
# # just change file name
# replace_file_name(file_path_name,word_search, word_replace)
# apply_file(log_file, result_excel_name)
dir_name=os.path.dirname(os.path.abspath(__file__))
print(dir_name)
file_key=dir_name+"key_file_type.txt"
word_search='oem1'
word_replace='mpu6050'
# print(word_search.upper())
# main
change_file_name(dir_name,file_key, word_search, word_replace)
结果
/*=============================================================================
@file sns_mpu6050.c
MPU6050 (template algorithm) implementation
Copyright (c) 2017 Qualcomm Technologies, Inc.
All Rights Reserved.
Confidential and Proprietary - Qualcomm Technologies, Inc.
===========================================================================*/
/*=============================================================================
Include Files
===========================================================================*/
#include "sns_sensor.h"
#include "sns_register.h"
#include "sns_mpu6050_sensor.h"
#include "sns_sensor_instance.h"
/*=============================================================================
External Variable Declarations
===========================================================================*/
extern sns_sensor_instance_api sns_mpu6050_sensor_instance_api;
extern sns_sensor_api sns_mpu6050_api;
/*=============================================================================
Public Function Definitions
===========================================================================*/
sns_rc sns_mpu6050_register(sns_register_cb const *register_api)
{
register_api->init_sensor(sizeof(sns_mpu6050_sensor_state),
&sns_mpu6050_api,
&sns_mpu6050_sensor_instance_api);
return SNS_RC_SUCCESS;
}
windows下查看命令:tree /f
最后
以上就是感性八宝粥为你收集整理的【sensor-SEE】python脚本更新sensor driver文件放置python代码结果的全部内容,希望文章能够帮你解决【sensor-SEE】python脚本更新sensor driver文件放置python代码结果所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复