4 wciia - Whose Code Is It Anyway
6 Determines code owner of the file/folder relative to the llvm source root.
7 Code owner is determined from the content of the CODE_OWNERS.TXT
8 by parsing the D: field
15 - must be run from llvm source root
16 - very simplistic algorithm
17 - only handles * as a wildcard
18 - not very user friendly
19 - does not handle the proposed F: field
27 def process_files_and_folders(owner
):
28 filesfolders
= owner
['filesfolders']
29 # paths must be in ( ... ) so strip them
30 lpar
= filesfolders
.find('(')
31 rpar
= filesfolders
.rfind(')')
35 paths
= filesfolders
[lpar
+1:rpar
]
38 for path
in paths
.split():
39 owner
['paths'].append(path
)
41 def process_code_owner(owner
):
42 if 'filesfolders' in owner
:
43 filesfolders
= owner
['filesfolders']
45 # print "F: field missing, using D: field"
46 owner
['filesfolders'] = owner
['description']
47 process_files_and_folders(owner
)
48 code_owners
[owner
['name']] = owner
50 # process CODE_OWNERS.TXT first
51 code_owners_file
= open("CODE_OWNERS.TXT", "r").readlines()
53 for line
in code_owners_file
:
54 for word
in line
.split():
56 name
= line
[2:].strip()
58 process_code_owner(code_owner
)
61 code_owner
['name'] = name
63 email
= line
[2:].strip()
64 code_owner
['email'] = email
66 description
= line
[2:].strip()
67 code_owner
['description'] = description
69 filesfolders
= line
[2:].strip()
70 code_owner
['filesfolders'].append(filesfolders
)
72 def find_owners(fpath
):
75 # very simplistic way of findning the best match
76 for name
in code_owners
:
77 owner
= code_owners
[name
]
79 for path
in owner
['paths']:
80 # print "searching (" + path + ")"
84 # see if path ends with a *
85 rstar
= path
.rfind('*')
87 # try the longest match,
89 if len(fpath
) < len(path
):
90 rpos
= path
.find(fpath
)
93 onames
.append('Chris Lattner')
96 # now lest try to find the owner of the file or folder
100 print "usage " + sys
.argv
[0] + " file_or_folder"
103 # the path we are checking
104 path
= str(sys
.argv
[1])
106 # check if this is real path
107 if not os
.path
.exists(path
):
108 print "path (" + path
+ ") does not exist"
111 owners_name
= find_owners(path
)
113 # be grammatically correct
114 print "The owner(s) of the (" + path
+ ") is(are) : " + str(owners_name
)
118 # bottom up walk of the current .
121 for dir,subdirList
,fileList
in os
.walk( root
, topdown
=False ) :
123 for fname
in fileList
: