[Apt-offline-devel] [SCM] Offline APT Package Manager branch, apt-offline-qt, updated. v0.9.9-110-gdeef88f
Manish Sinha
manishsinha.tech at gmail.com
Sat Aug 21 15:39:58 UTC 2010
The following commit has been merged in the apt-offline-qt branch:
commit 197d01185aaec2e94256a84e30ead62ebdb1c79f
Author: Manish Sinha <manishsinha.tech at gmail.com>
Date: Sun Feb 14 01:53:20 2010 +0530
Added support for ProgressBar
diff --git a/apt_offline_core/AptOfflineCoreLib.py b/apt_offline_core/AptOfflineCoreLib.py
index 063eae6..d914fb3 100644
--- a/apt_offline_core/AptOfflineCoreLib.py
+++ b/apt_offline_core/AptOfflineCoreLib.py
@@ -64,6 +64,7 @@ except ImportError:
PythonApt = False #Remove it after porting to python-apt
import AptOfflineLib
+import apt_offline_gui.QtProgressBar
#INFO: Set the default timeout to 30 seconds for the packages that are being downloaded.
socket.setdefaulttimeout(30)
@@ -291,7 +292,14 @@ class DownloadFromWeb(AptOfflineLib.ProgressBar, GenericDownloadFunction):
'''width = Progress Bar width'''
AptOfflineLib.ProgressBar.__init__(self, width=width, total_items=total_items)
+class QtDownloadFromWeb(apt_offline_gui.QtProgressBar.QtProgressBar, GenericDownloadFunction):
+ '''Class for DownloadFromWeb
+ This class also inherits progressbar functionalities from
+ parent class, ProgressBar'''
+ def __init__(self,progressbar,label, total_items):
+ '''width = Progress Bar width'''
+ apt_offline_gui.QtProgressBar.QtProgressBar.__init__(self,progressbar=progressbar,label=label, total_items=total_items)
def stripper(item):
@@ -453,6 +461,14 @@ def fetcher( args ):
AptOfflineLib.Archiver.__init__( self, lock=lock )
#self.lock = lock
+ class QtFetcherClass( QtDownloadFromWeb, AptOfflineLib.Archiver, AptOfflineLib.Checksum ):
+ def __init__( self, progress_bar, progress_label ,lock, total_items ):
+ QtDownloadFromWeb.__init__( self, progressbar=progress_bar, label=progress_label, total_items=total_items )
+ #ProgressBar.__init__(self, width)
+ #self.width = width
+ AptOfflineLib.Archiver.__init__( self, lock=lock )
+ #self.lock = lock
+
if Str_DownloadDir is None:
tempdir = tempfile.gettempdir()
if os.access( tempdir, os.W_OK ) is True:
@@ -519,7 +535,14 @@ def fetcher( args ):
total_items = len(FetchData['Item'])
#global FetcherInstance
- FetcherInstance = FetcherClass( width=30, lock=True, total_items=total_items )
+ try:
+ gui = args.qt_gui
+ progress = args.progress_bar
+ progressLabel = args.progress_label
+ FetcherInstance = QtFetcherClass(progress=progress, progressLabel=progressLabel, lock=True, total_items=total_items )
+ except AttributeError:
+ FetcherInstance = FetcherClass( width=30, lock=True, total_items=total_items )
+
#INFO: Thread Support
if Int_NumOfThreads > 2:
diff --git a/apt_offline_gui/QtProgressBar.py b/apt_offline_gui/QtProgressBar.py
new file mode 100644
index 0000000..86e5323
--- /dev/null
+++ b/apt_offline_gui/QtProgressBar.py
@@ -0,0 +1,69 @@
+class QtProgressBar( object ):
+
+ def __init__( self, progressbar=None,label =None, minValue=0, maxValue=0, total_items=None):
+ self.min = minValue
+ self.max = maxValue
+ self.span = float( self.max - self.min )
+ self.fd = fd
+ self.signal_set = False
+
+ # This field stores QProgessBar
+ self.progressBar = progressbar
+ # This field stores the Label
+ self.progressLabel = label
+
+ self.value = self.min
+
+ if total_items is None or total_items <= 0:
+ self.items = 0 #count of items being tracked
+ self.items_update = True
+ else:
+ self.items = total_items
+ self.items_update = False
+
+ self.complete = 0
+
+ def handle_resize( self, signum, frame ):
+ h, w = array( 'h', ioctl( self.fd, termios.TIOCGWINSZ, '\0' * 8 ) )[:2]
+ self.width = w
+
+ def updateValue( self, newValue ):
+ #require caller to supply a value! newValue is the increment from last call
+ self.value = max( self.min, min( self.max, self.value + newValue ) )
+ self.display()
+
+ def completed( self ):
+ self.complete = self.complete + 1
+
+ #if self.signal_set:
+ #signal.signal( signal.SIGWINCH, signal.SIG_DFL )
+ self.display()
+
+ def addItem( self, maxValue ):
+ self.max = self.max + maxValue
+ self.span = float( self.max - self.min )
+ if self.items_update is True:
+ self.items = self.items + 1
+ self.display()
+
+ def display( self ):
+ #print "\r%3s /%3s items: %s\r" % ( self.complete, self.items, str( self ) ),
+ self.progressBar.setValue(int(self.__str__()))
+ progressText = "%3s /%3s Size: %s" % ( self.complete, self.items, self.__numStr__( self.max / 1024 ))
+ self.progressLabel.setText(progressText)
+
+ def __str__( self ):
+ #compute display fraction
+ percentFilled = ( ( self.value - self.min ) / self.span )
+ #widthFilled = int( self.width * percentFilled + 0.5 )
+ #return ( "[" + "#"*widthFilled + " " * ( self.width - widthFilled ) + "]" + " %5.1f%% of %s" % ( percentFilled * 100.0, self.__numStr__( self.max / 1024 ) ) )
+ return percentFilled
+
+ def __numStr__( self, size ):
+ if size > 1024:
+ size = size / 1024
+ if size > 1024:
+ size = size / 1024
+ return ( "%d GiB" % ( size ) )
+ return ( "%d MiB" % ( size ) )
+ return ( "%d KiB" % ( size ) )
--
Offline APT Package Manager
More information about the Apt-offline-devel
mailing list