Unverified Commit c58e7d89 authored by NBolade-224's avatar NBolade-224 Committed by GitHub
Browse files

edit in tools check_stamped (#2305)

parent 28d577e1
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
##################################################################################### #####################################################################################
# The MIT License (MIT) # The MIT License (MIT)
# #
# Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved. # Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
...@@ -27,11 +27,11 @@ import sys ...@@ -27,11 +27,11 @@ import sys
debug = False debug = False
# The filetypes we want to check for that are stamped # The filetypes we want to check for that are stamped
# LICENSE is included here as it SHOULD have a liscence in it otherwise flag it as unstamped # LICENSE is included here as it SHOULD have a license in it otherwise flag it as unstamped
supported_file_types = (".cpp", ".hpp", ".h", ".ipynb", ".py", ".txt", ".sh", supported_file_types = (".cpp", ".hpp", ".h", ".ipynb", ".py", ".txt", ".sh",
".bsh", "LICENSE", ".cmake") ".bsh", "LICENSE", ".cmake")
#add general stuff we shouldn't stamp and any exceptions here # add general stuff we shouldn't stamp and any exceptions here
unsupported_file_types = [ unsupported_file_types = [
".onnx", ".pb", ".rst", ".jpg", ".jpeg", ".proto", ".md", ".clang", ".onnx", ".pb", ".rst", ".jpg", ".jpeg", ".proto", ".md", ".clang",
".weight", ".ini", ".json", ".docker", ".git", ".rules", ".yml" ".weight", ".ini", ".json", ".docker", ".git", ".rules", ".yml"
...@@ -40,105 +40,89 @@ unsupported_file_types = [ ...@@ -40,105 +40,89 @@ unsupported_file_types = [
specificIgnores = ("digits.txt", "Dockerfile", "Jenkinsfile", "") specificIgnores = ("digits.txt", "Dockerfile", "Jenkinsfile", "")
def hasKeySequence(inputfile, key_message): def hasKeySequence(inputfile: str, key_message: str) -> bool:
result = False
if key_message in inputfile: if key_message in inputfile:
result = True return True
return result return False
#Simple just open and write stuff to each file with the license stamp # Simple just open and write stuff to each file with the license stamp
def openAndCheckFile(filename): def needStampCheck(filename: str) -> bool:
result = False # open save old contents and append things here
#open save old contents and append things here if debug: print("Open", filename, end=' ')
if debug is True:
print("Open", filename, end='')
try: try:
file = open(filename, 'r') file = open(filename, 'r')
except OSError as e: except OSError as e:
if debug is True: if debug: print(str(e) + "....Open Error: Skipping file ")
print(str(e) + "....Open Error: Skipping file ")
file.close() file.close()
return return False
else: else:
with file as contents: with file as contents:
try: try:
save = contents.read() save = contents.read()
hasAmdLic = hasKeySequence(
save, "Advanced Micro Devices, Inc. All rights reserved")
#Check if we have a licence stamp already # Check if we have a license stamp already
if hasAmdLic is True: if hasKeySequence(
if debug is True: save,
print("....Already Stamped: Skipping file ") "Advanced Micro Devices, Inc. All rights reserved"):
if debug: print("....Already Stamped: Skipping file ")
contents.close() contents.close()
result = True return False
except UnicodeDecodeError as eu: except UnicodeDecodeError as eu:
if debug is True: if debug: print(f"{str(eu)}...Skipping binary file ")
print(str(eu) + "...Skipping binary file ")
contents.close() contents.close()
result = True return False
return result return True
# Deterine if filename is desired in the fileTuple past in # Check if any element in fileTuple is in filename
def check_filename(filename, fileTuple): def check_filename(filename: str, fileTuple: tuple or list) -> bool:
supported = False if any([x in filename for x in fileTuple]):
for key in fileTuple: return True
if key in filename: return False
supported = True
break
return supported
def main(): def main() -> None:
unsupported_file_types.extend(specificIgnores) unsupported_file_types.extend(specificIgnores)
#Get a list of all the tracked files in our git repo # Get a list of all the tracked files in our git repo
proc = subprocess.run("git ls-files --exclude-standard", proc = subprocess.run("git ls-files --exclude-standard",
shell=True, shell=True,
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
fileList = proc.stdout.decode().split('\n') fileList = proc.stdout.decode().split('\n')
if debug is True: if debug: print("Target file list:\n" + str(fileList))
print("Target file list:\n" + str(fileList))
unsupportedFiles = [] unsupportedFiles = []
unstampedFiles = [] unstampedFiles = []
unknownFiles = [] unknownFiles = []
for file in fileList: for file in fileList:
supported = check_filename(file, supported_file_types) if check_filename(file, supported_file_types):
if supported is True: if needStampCheck(file):
isStamped = openAndCheckFile(file)
if isStamped is False:
unstampedFiles.append(file) unstampedFiles.append(file)
elif check_filename(file, unsupported_file_types):
unsupportedFiles.append(file)
else: else:
unsupported = check_filename(file, unsupported_file_types) unknownFiles.append(file)
if unsupported is True:
unsupportedFiles.append(file)
else:
unknownFiles.append(file)
#Do a bunch of checks based on our file lists # Do a bunch of checks based on our file lists
if len(unstampedFiles) > 0: if len(unstampedFiles) > 0:
print("Error: The following " + str(len(unstampedFiles)) + print("\nError: The following " + str(len(unstampedFiles)) +
" files are currently without a license:") " files are currently without a license:")
print(str(unstampedFiles)) print(str(unstampedFiles))
sys.exit(1) sys.exit(1)
if len(unknownFiles) > 0: if len(unknownFiles) > 0:
print("Error: The following " + str(len(unknownFiles)) + print("\nError: The following " + str(len(unknownFiles)) +
" files not handled:") " files not handled:")
print(str(unknownFiles)) print(str(unknownFiles))
sys.exit(2) sys.exit(2)
sys.exit(0)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment