[Piuparts-commits] [SCM] piuparts git repository branch, develop, updated. 0.44-679-g25460c0

Andreas Beckmann debian at abeckmann.de
Tue Jun 5 07:42:13 UTC 2012


The following commit has been merged in the develop branch:
commit 6e1965c74dfa3f723ce1b00dfcc1af909903e335
Author: Andreas Beckmann <debian at abeckmann.de>
Date:   Sun Jun 3 19:14:15 2012 +0200

    p: run(): factor out kill_subprocess()
    
    Signed-off-by: Andreas Beckmann <debian at abeckmann.de>

diff --git a/piuparts.py b/piuparts.py
index 245151d..df031e2 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -386,6 +386,19 @@ def indent_string(str):
 
 def run(command, ignore_errors=False):
     """Run an external command and die with error message if it fails."""
+
+    def kill_subprocess(p, reason):
+        logging.error("Terminating command due to %s" % reason)
+        p.terminate()
+        for i in range(10):
+            time.sleep(0.5)
+            if p.poll() is not None:
+                break
+        else:
+            logging.error("Killing command due to %s" % reason)
+            p.kill()
+        p.wait()
+
     assert type(command) == type([])
     command = [x for x in command if x] # Delete any empty argument
     logging.debug("Starting command: %s" % command)
@@ -405,16 +418,7 @@ def run(command, ignore_errors=False):
         output += p.stdout.read(1 << 16)
         if (len(output) > settings.max_command_output_size):
             excessive_output = True
-            logging.error("Terminating command due to excessive output")
-            p.terminate()
-            for i in range(10):
-                time.sleep(0.5)
-                if p.poll() is not None:
-                    break
-            else:
-                logging.error("Killing command due to excessive output")
-                p.kill()
-            p.wait()
+            kill_subprocess(p, "excessive output")
             break
     if not excessive_output:
         output += p.stdout.read(settings.max_command_output_size)

-- 
piuparts git repository



More information about the Piuparts-commits mailing list