[yum-cvs] yum output.py,1.70,1.71

Menno Smits mjs at linux.duke.edu
Sun Sep 3 21:34:58 UTC 2006


Update of /home/groups/yum/cvs/yum
In directory login1.linux.duke.edu:/tmp/cvs-serv3273

Modified Files:
	output.py 
Log Message:
Allow the interrupt callback to be set via the API. Push the command line Yum's
own interrupt callback function out of the API code.


Index: output.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/output.py,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -r1.70 -r1.71
--- output.py	25 Aug 2006 05:13:22 -0000	1.70
+++ output.py	3 Sep 2006 21:34:56 -0000	1.71
@@ -25,6 +25,7 @@
 from i18n import _
 
 from urlgrabber.progress import TextMeter
+from urlgrabber.grabber import URLGrabError
 from yum.misc import sortPkgObj
 
 try:
@@ -32,7 +33,6 @@
 except:
     pass
 
-import yum.Errors
 from yum import logginglevels
 
 class YumOutput:
@@ -329,15 +329,36 @@
         else:
             self.repos.setProgressBar(TextMeter(fo=sys.stdout))
             self.repos.callback = CacheProgressCallback()
+
         # setup our failure report for failover
         freport = (self.failureReport,(),{})
         self.repos.setFailureCallback(freport)
+
+        # setup callback for CTRL-C's
+        self.repos.setInterruptCallback(self.interrupt_callback)
         
         # setup our depsolve progress callback
         dscb = DepSolveProgressCallBack()
         self.dsCallback = dscb
             
-    
+    def interrupt_callback(self, cbobj):
+        '''Handle CTRL-C's during downloads
+
+        If a CTRL-C occurs a URLGrabError will be raised to push the download
+        onto the next mirror.  
+        
+        If two CTRL-C's occur in quick succession then yum will exit.
+
+        @param cbobj: urlgrabber callback obj
+        '''
+        now = time.time()
+        if hasattr(self, '_last_interrupt') and now - self._last_interrupt < 0.2:
+            # Two quick CTRL-C's, quit
+            raise KeyboardInterrupt
+
+        # Go to next mirror
+        self._last_interrupt = now
+        raise URLGrabError(15, 'user interrupt')
 
 class DepSolveProgressCallBack:
     """provides text output callback functions for Dependency Solver callback"""




More information about the Yum-cvs-commits mailing list