[Apt-offline-devel] [SCM] Offline APT Package Manager branch, master, updated. 0.9.4-5-gf045c27

Ritesh Raj Sarraf rrs at researchut.com
Sat Oct 17 18:55:09 UTC 2009


The following commit has been merged in the master branch:
commit 07c7aa87e7ed5f61593fc60764f5357d4444df60
Author: Ritesh Raj Sarraf <rrs at researchut.com>
Date:   Sun Oct 18 00:07:20 2009 +0530

    show the actual total number of items in the progress bar

diff --git a/AptOfflineCoreLib.py b/AptOfflineCoreLib.py
index 7e59cde..25e6651 100644
--- a/AptOfflineCoreLib.py
+++ b/AptOfflineCoreLib.py
@@ -212,9 +212,9 @@ class DownloadFromWeb(AptOfflineLib.ProgressBar):
         This class also inherits progressbar functionalities from
         parent class, ProgressBar'''
         
-        def __init__(self, width):
+        def __init__(self, width, total_itmes):
                 '''width = Progress Bar width'''
-                AptOfflineLib.ProgressBar.__init__(self, width=width)
+                AptOfflineLib.ProgressBar.__init__(self, width=width, total_items)
         
         def download_from_web(self, url, file, download_dir):
                 '''url = url to fetch
@@ -434,18 +434,13 @@ def fetcher( args ):
                         log.verbose( "WARNING: cache dir %s is incorrect. Did you give the full path ?\n" % (Str_CacheDir) )
         
         class FetcherClass( DownloadFromWeb, AptOfflineLib.Archiver, AptOfflineLib.Checksum ):
-                def __init__( self, width, lock ):
-                        DownloadFromWeb.__init__( self, width=width )
+                def __init__( self, width, lock, total_items ):
+                        DownloadFromWeb.__init__( self, width=width, total_items )
                         #ProgressBar.__init__(self, width)
                         #self.width = width
                         AptOfflineLib.Archiver.__init__( self, lock=lock )
                         #self.lock = lock
         
-        #global FetcherInstance
-        FetcherInstance = FetcherClass( width=30, lock=True )
-        #INFO: For the Progress Bar
-        #progbar = ProgressBar(width = 30)
-        
         if Str_DownloadDir is None:
                 import tempfile
                 tempdir = tempfile.gettempdir()
@@ -506,10 +501,15 @@ def fetcher( args ):
                 FetchData['Item'] = []
                 for item in raw_data_list:
                         FetchData['Item'].append( item )
-                
-        
         del raw_data_list
         
+        # INFO: Let's get the total number of items. This will get the
+        # correct total count in the progress bar.
+        total_items = len(FetchData.keys() )
+        
+        #global FetcherInstance
+        FetcherInstance = FetcherClass( width=30, lock=True, total_items )
+        
         #INFO: Thread Support
         if Int_NumOfThreads > 2:
                 log.msg("WARNING: If you are on a slow connection, it is good to\n")
diff --git a/AptOfflineLib.py b/AptOfflineLib.py
index dfe8a51..151c03d 100644
--- a/AptOfflineLib.py
+++ b/AptOfflineLib.py
@@ -263,7 +263,7 @@ class Log:
 
 class ProgressBar( object ):
         
-        def __init__( self, minValue=0, maxValue=0, width=None, fd=sys.stderr ):
+        def __init__( self, minValue=0, maxValue=0, width=None, total_items=None, fd=sys.stderr ):
                 #width does NOT include the two places for [] markers
                 self.min = minValue
                 self.max = maxValue
@@ -283,7 +283,12 @@ class ProgressBar( object ):
                         self.width = width
             
                 self.value = self.min
-                self.items = 0 #count of items being tracked
+                
+                if total_items is None:
+                        self.items = 0 #count of items being tracked
+                else:
+                        self.items = total_items
+                        
                 self.complete = 0
         
         def handle_resize( self, signum, frame ):
@@ -305,7 +310,7 @@ class ProgressBar( object ):
         def addItem( self, maxValue ):
                 self.max = self.max + maxValue
                 self.span = float( self.max - self.min )
-                self.items = self.items + 1
+                #self.items = self.items + 1
                 self.display()
         
         def display( self ):

-- 
Offline APT Package Manager



More information about the Apt-offline-devel mailing list