Chinaunix首页 | 论坛 | 博客
  • 博客访问: 307085
  • 博文数量: 65
  • 博客积分: 185
  • 博客等级: 入伍新兵
  • 技术积分: 609
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-06 21:41
个人简介

好好学习,天天向上

文章分类

全部博文(65)

文章存档

2022年(3)

2021年(25)

2020年(1)

2019年(3)

2016年(2)

2015年(3)

2014年(14)

2013年(7)

2012年(7)

我的朋友

分类: Python/Ruby

2021-12-06 17:03:29



点击(此处)折叠或打开

  1. #!/usr/bin/python3
  2. # -*- coding:UTF-8 -*-
  3. import sys
  4. import os
  5. import glob
  6. import re
  7. import subprocess

  8. debug_printall=0 #all file and dir is printout althrough white/black list is assign

  9. ## second list are dedicated to dir only,
  10. ## 1. file: file(not dir) in first level and file(not dir) in second level are all
  11. ## added to printout.
  12. ## 2. dir: Only Dir in whitelist or dir not in black list is printout

  13. if len(sys.argv) < 4:
  14.         print("Usage: ./xx.py ./(current kernel-src) arm64(arch/*) 0/1(0 for ctags, 1 for si)")
  15.         sys.exit()
  16. for_linux_si = arch_in=sys.argv[3]
  17. ctags_file = open('ctags_file.txt', 'w') # open for writing, truncating the file first

  18. if (for_linux_si == "0"):
  19.     first_level_black_list = ["crypto", "Documentation", "security", "sound", \
  20.                             "tools", "virt", "firmware", ".git", "samples", "scripts"]


  21.     second_level_white_list = [\
  22.         ["&arch&", "arm64"], \
  23.         ["&fs&", "ext4", "cqfs", "debugfs", "devpts", "iomap", "proc", "ramfs", "sysfs", "tracefs", "ubifs", "romfs"],\
  24.         ["&dumy&", "dumy"], \
  25.         ]
  26.     second_level_black_list = [ \
  27.         ["&drivers&", "android", "auxdisplay", "bcma", "bluetooth", "crypto", "dax", "dca", "dio", "video", "w1",\
  28.         "firewire", "fsi", "gnss", "gpu", "greybus", "hid", "hsi", "hv", "media", "nfc", "pinctrl", "scsi", "usb", "xen"],\
  29.         ["&include&", "drm", "scsi", "media", "pcmcia", "xen", "video"],\
  30.         ["&net&", "6lowpan", "bluetooth", "openvswitch", "appletalk", "wireless"],\
  31.         ]

  32. if (for_linux_si == "1"):
  33.     first_level_black_list = ["crypto", "Documentation", "security", "sound", \
  34.                             "tools", "virt", "firmware", ".git", "samples", "scripts"]


  35.     second_level_white_list = [\
  36.         ["&arch&", "arm64"], \
  37.         ["&fs&", "debugfs", "devpts", "proc", "ramfs", "sysfs", "tracefs", "romfs"],\
  38.         ["&drivers&", "base", "block", "bus", "clk", "clocksource", "dma", "dma-buf", "irqchip"], \
  39.         ]
  40.         
  41.     second_level_black_list = [ \
  42.         ["&include&", "drm", "scsi", "media", "pcmcia", "xen", "video"],\
  43.         ["&net&", "6lowpan", "bluetooth", "openvswitch", "appletalk", "wireless"],\
  44.         ]

  45. dir_in=sys.argv[1]

  46. arch_in=sys.argv[2]
  47. second_level_white_list[0][1] = arch_in
  48. print("arch_in: " + second_level_white_list[0][1])

  49. if (os.path.exists(dir_in)):
  50.     #print(dir_in +"do exist")
  51.     files = os.listdir(dir_in)
  52.     files.sort()
  53.     for file in files:
  54.         if (file[0] == '.' or file == "tags" or file.endswith(".patch")):
  55.             #print("skip .file: " + file)
  56.             continue
  57.         if (file in first_level_black_list and debug_printall == 0):
  58.             #print("skip first level black list:" + file)
  59.             continue        
  60.         m = os.path.join('', file)
  61.         if (os.path.isdir(m)):
  62.             second_files = os.listdir(m)
  63.             second_files.sort()
  64.             for second_file in second_files:
  65.                 if (second_file[0] == '.'):
  66.                     #print("skip .file: " + file)
  67.                     continue
  68.                 if (debug_printall == 1): #for debug
  69.                     print(m +"/"+ second_file)
  70.                     continue
  71.                 not_white = [0]*50 #any dir not in white list eg: dir is not &arch&
  72.                 not_black = [0]*50
  73.                 not_white_all = 1 #any dir not in white list eg: dir is not &*&
  74.                 not_black_all = 1
  75.                 if (os.path.isdir(os.path.join(m, second_file))):
  76.                 
  77.                     for i in range(0, len(second_level_white_list)):
  78.                         dir_name = second_level_white_list[i][0].strip('&')
  79.                         if (dir_name == m):
  80.                             if (second_file in second_level_white_list[i]):
  81.                                 print(m +"/"+ second_file, file=ctags_file)
  82.                             else:
  83.                                 pass
  84.                                 #print("skip " + "not in white list, skip "+ m +"/"+ second_file)
  85.                             not_white[i] = 0
  86.                         else:
  87.                             not_white[i] = 1

  88.                     for j in range(0, len(second_level_black_list)):
  89.                         dir_name = second_level_black_list[j][0].strip('&')
  90.                         if (dir_name == m ):
  91.                             if (second_file not in second_level_black_list[j]): # not in black list
  92.                                 print(m +"/"+ second_file, file=ctags_file)
  93.                             else:
  94.                                 pass
  95.                                 #print("skip " + "in black list, skip "+ m +"/"+ second_file)
  96.                             not_black[j] = 0
  97.                         else:
  98.                             not_black[j] = 1
  99.                     
  100.                     for i in range(0, len(second_level_white_list)):
  101.                         not_white_all = not_white_all&not_white[i]
  102.                     for i in range(0, len(second_level_black_list)):
  103.                         not_black_all = not_black_all&not_black[i]
  104.                         
  105.                     if (not_white_all == 1 and not_black_all == 1):
  106.                         print(m +"/"+ second_file, file=ctags_file) #dir not include in white and black list
  107.                 else:
  108.                     #pass
  109.                     print(m +"/"+ second_file, file=ctags_file) #second level file, not include dir
  110.                 
  111.         else:
  112.             #pass
  113.             print(file, file=ctags_file) #first level file, not include dir

  114. ## for linux
  115. if (for_linux_si == "0"):
  116.     cmd_str="ctags -R -L ctags_file.txt"
  117.     print(cmd_str+" ... wait ...")
  118.     os.system(cmd_str)

  119. ctags_file.close()

  120. ##for sourceinsight
  121. if (for_linux_si == "1"):
  122.     file_i=open('ctags_file.txt')
  123.     file_o=open('sourceinsight_list.txt', 'w')
  124.     list_l=file_i.readlines()
  125.     print("len: ", len(list_l))
  126.     si_lines = 0
  127.     for c in list_l:
  128.         c=c.rstrip("\n") #must strip it
  129.         path_f = os.path.join('', c)
  130.         if (os.path.isdir(path_f)):
  131.             for root,dirs,files1 in os.walk(path_f):
  132.                 for file in files1:
  133.                     #print(root)
  134.                     print(os.path.join(root,file).replace('/', '\\'), file=file_o)
  135.                     si_lines = si_lines + 1
  136.         else:
  137.             print(c.replace('/', '\\'), file=file_o)
  138.             si_lines = si_lines + 1
  139.     print("files num: ", si_lines)
  140.     
  141. file_i.close()
  142. file_o.close()

  143. sys.exit()


阅读(453) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~