-
#!/usr/bin/python3
-
# -*- coding:UTF-8 -*-
-
import sys
-
import os
-
import glob
-
import re
-
import subprocess
-
-
debug_printall=0 #all file and dir is printout althrough white/black list is assign
-
-
## second list are dedicated to dir only,
-
## 1. file: file(not dir) in first level and file(not dir) in second level are all
-
## added to printout.
-
## 2. dir: Only Dir in whitelist or dir not in black list is printout
-
-
if len(sys.argv) < 4:
-
print("Usage: ./xx.py ./(current kernel-src) arm64(arch/*) 0/1(0 for ctags, 1 for si)")
-
sys.exit()
-
for_linux_si = arch_in=sys.argv[3]
-
ctags_file = open('ctags_file.txt', 'w') # open for writing, truncating the file first
-
-
if (for_linux_si == "0"):
-
first_level_black_list = ["crypto", "Documentation", "security", "sound", \
-
"tools", "virt", "firmware", ".git", "samples", "scripts"]
-
-
-
second_level_white_list = [\
-
["&arch&", "arm64"], \
-
["&fs&", "ext4", "cqfs", "debugfs", "devpts", "iomap", "proc", "ramfs", "sysfs", "tracefs", "ubifs", "romfs"],\
-
["&dumy&", "dumy"], \
-
]
-
second_level_black_list = [ \
-
["&drivers&", "android", "auxdisplay", "bcma", "bluetooth", "crypto", "dax", "dca", "dio", "video", "w1",\
-
"firewire", "fsi", "gnss", "gpu", "greybus", "hid", "hsi", "hv", "media", "nfc", "pinctrl", "scsi", "usb", "xen"],\
-
["&include&", "drm", "scsi", "media", "pcmcia", "xen", "video"],\
-
["&net&", "6lowpan", "bluetooth", "openvswitch", "appletalk", "wireless"],\
-
]
-
-
if (for_linux_si == "1"):
-
first_level_black_list = ["crypto", "Documentation", "security", "sound", \
-
"tools", "virt", "firmware", ".git", "samples", "scripts"]
-
-
-
second_level_white_list = [\
-
["&arch&", "arm64"], \
-
["&fs&", "debugfs", "devpts", "proc", "ramfs", "sysfs", "tracefs", "romfs"],\
-
["&drivers&", "base", "block", "bus", "clk", "clocksource", "dma", "dma-buf", "irqchip"], \
-
]
-
-
second_level_black_list = [ \
-
["&include&", "drm", "scsi", "media", "pcmcia", "xen", "video"],\
-
["&net&", "6lowpan", "bluetooth", "openvswitch", "appletalk", "wireless"],\
-
]
-
-
dir_in=sys.argv[1]
-
-
arch_in=sys.argv[2]
-
second_level_white_list[0][1] = arch_in
-
print("arch_in: " + second_level_white_list[0][1])
-
-
if (os.path.exists(dir_in)):
-
#print(dir_in +"do exist")
-
files = os.listdir(dir_in)
-
files.sort()
-
for file in files:
-
if (file[0] == '.' or file == "tags" or file.endswith(".patch")):
-
#print("skip .file: " + file)
-
continue
-
if (file in first_level_black_list and debug_printall == 0):
-
#print("skip first level black list:" + file)
-
continue
-
m = os.path.join('', file)
-
if (os.path.isdir(m)):
-
second_files = os.listdir(m)
-
second_files.sort()
-
for second_file in second_files:
-
if (second_file[0] == '.'):
-
#print("skip .file: " + file)
-
continue
-
if (debug_printall == 1): #for debug
-
print(m +"/"+ second_file)
-
continue
-
not_white = [0]*50 #any dir not in white list eg: dir is not &arch&
-
not_black = [0]*50
-
not_white_all = 1 #any dir not in white list eg: dir is not &*&
-
not_black_all = 1
-
if (os.path.isdir(os.path.join(m, second_file))):
-
-
for i in range(0, len(second_level_white_list)):
-
dir_name = second_level_white_list[i][0].strip('&')
-
if (dir_name == m):
-
if (second_file in second_level_white_list[i]):
-
print(m +"/"+ second_file, file=ctags_file)
-
else:
-
pass
-
#print("skip " + "not in white list, skip "+ m +"/"+ second_file)
-
not_white[i] = 0
-
else:
-
not_white[i] = 1
-
-
for j in range(0, len(second_level_black_list)):
-
dir_name = second_level_black_list[j][0].strip('&')
-
if (dir_name == m ):
-
if (second_file not in second_level_black_list[j]): # not in black list
-
print(m +"/"+ second_file, file=ctags_file)
-
else:
-
pass
-
#print("skip " + "in black list, skip "+ m +"/"+ second_file)
-
not_black[j] = 0
-
else:
-
not_black[j] = 1
-
-
for i in range(0, len(second_level_white_list)):
-
not_white_all = not_white_all¬_white[i]
-
for i in range(0, len(second_level_black_list)):
-
not_black_all = not_black_all¬_black[i]
-
-
if (not_white_all == 1 and not_black_all == 1):
-
print(m +"/"+ second_file, file=ctags_file) #dir not include in white and black list
-
else:
-
#pass
-
print(m +"/"+ second_file, file=ctags_file) #second level file, not include dir
-
-
else:
-
#pass
-
print(file, file=ctags_file) #first level file, not include dir
-
-
## for linux
-
if (for_linux_si == "0"):
-
cmd_str="ctags -R -L ctags_file.txt"
-
print(cmd_str+" ... wait ...")
-
os.system(cmd_str)
-
-
ctags_file.close()
-
##for sourceinsight
-
if (for_linux_si == "1"):
-
file_i=open('ctags_file.txt')
-
file_o=open('sourceinsight_list.txt', 'w')
-
list_l=file_i.readlines()
-
print("len: ", len(list_l))
-
si_lines = 0
-
for c in list_l:
-
c=c.rstrip("\n") #must strip it
-
path_f = os.path.join('', c)
-
if (os.path.isdir(path_f)):
-
for root,dirs,files1 in os.walk(path_f):
-
for file in files1:
-
#print(root)
-
print(os.path.join(root,file).replace('/', '\\'), file=file_o)
-
si_lines = si_lines + 1
-
else:
-
print(c.replace('/', '\\'), file=file_o)
-
si_lines = si_lines + 1
-
print("files num: ", si_lines)
-
-
file_i.close()
-
file_o.close()
-
-
sys.exit()
阅读(446) | 评论(0) | 转发(0) |