diff options
author | Thaddeus Crews <repiteo@outlook.com> | 2024-03-10 12:09:48 -0500 |
---|---|---|
committer | Thaddeus Crews <repiteo@outlook.com> | 2024-03-10 12:57:57 -0500 |
commit | fb299d0fb134c603eafe7737bab8d22ec0b1cd59 (patch) | |
tree | 7f8bfac3259a5c6f55d09c5e041357e98b3c7fe9 /misc/scripts | |
parent | 0ace0a129284ffc6646b199699c1607a316fcec0 (diff) | |
download | redot-engine-fb299d0fb134c603eafe7737bab8d22ec0b1cd59.tar.gz |
SCons: Ensure `with` statement where applicable
Diffstat (limited to 'misc/scripts')
-rwxr-xr-x | misc/scripts/check_ci_log.py | 4 | ||||
-rwxr-xr-x | misc/scripts/copyright_headers.py | 37 |
2 files changed, 19 insertions, 22 deletions
diff --git a/misc/scripts/check_ci_log.py b/misc/scripts/check_ci_log.py index 1e5a12eeb4..d979d373de 100755 --- a/misc/scripts/check_ci_log.py +++ b/misc/scripts/check_ci_log.py @@ -9,8 +9,8 @@ if len(sys.argv) < 2: fname = sys.argv[1] -fileread = open(fname.strip(), "r") -file_contents = fileread.read() +with open(fname.strip(), "r") as fileread: + file_contents = fileread.read() # If find "ERROR: AddressSanitizer:", then happens invalid read or write # This is critical bug, so we need to fix this as fast as possible diff --git a/misc/scripts/copyright_headers.py b/misc/scripts/copyright_headers.py index 8fb793976c..b60eb32289 100755 --- a/misc/scripts/copyright_headers.py +++ b/misc/scripts/copyright_headers.py @@ -65,31 +65,28 @@ text += "\n" # In a second pass, we skip all consecutive comment lines starting with "/*", # then we can append the rest (step 2). -fileread = open(fname.strip(), "r") -line = fileread.readline() -header_done = False - -while line.strip() == "": # Skip empty lines at the top +with open(fname.strip(), "r") as fileread: line = fileread.readline() + header_done = False -if line.find("/**********") == -1: # Godot header starts this way - # Maybe starting with a non-Godot comment, abort header magic - header_done = True + while line.strip() == "": # Skip empty lines at the top + line = fileread.readline() -while not header_done: # Handle header now - if line.find("/*") != 0: # No more starting with a comment + if line.find("/**********") == -1: # Godot header starts this way + # Maybe starting with a non-Godot comment, abort header magic header_done = True - if line.strip() != "": - text += line - line = fileread.readline() -while line != "": # Dump everything until EOF - text += line - line = fileread.readline() + while not header_done: # Handle header now + if line.find("/*") != 0: # No more starting with a comment + header_done = True + if line.strip() != "": + text += line + line = fileread.readline() -fileread.close() + while line != "": # Dump everything until EOF + text += line + line = fileread.readline() # Write -filewrite = open(fname.strip(), "w", encoding="utf-8", newline="\n") -filewrite.write(text) -filewrite.close() +with open(fname.strip(), "w", encoding="utf-8", newline="\n") as filewrite: + filewrite.write(text) |