Package yum :: Module callbacks
[hide private]
[frames] | no frames]

Source Code for Module yum.callbacks

  1  #!/usr/bin/python -tt 
  2  # This program is free software; you can redistribute it and/or modify 
  3  # it under the terms of the GNU General Public License as published by 
  4  # the Free Software Foundation; either version 2 of the License, or 
  5  # (at your option) any later version. 
  6  # 
  7  # This program is distributed in the hope that it will be useful, 
  8  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  9  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 10  # GNU Library General Public License for more details. 
 11  # 
 12  # You should have received a copy of the GNU General Public License 
 13  # along with this program; if not, write to the Free Software 
 14  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 15   
 16  # imports 
 17   
 18  import logging  
 19  from urlgrabber.progress import BaseMeter,format_time,format_number 
 20   
 21   
 22  # ProcessTransaction States 
 23   
 24  PT_DOWNLOAD        = 10    # Start Download 
 25  PT_DOWNLOAD_PKGS   = 11    # Packages to download 
 26  PT_GPGCHECK        = 20    # Start Checkin Package Signatures 
 27  PT_TEST_TRANS      = 30    # Start Test Transaction 
 28  PT_TRANSACTION     = 40    # Start Transaction 
 29   
 30  PT_MESSAGES = { PT_DOWNLOAD    : "Downloading Packages", 
 31                  PT_GPGCHECK    : "Check Package Signatures", 
 32                  PT_TEST_TRANS  : "Running Test Transaction", 
 33                  PT_TRANSACTION : "Running Transaction"} 
 34   
 35   
 36   
37 -class ProcessTransBaseCallback:
38
39 - def __init__(self):
40 self.logger = logging.getLogger('yum.verbose.ProcessTrasactionBaseCallback')
41
42 - def event(self,state,data=None):
43 if state in PT_MESSAGES.keys(): 44 self.logger.info(PT_MESSAGES[state])
45
46 -class ProcessTransNoOutputCallback:
47 - def __init__(self):
48 pass
49
50 - def event(self,state,data=None):
51 pass
52
53 -class DownloadBaseCallback( BaseMeter ):
54 """ 55 This is class is a base class to use by implement a download progress 56 handler to be used with YumBase.repos.setProgressBar. 57 58 Example: 59 60 from yum.callbacks import DownloadBaseCallback 61 62 class MyDownloadCallback( DownloadBaseCallback ): 63 64 def updateProgress(self,name,frac,fread,ftime): 65 ''' 66 Update the progressbar 67 @param name: filename 68 @param frac: Progress fracment (0 -> 1) 69 @param fread: formated string containing BytesRead 70 @param ftime : formated string containing remaining or elapsed time 71 ''' 72 pct = int( frac*100 ) 73 print " %s : %s " % (name,pct) 74 75 76 if __name__ == '__main__': 77 my = YumBase() 78 my.doConfigSetup() 79 dnlcb = MyDownloadCallback() 80 my.repos.repos.setProgressBar( dnlcb ) 81 for pkg in my.pkgSack: 82 print pkg.name 83 84 """ 85
86 - def __init__(self):
87 BaseMeter.__init__( self ) 88 self.totSize = "" # Total size to download in a formatted string (Kb, MB etc)
89
90 - def update( self, amount_read, now=None ):
91 BaseMeter.update( self, amount_read, now )
92
93 - def _do_start( self, now=None ):
94 name = self._getName() 95 self.updateProgress(name,0.0,"","") 96 if not self.size is None: 97 self.totSize = format_number( self.size )
98
99 - def _do_update( self, amount_read, now=None ):
100 fread = format_number( amount_read ) 101 name = self._getName() 102 if self.size is None: 103 # Elapsed time 104 etime = self.re.elapsed_time() 105 fetime = format_time( etime ) 106 frac = 0.0 107 self.updateProgress(name,frac,fread,fetime) 108 else: 109 # Remaining time 110 rtime = self.re.remaining_time() 111 frtime = format_time( rtime ) 112 frac = self.re.fraction_read() 113 self.updateProgress(name,frac,fread,frtime)
114 115
116 - def _do_end( self, amount_read, now=None ):
117 total_time = format_time( self.re.elapsed_time() ) 118 total_size = format_number( amount_read ) 119 name = self._getName() 120 self.updateProgress(name,1.0,total_size,total_time)
121
122 - def _getName(self):
123 ''' 124 Get the name of the package being downloaded 125 ''' 126 if self.text and type( self.text ) == type( "" ): 127 name = self.text 128 else: 129 name = self.basename 130 return name
131
132 - def updateProgress(self,name,frac,fread,ftime):
133 ''' 134 Update the progressbar (Overload in child class) 135 @param name: filename 136 @param frac: Progress fracment (0 -> 1) 137 @param fread: formated string containing BytesRead 138 @param ftime : formated string containing remaining or elapsed time 139 ''' 140 pass
141