3 wciia - Whose Code Is It Anyway
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
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
22 from __future__
import print_function
28 def process_files_and_folders(owner
):
29 filesfolders
= owner
['filesfolders']
30 # paths must be in ( ... ) so strip them
31 lpar
= filesfolders
.find('(')
32 rpar
= filesfolders
.rfind(')')
36 paths
= filesfolders
[lpar
+ 1:rpar
]
39 for path
in paths
.split():
40 owner
['paths'].append(path
)
43 def process_code_owner(owner
):
44 if 'filesfolders' in owner
:
45 filesfolders
= owner
['filesfolders']
47 # print "F: field missing, using D: field"
48 owner
['filesfolders'] = owner
['description']
49 process_files_and_folders(owner
)
50 code_owners
[owner
['name']] = owner
53 # process CODE_OWNERS.TXT first
54 code_owners_file
= open("CODE_OWNERS.TXT", "r").readlines()
56 for line
in code_owners_file
:
57 for word
in line
.split():
59 name
= line
[2:].strip()
61 process_code_owner(code_owner
)
64 code_owner
['name'] = name
66 email
= line
[2:].strip()
67 code_owner
['email'] = email
69 description
= line
[2:].strip()
70 code_owner
['description'] = description
72 filesfolders
= line
[2:].strip()
73 code_owner
['filesfolders'].append(filesfolders
)
76 def find_owners(fpath
):
79 # very simplistic way of findning the best match
80 for name
in code_owners
:
81 owner
= code_owners
[name
]
83 for path
in owner
['paths']:
84 # print "searching (" + path + ")"
88 # see if path ends with a *
89 rstar
= path
.rfind('*')
91 # try the longest match,
93 if len(fpath
) < len(path
):
94 rpos
= path
.find(fpath
)
97 onames
.append('Chris Lattner')
101 # now lest try to find the owner of the file or folder
104 if len(sys
.argv
) < 2:
105 print("usage " + sys
.argv
[0] + " file_or_folder")
108 # the path we are checking
109 path
= str(sys
.argv
[1])
111 # check if this is real path
112 if not os
.path
.exists(path
):
113 print("path (" + path
+ ") does not exist")
116 owners_name
= find_owners(path
)
118 # be grammatically correct
119 print("The owner(s) of the (" + path
+ ") is(are) : " + str(owners_name
))
123 # bottom up walk of the current .
126 for dir, subdirList
, fileList
in os
.walk(root
, topdown
=False):
128 for fname
in fileList
: