]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
scripts/patchtest: clean up main()
authorTrevor Gamblin <tgamblin@baylibre.com>
Thu, 18 Jun 2026 20:36:31 +0000 (16:36 -0400)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 29 Jun 2026 09:37:38 +0000 (10:37 +0100)
- Reference PatchtestParser members directly instead of setting local
  variables
- Remove unused variables
- Declare 'ret' just before where it gets used
- Use subprocess.run() instead of os.popen() for a cleaner 'git status'
  call
- Remove unnecessary square brackets in the status_matches if block
- Remove unneeded try-finally block

Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/patchtest

index d2f6302743ab74a92e6cfa6af62db43ca982c115..592d91dbb081388de20cccde412a0ba9b634497e 100755 (executable)
@@ -12,6 +12,7 @@
 import json
 import logging
 import os
+import subprocess
 import sys
 import traceback
 import unittest
@@ -162,16 +163,14 @@ def print_result_message(preresult, postresult):
     print("----------------------------------------------------------------------\n")
 
 def main():
-    ret = 0
-    tmp_patch = False
     patch_path = PatchtestParser.patch_path
-    log_results = PatchtestParser.log_results
-    log_path = None
-    patch_list = None
 
-    git_status = os.popen("(cd %s && git status)" % PatchtestParser.repodir).read()
+    git_status = subprocess.run(
+        ['git', '-C', PatchtestParser.repodir, 'status'],
+        capture_output=True, text=True,
+    ).stdout
     status_matches = ["Changes not staged for commit", "Changes to be committed"]
-    if any([match in git_status for match in status_matches]):
+    if any(match in git_status for match in status_matches):
         logger.error("patchtest: there are uncommitted changes in the target repo that would be overwritten. Please commit or restore them before running patchtest")
         return 1
 
@@ -180,6 +179,7 @@ def main():
     else:
         patch_list = [patch_path]
 
+    ret = 0
     for patch in patch_list:
         if os.path.getsize(patch) == 0:
             logger.error('patchtest: patch is empty')
@@ -187,19 +187,13 @@ def main():
 
         logger.info('Testing patch %s' % patch)
 
-        if log_results:
+        log_path = None
+        if PatchtestParser.log_results:
             log_path = patch + ".testresult"
             with open(log_path, "a") as f:
                 f.write("Patchtest results for patch '%s':\n\n" % patch)
 
-        try:
-            if log_path:
-                ret = run(patch, log_path)
-            else:
-                ret = run(patch)
-        finally:
-            if tmp_patch:
-                os.remove(patch)
+        ret = run(patch, log_path)
 
     return ret