Don't check the token if -t is not defined
[snf-image-creator] / image_creator / rsync.py
index 16f3c63..08bc27a 100644 (file)
@@ -107,8 +107,7 @@ class Rsync:
 
         self._out.success("%d" % total)
 
-        progress = self._out.Progress(total, "Copying %s files to %s" %
-                                      (slabel, dlabel))
+        progress = self._out.Progress(total, "Copying files to %s" % dlabel)
         run = subprocess.Popen(cmd + [src, dest], shell=False,
                                stdout=subprocess.PIPE, bufsize=0)
         try:
@@ -124,12 +123,19 @@ class Rsync:
             progress.success('done')
 
         finally:
-            run.poll()
-            if run.returncode is None:
-                run.send_signal(signal.SIGHUP)
+            def handler(signum, frame):
+                run.terminate()
+                time.sleep(1)
+                run.poll()
+                if run.returncode is None:
+                    run.kill()
+                run.wait()
+
+            signal.signal(signal.SIGALRM, handler)
+            signal.alarm(2)
             run.communicate()
+            signal.alarm(0)
             if run.returncode != 0:
                 raise FatalError("rsync failed")
 
-
 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :