参数传递sys.argv, 文件递归搜索os.walk
来源:互联网 发布:知乎 朱炫 西游记 编辑:程序博客网 时间:2024/06/05 18:52
使用sys.argv可以传递参数
sys.argv[0]表示代码本身文件路径
所以传入的文件从sys.argv[1], 开始算起,传入内容大概是以空格进行分割
有时传入的内容中,有特殊字符,注意用反斜线转义
输入命令,如下
find_case.py '\\CLK38M_PROC\[115\].U_CLK38M_2FF_SYNC.INST_COMMON_SYNC_SVA_CHK .ipdb_common_sync_glitch_chk'
或者
phthon change.py /home/eagle2.work/regression_simfab/log
code如下
import sysroot=sys.argv[1]
或者,全代码
#!/usr/bin/env pythonimport osimport reimport syschecker_log =sys.argv[1]root='/home/eagle2.work3/regression_simfab/XG756_C0/XG756_C0_SPEC_3_3_SOC_TB_sva_case_search'search_argu=[['check_logfiles.log.bz2'],['sf_tc.store','check_logfiles.log'],['<result>FAILED','<item>check_logs failed']]def detect():#ergodic the files in path root #search_argu[1] is the two search search_arguments in file2 i=0 global check_file1 global check_file2 global rt for rt,dirs,files in os.walk(root):#ergodic the files in path root for file in files: i+=1 #print(i) #detect zip file # print(rt) path=rt+'/' pathlist=os.listdir(path) for filename in pathlist: if filename.endswith(str(search_argu[0][0])): # print("*******need to bunzip first********") order1='cd '+path+' && bunzip2 '+filename # print(rt) os.system(order1) else: pass if (pathlist.count(search_argu[1][0])==0) or (pathlist.count(search_argu[1][1])==0): i+=1 # print('file not found') # print(i) break try: check_file1=path+search_argu[1][0] check_file2=path+search_argu[1][1] except FileNotFoundError: # print('can not find files') sys.exit() check2(check_file2) # print ("##################################################") breakdef check1(file):#check file st_tc.store has [<result>FAILED] [<item>check_logs failed] or not a=0 b=0 #print('check1') open_file1=open(file) #print(open_file1) for line in open_file1: if(re.search(search_argu[2][0],line)): a=1 break for line in open_file1: if (re.search(search_argu[2][1],line)): b=1 break open_file1.close() if(a+b==2): # print('check1 succeed') return(1) else: # print('check1 failed') return(0)def check2(file):#check file check_logfiles.log num=0 should_detect=[] remain_file=[] open_file2=open(file) if(check1(check_file1)==1): for line in open_file2: num+=1 if(re.search(checker_log,line)!=None): should_detect.append(line) else: pass if len(should_detect) > 0: # print(len(should_detect)) print(rt) print ('%d times found in this case' %(len(should_detect))) else: # print ("can't find in this case") pass open_file2.close()if __name__=='__main__': detect()
0 0
- 参数传递sys.argv, 文件递归搜索os.walk
- sys.argv命令行参数--文中搜索以及替换文本
- sys argv 命令行参数
- Python递归查找文件(os.walk, os.path, fnmatch)
- os.path.abspath(sys.argv[0])学习
- python:9:os模块与sys.argv
- python 获取当前 py 文件 的文件名 os.path.basename(sys.argv[0]).split(".")[0]
- python中使用sys.argv命令行参数
- Python main的命令行参数:sys.argv
- 文件遍历os.walk方法
- Python os.walk文件遍历
- 用os.path.walk来遍历文件,并且搜索文件里面的内容
- Python os.path.walk遍历文件,搜索文件里面的内容
- Python os.path.walk遍历文件,搜索文件里面的内容
- python---sys模块sys.argv,os模块os.path.isfile(),os.access()
- sys.argv[]
- sys.argv
- sys.argv[]
- 前端开源项目周报0307
- JAVA策略模式例子
- ThinkPHP3.2 + PHPExcel 进行execl文件导出操作
- web
- 开发国际化 NSLocalizedString用法
- 参数传递sys.argv, 文件递归搜索os.walk
- Android项目重构之路:架构篇
- Hadoop用户行为分析项目
- Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/JaxenException这个错误信息
- 实验2
- 2D激光SLAM算法比较+cartographer
- 思岚科技亮相2017电子博览会 倍受瞩目
- dubbo 服务提供者 心跳机制
- leetcode 24 Swap Nodes in Pairs