summaryrefslogtreecommitdiffstats
path: root/misc/scripts/copyright_headers.py
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-03-10 21:13:18 +0100
committerRémi Verschelde <rverschelde@gmail.com>2024-03-10 21:13:18 +0100
commit53701a02341eef7ec3ebca69b673d31d58760e45 (patch)
tree0a8f0d6c04955b6d66c088d4a501075bd8bfd385 /misc/scripts/copyright_headers.py
parentaf527e53c450eb957bfa6a5446a095b190ebcae9 (diff)
parentfb299d0fb134c603eafe7737bab8d22ec0b1cd59 (diff)
downloadredot-engine-53701a02341eef7ec3ebca69b673d31d58760e45.tar.gz
Merge pull request #89361 from Repiteo/scons/with-statement
SCons: Ensure `with` statement where applicable
Diffstat (limited to 'misc/scripts/copyright_headers.py')
-rwxr-xr-xmisc/scripts/copyright_headers.py37
1 files changed, 17 insertions, 20 deletions
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)