[Piuparts-commits] [SCM] piuparts git repository branch, piatti, updated. 0.44-805-gcb3c644

Andreas Beckmann debian at abeckmann.de
Tue Jun 19 08:54:39 UTC 2012


The following commit has been merged in the piatti branch:
commit a0bc2ffc3d5af15f0cd0ca6ef6d35b59bd6800b0
Author: Andreas Beckmann <debian at abeckmann.de>
Date:   Fri Jun 15 19:38:20 2012 +0200

    p-s: implement proper Ctrl-C handling
    
    press Ctrl-C once to exit after the current piuparts test has finished
    press Ctrl-C again to cleanly terminate the currently running test
    press Ctrl-C again to abort any ongoing cleanup
    
    Signed-off-by: Andreas Beckmann <debian at abeckmann.de>

diff --git a/debian/changelog b/debian/changelog
index 822b458..a136afa 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -136,6 +136,10 @@ piuparts (0.45) UNRELEASED; urgency=low
     - Don't update the tarball for disabled sections.
     - Rewrite starting piuparts.
     - Rewrite stopping piuparts for more reliable cleanup.
+    - Introduce Ctrl-C/SIGINT handling:
+      press Ctrl-C once to exit after the current piuparts test has finished,
+      press Ctrl-C again to cleanly terminate the currently running test,
+      press Ctrl-C again to abort any ongoing cleanup.
   * piuparts-report.py:
     - Remove known_circular_depends handling.
     - Exclude obsolete states from generated report.
diff --git a/piuparts-slave.py b/piuparts-slave.py
index 906b486..f5be5e2 100644
--- a/piuparts-slave.py
+++ b/piuparts-slave.py
@@ -41,6 +41,9 @@ import piupartslib.packagesdb
 CONFIG_FILE = "/etc/piuparts/piuparts.conf"
 MAX_WAIT_TEST_RUN = 45*60
 
+interrupted = False
+old_sigint_handler = None
+
 def setup_logging(log_level, log_file_name):
     logger = logging.getLogger()
     logger.setLevel(log_level)
@@ -95,6 +98,13 @@ class Alarm(Exception):
 def alarm_handler(signum, frame):
     raise Alarm
 
+def sigint_handler(signum, frame):
+    global interrupted
+    interrupted = True
+    print '\nSlave interrupted by the user, waiting for the current test to finish.'
+    print 'Press Ctrl-C again to abort now.'
+    signal(SIGINT, old_sigint_handler)
+
 
 class MasterIsBusy(Exception):
 
@@ -420,6 +430,8 @@ class Section:
                             log_name(package_name, version)),
                             "Package %s not found" % package_name)
             self._slave.forget_reserved(package_name, version)
+            if interrupted:
+                raise KeyboardInterrupt
         return test_count
 
 
@@ -494,11 +506,21 @@ def run_test_with_timeout(cmd, maxwait, kill_all=True):
     except Alarm:
         terminate_subprocess(p, kill_all)
         return -1,stdout
+    except KeyboardInterrupt:
+        print '\nSlave interrupted by the user, cleaning up...'
+        try:
+            kill_subprocess(p, kill_all)
+        except KeyboardInterrupt:
+            print '\nTerminating piuparts was interrupted... manual cleanup still neccessary.'
+            raise
+        raise
 
     return p.returncode,stdout
 
 
 def test_package(config, package, packages_files):
+    global old_sigint_handler
+    old_sigint_handler = signal(SIGINT, sigint_handler)
     logging.info("Testing package %s/%s %s" % (config.section, package["Package"], package["Version"]))
 
     output_name = log_name(package["Package"], package["Version"])
@@ -555,6 +577,7 @@ def test_package(config, package, packages_files):
         subdir = "pass"
     os.rename(new_name, os.path.join(subdir, output_name))
     logging.debug("Done with %s: %s (%d)" % (output_name, subdir, ret))
+    signal(SIGINT, old_sigint_handler)
 
 
 def create_chroot(config, tarball, distro):
@@ -664,7 +687,7 @@ if __name__ == "__main__":
      main()
   except KeyboardInterrupt:
      print ''
-     print 'Slave interrupted by the user, exiting... manual cleanup still neccessary.'
+     print 'Slave interrupted by the user, exiting...'
      sys.exit(1)
 
 # vi:set et ts=4 sw=4 :

-- 
piuparts git repository



More information about the Piuparts-commits mailing list