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
23 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
)
42 def process_code_owner(owner
):
43 if 'filesfolders' in owner
:
44 filesfolders
= owner
['filesfolders']
46 # print "F: field missing, using D: field"
47 owner
['filesfolders'] = owner
['description']
48 process_files_and_folders(owner
)
49 code_owners
[owner
['name']] = owner
51 # process CODE_OWNERS.TXT first
52 code_owners_file
= open("CODE_OWNERS.TXT", "r").readlines()
54 for line
in code_owners_file
:
55 for word
in line
.split():
57 name
= line
[2:].strip()
59 process_code_owner(code_owner
)
62 code_owner
['name'] = name
64 email
= line
[2:].strip()
65 code_owner
['email'] = email
67 description
= line
[2:].strip()
68 code_owner
['description'] = description
70 filesfolders
= line
[2:].strip()
71 code_owner
['filesfolders'].append(filesfolders
)
73 def find_owners(fpath
):
76 # very simplistic way of findning the best match
77 for name
in code_owners
:
78 owner
= code_owners
[name
]
80 for path
in owner
['paths']:
81 # print "searching (" + path + ")"
85 # see if path ends with a *
86 rstar
= path
.rfind('*')
88 # try the longest match,
90 if len(fpath
) < len(path
):
91 rpos
= path
.find(fpath
)
94 onames
.append('Chris Lattner')
97 # now lest try to find the owner of the file or folder
100 if len(sys
.argv
) < 2:
101 print("usage " + sys
.argv
[0] + " file_or_folder")
104 # the path we are checking
105 path
= str(sys
.argv
[1])
107 # check if this is real path
108 if not os
.path
.exists(path
):
109 print("path (" + path
+ ") does not exist")
112 owners_name
= find_owners(path
)
114 # be grammatically correct
115 print("The owner(s) of the (" + path
+ ") is(are) : " + str(owners_name
))
119 # bottom up walk of the current .
122 for dir,subdirList
,fileList
in os
.walk( root
, topdown
=False ) :
124 for fname
in fileList
: