1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[Utils] Fix indentation error in utils/wciia.py

Running this script gives
```
"llvm-project/llvm/./utils/wciia.py", line 56
    if word == "N:":
TabError: inconsistent use of tabs and spaces in indentation
```
Under emacs' whitespace-mode, it shows
```
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·=·{}$
```
I use `yapf` to format this script directly and it's running correctly.
This commit is contained in:
Kai Luo 2021-05-16 22:34:09 +08:00
parent 945b8d0f5d
commit f5ce33b9fe

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
""" """
wciia - Whose Code Is It Anyway wciia - Whose Code Is It Anyway
@ -25,89 +24,94 @@ import os
code_owners = {} code_owners = {}
def process_files_and_folders(owner): def process_files_and_folders(owner):
filesfolders = owner['filesfolders'] filesfolders = owner['filesfolders']
# paths must be in ( ... ) so strip them # paths must be in ( ... ) so strip them
lpar = filesfolders.find('(') lpar = filesfolders.find('(')
rpar = filesfolders.rfind(')') rpar = filesfolders.rfind(')')
if rpar <= lpar: if rpar <= lpar:
# give up # give up
return return
paths = filesfolders[lpar+1:rpar] paths = filesfolders[lpar + 1:rpar]
# split paths # split paths
owner['paths'] = [] owner['paths'] = []
for path in paths.split(): for path in paths.split():
owner['paths'].append(path) owner['paths'].append(path)
def process_code_owner(owner): def process_code_owner(owner):
if 'filesfolders' in owner: if 'filesfolders' in owner:
filesfolders = owner['filesfolders'] filesfolders = owner['filesfolders']
else: else:
# print "F: field missing, using D: field" # print "F: field missing, using D: field"
owner['filesfolders'] = owner['description'] owner['filesfolders'] = owner['description']
process_files_and_folders(owner) process_files_and_folders(owner)
code_owners[owner['name']] = owner code_owners[owner['name']] = owner
# process CODE_OWNERS.TXT first # process CODE_OWNERS.TXT first
code_owners_file = open("CODE_OWNERS.TXT", "r").readlines() code_owners_file = open("CODE_OWNERS.TXT", "r").readlines()
code_owner = {} code_owner = {}
for line in code_owners_file: for line in code_owners_file:
for word in line.split(): for word in line.split():
if word == "N:": if word == "N:":
name = line[2:].strip() name = line[2:].strip()
if code_owner: if code_owner:
process_code_owner(code_owner) process_code_owner(code_owner)
code_owner = {} code_owner = {}
# reset the values # reset the values
code_owner['name'] = name code_owner['name'] = name
if word == "E:": if word == "E:":
email = line[2:].strip() email = line[2:].strip()
code_owner['email'] = email code_owner['email'] = email
if word == "D:": if word == "D:":
description = line[2:].strip() description = line[2:].strip()
code_owner['description'] = description code_owner['description'] = description
if word == "F:": if word == "F:":
filesfolders = line[2:].strip() filesfolders = line[2:].strip()
code_owner['filesfolders'].append(filesfolders) code_owner['filesfolders'].append(filesfolders)
def find_owners(fpath): def find_owners(fpath):
onames = [] onames = []
lmatch = -1 lmatch = -1
# very simplistic way of findning the best match # very simplistic way of findning the best match
for name in code_owners: for name in code_owners:
owner = code_owners[name] owner = code_owners[name]
if 'paths' in owner: if 'paths' in owner:
for path in owner['paths']: for path in owner['paths']:
# print "searching (" + path + ")" # print "searching (" + path + ")"
# try exact match # try exact match
if fpath == path: if fpath == path:
return name return name
# see if path ends with a * # see if path ends with a *
rstar = path.rfind('*') rstar = path.rfind('*')
if rstar>0: if rstar > 0:
# try the longest match, # try the longest match,
rpos = -1 rpos = -1
if len(fpath) < len(path): if len(fpath) < len(path):
rpos = path.find(fpath) rpos = path.find(fpath)
if rpos == 0: if rpos == 0:
onames.append(name) onames.append(name)
onames.append('Chris Lattner') onames.append('Chris Lattner')
return onames return onames
# now lest try to find the owner of the file or folder # now lest try to find the owner of the file or folder
import sys import sys
if len(sys.argv) < 2: if len(sys.argv) < 2:
print("usage " + sys.argv[0] + " file_or_folder") print("usage " + sys.argv[0] + " file_or_folder")
exit(-1) exit(-1)
# the path we are checking # the path we are checking
path = str(sys.argv[1]) path = str(sys.argv[1])
# check if this is real path # check if this is real path
if not os.path.exists(path): if not os.path.exists(path):
print("path (" + path + ") does not exist") print("path (" + path + ") does not exist")
exit(-1) exit(-1)
owners_name = find_owners(path) owners_name = find_owners(path)
@ -119,8 +123,8 @@ exit(0)
# bottom up walk of the current . # bottom up walk of the current .
# not yet used # not yet used
root = "." root = "."
for dir,subdirList,fileList in os.walk( root , topdown=False ) : for dir, subdirList, fileList in os.walk(root, topdown=False):
print("dir :" , dir) print("dir :", dir)
for fname in fileList : for fname in fileList:
print("-" , fname) print("-", fname)
print() print()