llvm.org GIT mirror llvm / 7e2db21
adding whose code is it anywa tools git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168254 91177308-0d34-0410-b5e6-96231b3b80d8 Pawel Wodnicki 7 years ago
1 changed file(s) with 125 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 #! python
1
2 """
3 wciia - Whose Code Is It Anyway
4
5 Determines code owner of the file/folder relative to the llvm source root.
6 Code owner is determined from the content of the CODE_OWNERS.TXT
7 by parsing the D: field
8
9 usage:
10
11 utils/wciia.py path
12
13 limitations:
14 - must be run from llvm source root
15 - very simplistic algorithm
16 - only handles * as a wildcard
17 - not very user friendly
18 - does not handle the proposed F: field
19
20 """
21
22 import os
23
24 code_owners = {}
25
26 def process_files_and_folders(owner):
27 filesfolders = owner['filesfolders']
28 # paths must be in ( ... ) so strip them
29 lpar = filesfolders.find('(')
30 rpar = filesfolders.rfind(')')
31 if rpar <= lpar:
32 # give up
33 return
34 paths = filesfolders[lpar+1:rpar]
35 # split paths
36 owner['paths'] = []
37 for path in paths.split():
38 owner['paths'].append(path)
39
40 def process_code_owner(owner):
41 if 'filesfolders' in owner:
42 filesfolders = owner['filesfolders']
43 else:
44 # print "F: field missing, using D: field"
45 owner['filesfolders'] = owner['description']
46 process_files_and_folders(owner)
47 code_owners[owner['name']] = owner
48
49 # process CODE_OWNERS.TXT first
50 code_owners_file = open("CODE_OWNERS.TXT", "r").readlines()
51 code_owner = {}
52 for line in code_owners_file:
53 for word in line.split():
54 if word == "N:":
55 name = line[2:].strip()
56 if code_owner:
57 process_code_owner(code_owner)
58 code_owner = {}
59 # reset the values
60 code_owner['name'] = name
61 if word == "E:":
62 email = line[2:].strip()
63 code_owner['email'] = email
64 if word == "D:":
65 description = line[2:].strip()
66 code_owner['description'] = description
67 if word == "F:":
68 filesfolders = line[2:].strip()
69 code_owner['filesfolders'].append(filesfolders)
70
71 def find_owners(fpath):
72 onames = []
73 lmatch = -1
74 # very simplistic way of findning the best match
75 for name in code_owners:
76 owner = code_owners[name]
77 if 'paths' in owner:
78 for path in owner['paths']:
79 # print "searching (" + path + ")"
80 # try exact match
81 if fpath == path:
82 return name
83 # see if path ends with a *
84 rstar = path.rfind('*')
85 if rstar>0:
86 # try the longest match,
87 rpos = -1
88 if len(fpath) < len(path):
89 rpos = path.find(fpath)
90 if rpos == 0:
91 onames.append(name)
92 onames.append('Chris Lattner')
93 return onames
94
95 # now lest try to find the owner of the file or folder
96 import sys
97
98 if len(sys.argv) < 2:
99 print "usage " + sys.argv[0] + " file_or_folder"
100 exit(-1)
101
102 # the path we are checking
103 path = str(sys.argv[1])
104
105 # check if this is real path
106 if not os.path.exists(path):
107 print "path (" + path + ") does not exist"
108 exit(-1)
109
110 owners_name = find_owners(path)
111
112 # be gramatically correct
113 print "The owner(s) of the (" + path + ") is(are) : " + str(owners_name)
114
115 exit(0)
116
117 # bottom up walk of the current .
118 # not yet used
119 root = "."
120 for dir,subdirList,fileList in os.walk( root , topdown=False ) :
121 print "dir :" , dir
122 for fname in fileList :
123 print "-" , fname
124 print