summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorPawel Wodnicki <pawel@32bitmicro.com>2012-11-17 06:24:37 +0000
committerPawel Wodnicki <pawel@32bitmicro.com>2012-11-17 06:24:37 +0000
commit7e2db212a00f8885740e6791fc7b34d9f969dc21 (patch)
tree45bfac8a0f091b1ef47bb5b115fcde81e4a3a30d /utils
parent0f5720f85b10fb160e24828c22de42ea1cfb5fde (diff)
downloadllvm-7e2db212a00f8885740e6791fc7b34d9f969dc21.tar.gz
llvm-7e2db212a00f8885740e6791fc7b34d9f969dc21.tar.bz2
llvm-7e2db212a00f8885740e6791fc7b34d9f969dc21.tar.xz
adding whose code is it anywa tools
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168254 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/wciia.py125
1 files changed, 125 insertions, 0 deletions
diff --git a/utils/wciia.py b/utils/wciia.py
new file mode 100644
index 0000000000..d1a96f4770
--- /dev/null
+++ b/utils/wciia.py
@@ -0,0 +1,125 @@
+#! python
+
+"""
+wciia - Whose Code Is It Anyway
+
+Determines code owner of the file/folder relative to the llvm source root.
+Code owner is determined from the content of the CODE_OWNERS.TXT
+by parsing the D: field
+
+usage:
+
+utils/wciia.py path
+
+limitations:
+- must be run from llvm source root
+- very simplistic algorithm
+- only handles * as a wildcard
+- not very user friendly
+- does not handle the proposed F: field
+
+"""
+
+import os
+
+code_owners = {}
+
+def process_files_and_folders(owner):
+ filesfolders = owner['filesfolders']
+ # paths must be in ( ... ) so strip them
+ lpar = filesfolders.find('(')
+ rpar = filesfolders.rfind(')')
+ if rpar <= lpar:
+ # give up
+ return
+ paths = filesfolders[lpar+1:rpar]
+ # split paths
+ owner['paths'] = []
+ for path in paths.split():
+ owner['paths'].append(path)
+
+def process_code_owner(owner):
+ if 'filesfolders' in owner:
+ filesfolders = owner['filesfolders']
+ else:
+# print "F: field missing, using D: field"
+ owner['filesfolders'] = owner['description']
+ process_files_and_folders(owner)
+ code_owners[owner['name']] = owner
+
+# process CODE_OWNERS.TXT first
+code_owners_file = open("CODE_OWNERS.TXT", "r").readlines()
+code_owner = {}
+for line in code_owners_file:
+ for word in line.split():
+ if word == "N:":
+ name = line[2:].strip()
+ if code_owner:
+ process_code_owner(code_owner)
+ code_owner = {}
+ # reset the values
+ code_owner['name'] = name
+ if word == "E:":
+ email = line[2:].strip()
+ code_owner['email'] = email
+ if word == "D:":
+ description = line[2:].strip()
+ code_owner['description'] = description
+ if word == "F:":
+ filesfolders = line[2:].strip()
+ code_owner['filesfolders'].append(filesfolders)
+
+def find_owners(fpath):
+ onames = []
+ lmatch = -1
+ # very simplistic way of findning the best match
+ for name in code_owners:
+ owner = code_owners[name]
+ if 'paths' in owner:
+ for path in owner['paths']:
+# print "searching (" + path + ")"
+ # try exact match
+ if fpath == path:
+ return name
+ # see if path ends with a *
+ rstar = path.rfind('*')
+ if rstar>0:
+ # try the longest match,
+ rpos = -1
+ if len(fpath) < len(path):
+ rpos = path.find(fpath)
+ if rpos == 0:
+ onames.append(name)
+ onames.append('Chris Lattner')
+ return onames
+
+# now lest try to find the owner of the file or folder
+import sys
+
+if len(sys.argv) < 2:
+ print "usage " + sys.argv[0] + " file_or_folder"
+ exit(-1)
+
+# the path we are checking
+path = str(sys.argv[1])
+
+# check if this is real path
+if not os.path.exists(path):
+ print "path (" + path + ") does not exist"
+ exit(-1)
+
+owners_name = find_owners(path)
+
+# be gramatically correct
+print "The owner(s) of the (" + path + ") is(are) : " + str(owners_name)
+
+exit(0)
+
+# bottom up walk of the current .
+# not yet used
+root = "."
+for dir,subdirList,fileList in os.walk( root , topdown=False ) :
+ print "dir :" , dir
+ for fname in fileList :
+ print "-" , fname
+ print