gdb: copyright: make file header scan a bit more pythonic
authorMike Frysinger <vapier@gentoo.org>
Sat, 1 Jan 2022 18:08:20 +0000 (13:08 -0500)
committerMike Frysinger <vapier@gentoo.org>
Wed, 26 Oct 2022 08:56:40 +0000 (14:41 +0545)
Should be functionally the same, but uses more pythonic idioms to get
fewer lines of code, and to make sure to not leak open file handles.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/copyright.py

index 8d623e6f5c76c387240e5a91699487811a7dd5c4..040fed1870895b6572c8166471abf61f79c7cca6 100755 (executable)
@@ -148,15 +148,12 @@ def may_have_copyright_notice(filename):
     # so just open the file as a byte stream. We only need to search
     # for a pattern that should be the same regardless of encoding,
     # so that should be good enough.
-    fd = open(filename, "rb")
-
-    lineno = 1
-    for line in fd:
-        if b"Copyright" in line:
-            return True
-        lineno += 1
-        if lineno > 50:
-            return False
+    with open(filename, "rb") as fd:
+        for lineno, line in enumerate(fd, start=1):
+            if b"Copyright" in line:
+                return True
+            if lineno > MAX_LINES:
+                break
     return False