Skip to content

Instantly share code, notes, and snippets.

@ityuhui
Last active February 23, 2016 01:56
Show Gist options
  • Save ityuhui/37219691517d1dede405 to your computer and use it in GitHub Desktop.
Save ityuhui/37219691517d1dede405 to your computer and use it in GitHub Desktop.
Python 扫描源代码(文本)文件
def process1(file):
fr = open(file,'r')
try:
log_line_count = 0
debug_trace_log_line_count = 0
for line in fr:
if('+' == line[0]): # modify in diff
if('LOG_' in line):
log_line_count+=1
if('LOG_TRACE' in line or 'LOG_DEBUG' in line):
debug_trace_log_line_count+=1
log_greater_than_info = log_line_count - debug_trace_log_line_count
strText1 = "The count of line of " + file + " is (" + str(log_greater_than_info
) + ")"
print(strText1)
return log_greater_than_info
finally:
fr.close()
filelists = ['kernel.diff',
'kernel_kdaemon.diff',
'kernel_lib.diff',
'kernel_pem.diff',
'kernel_policy.diff',
'kernel_policy_mdplan.diff',
'kernel_rpi.diff']
total_log_count = 0
for file in filelists:
total_log_count += process1(file)
strTotal="The total count is " + str(total_log_count)
print(strTotal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment