[Apt-offline-devel] [SCM] Offline APT Package Manager branch, apt-offline-qt, updated. v0.9.9-110-gdeef88f

Ritesh Raj Sarraf rrs at researchut.com
Sat Aug 21 15:40:16 UTC 2010


The following commit has been merged in the apt-offline-qt branch:
commit ff3e30efaac98855ef03535eb7d49ebb6cb532a6
Merge: a788c68a4140965cde6ff2ebcdb7c5225c996f66 bc1d1de3779f537eafd3a70fd006fd49ca4ca993
Author: Ritesh Raj Sarraf <rrs at researchut.com>
Date:   Sat Aug 21 20:47:28 2010 +0530

    Merge branch 'ideamonk-master' into apt-offline-qt
    
    * ideamonk-master:
      installer progressbar added
      thread's finished state is now handled in installer - re-enables buttions
      added enable/disable of action buttons on install
      snap - http://twitpic.com/2g978t/full , removed commented unused codes in installer
      very basic sync functionality of install tested, no progress, no status change, just raw logs of what was synced comes up into UI on install, no post success or failure handlers yet implemented
      Fixed progress bar bug, Download progress works as it used to, looked pretty smooth right now :D
      If the user is not logged in with root priviliges, it shows up a prompt
      http://twitpic.com/171zjf progress bar is yet to be perfected, it skips out the FAILED files...
      real progress working, also fetched missing update file sizes to show progress, less time consuming than earlier implementation
      real progress bar works, but some odd changes to core lib, trying to find a better way
      Changed Ui_AptoFflineQtInstall.py
      Added support for ProgressBar
      Added .gitignore
    
    Conflicts:
    	apt_offline_core/AptOfflineCoreLib.py

diff --combined apt_offline_core/AptOfflineCoreLib.py
index 2949c4e,bd40151..e99763d
--- a/apt_offline_core/AptOfflineCoreLib.py
+++ b/apt_offline_core/AptOfflineCoreLib.py
@@@ -1,6 -1,7 +1,6 @@@
 -# -*- coding: utf-8 -*-
  
  ############################################################################
 -#    Copyright (C) 2005, 2009 Ritesh Raj Sarraf                            #
 +#    Copyright (C) 2005, 2010 Ritesh Raj Sarraf                            #
  #    rrs at researchut.com                                                    #
  #                                                                          #
  #    This program is free software; you can redistribute it and/or modify  #
@@@ -27,6 -28,7 +27,6 @@@ import strin
  import urllib2
  import Queue
  import threading
 -import optparse
  import socket
  import tempfile
  
@@@ -50,7 -52,9 +50,9 @@@ except ImportError
  
  import AptOfflineMagicLib
  
+ #INFO: added to store progressbar info
  guiBool = False
+ totalSize = [0,0]             # total_size, current_total
  
  #INFO: Check if python-apt is installed
  PythonApt = True
@@@ -62,6 -66,7 +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)
@@@ -74,11 -79,11 +77,11 @@@ figuring out if the packages are in th
  
  
  app_name = "apt-offline"
 -version = "0.9.6"
 -copyright = "(C) 2005 - 2009 Ritesh Raj Sarraf"
 +version = "0.9.9"
 +copyright = "(C) 2005 - 2010 Ritesh Raj Sarraf"
  terminal_license = "This program comes with ABSOLUTELY NO WARRANTY.\n\
  This is free software, and you are welcome to redistribute it under\n\
 -the GNU GPL License\n"
 +the GNU GPL Version 3 (or later) License\n"
          
  errlist = []
  supported_platforms = ["Linux", "GNU/kFreeBSD", "GNU"]
@@@ -252,7 -257,11 +255,11 @@@ class GenericDownloadFunction()
                                  i += block_size
                                  counter += 1
                                  self.updateValue(increment)
+                                 #REAL_PROGRESS: update current total in totalSize
+                                 totalSize[1] += block_size
+                                 
                          self.completed()
+                         
                          data.close()
                          temp.close()
                          return True
@@@ -289,7 -298,14 +296,14 @@@ class DownloadFromWeb(AptOfflineLib.Pro
                  '''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):
@@@ -302,19 -318,14 +316,19 @@@
          and returns them.'''
      
          item = item.split(' ')
 +	log.verbose("Item is %s\n" % (item) )
 +
          url = string.rstrip(string.lstrip(''.join(item[0]), chars="'"), chars="'")
          file = string.rstrip(string.lstrip(''.join(item[1]), chars="'"), chars="'")
          size = int(string.rstrip(string.lstrip(''.join(item[2]), chars = "'"), chars="'"))
          #INFO: md5 ends up having '\n' with it.
          # That needs to be stripped too.
 -        checksum = string.rstrip(string.lstrip(''.join(item[3]), chars = "'"), chars = "'")
 -        checksum = string.rstrip(checksum, chars = "\n")
 -    
 +	try:
 +		checksum = string.rstrip(string.lstrip(''.join(item[3]), chars = "'"), chars = "'")
 +        	checksum = string.rstrip(checksum, chars = "\n")
 +	except IndexError:
 +		if item[1].endswith("_Release") or item[1].endswith("_Release.gpg"):
 +			checksum = None
          return url, file, size, checksum
  
  
@@@ -328,11 -339,10 +342,11 @@@ def errfunc(errno, errormsg, filename)
          be well accessible.
          This function does the job of behaving accordingly
          as per the error codes.'''
 -        error_codes = [-3, 13, 504, 404, 10060, 104, 101010]
 +        error_codes = [-3, 13, 504, 404, 401, 10060, 104, 101010]
          # 104, 'Connection reset by peer'
          # 504 is for gateway timeout
          # 404 is for URL error. Page not found.
 +        # 401 is for Restricted pages
          # 10060 is for Operation Time out. There can be multiple reasons for this timeout
          # 101010 is for socket max retry count
          # 10054 is for Socket Timeout. Socket Timeout are seen during network congestion
@@@ -357,7 -367,8 +371,7 @@@
                  log.err("Explicit program termination %s\n" % (errno))
                  sys.exit(errno)
          else:
 -                log.err("I don't understand this error code %s\n" % (errno))
 -                sys.exit(errno)
 +                log.err("I don't understand this error code %s\nPlease file a bug report" % (errno))
          
          
  def get_pager_cmd(pager_cmd = None):
@@@ -438,10 -449,10 +452,10 @@@ def fetcher( args )
                  log.verbose( "\nMD5/SHA256 Checksum is being disabled. You need atleast Python 2.5 to do checksum verification.\n" )
          
          if Str_GetArg:
 -                if os.access( Str_GetArg, os.F_OK):
 +                if os.path.isfile(Str_GetArg):
                          log.msg( "\nFetching APT Data\n\n" )
                  else:
 -                        log.err( "\nFile not present. Check path.\n" )
 +                        log.err( "File not present. Check path.\n" )
                          sys.exit( 1 )
                          
          if Str_CacheDir is not None:
@@@ -456,6 -467,14 +470,14 @@@
                          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:
@@@ -522,7 -541,12 +544,12 @@@
          total_items = len(FetchData['Item'])
          
          #global FetcherInstance
-         FetcherInstance = FetcherClass( width=30, lock=True, total_items=total_items )
+         try:
+             gui = args.qt_gui
+             FetcherInstance = QtFetcherClass(progress_bar=args.progress, progress_label=args.progress_label, 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:
@@@ -531,185 -555,189 +558,185 @@@
                  log.msg("WARNING: Else higher number of threads executed could cause\n")
                  log.msg("WARNING: network congestion and timeouts.\n\n")
          
 -        def run(request, response, func=find_first_match):
 +        def DataFetcher(request, response, func=find_first_match):
                  '''Get items from the request Queue, process them
                  with func(), put the results along with the
                  Thread's name into the response Queue.
                  Stop running when item is None.'''
 -                while 1:
 -                        tuple_item_key = request.get()
 -                        if tuple_item_key is None:
 -                                break
 -                        (key, item) = tuple_item_key
 +                #while 1:
 +                #tuple_item_key = request.get()
 +                #if tuple_item_key is None:
 +                #        break
 +                #(key, item) = tuple_item_key
 +                
 +                (key, item) = request
 +
 +		# On many boxes, the cdrom apt repository will be enabled.
 +		# For now, let's skip the cdrom repository items.
 +		if item.startswith("\'cdrom"):
 +			log.verbose("cdrom apt repository not supported. Skipping\n")
 +			log.verbose(item)
 +			return True
 +                
 +                #INFO: Everything
 +                (url, file, download_size, checksum) = stripper(item)
 +                thread_name = threading.currentThread().getName()
 +                log.verbose("Thread is %s\n" % (thread_name) )
 +                
 +                if url.endswith(".deb"):
 +                        try:
 +                                PackageName = file.split("_")[0]
 +                        except IndexError:
 +                                log.err("Not getting a package name here is problematic. Better bail out.\n")
 +                                sys.exit(1)
                          
 -                        #INFO: Everything
 -                        (url, file, download_size, checksum) = stripper(item)
 -                        thread_name = threading.currentThread().getName()
 -                        log.verbose("Thread is %s\n" % (thread_name) )
 +                        #INFO: For Package version, we don't want to fail
 +                        try:
 +                                PackageVersion = file.split("_")[1]
 +                        except IndexError:
 +                                PackageVersion = "NA"
 +                                log.verbose("Weird!! Package version not present. Is it really a deb file?\n")
                          
 -                        if url.endswith(".deb"):
 -                                try:
 -                                        PackageName = file.split("_")[0]
 -                                except IndexError:
 -                                        log.err("Not getting a package name here is problematic. Better bail out.\n")
 -                                        sys.exit(1)
 -                                
 -                                #INFO: For Package version, we don't want to fail
 -                                try:
 -                                        PackageVersion = file.split("_")[1]
 -                                except IndexError:
 -                                        PackageVersion = "NA"
 -                                        log.verbose("Weird!! Package version not present. Is it really a deb file?\n")
 -                                
 -                                response.put(func(Str_CacheDir, file) ) 
 -                                #INFO: find_first_match() returns False or a file name with absolute path
 -                                full_file_path = response.get()
 -                                #INFO: If we find the file in the local Str_CacheDir, we'll execute this block.
 -                                if full_file_path != False:
 -                                        # We'll first check for its md5 checksum
 -                                        if Bool_DisableMD5Check is False:
 -                                                if FetcherInstance.CheckHashDigest(full_file_path, checksum) is True:
 -                                                        log.verbose("Checksum correct for package %s.%s\n" % (PackageName, LINE_OVERWRITE_FULL) )
 -                                                        if Bool_BugReports:
 -                                                                bug_fetched = 0
 -                                                                log.verbose("Fetching bug reports for package %s.%s\n" % (PackageName, LINE_OVERWRITE_FULL) )
 -                                                                if FetchBugReportsDebian.FetchBugsDebian(PackageName) in [1,2]:
 -                                                                        log.verbose("Fetched bug reports for package %s.%s\n" % (PackageName, LINE_OVERWRITE_FULL) )
 -                                                                        bug_fetched = 1
 -                                                                else:
 -                                                                        log.verbose("Couldn't fetch bug reports for package %s.%s\n" % (PackageName, LINE_OVERWRITE_MID) )
 -                                                        if Str_BundleFile:
 -                                                                if FetcherInstance.compress_the_file(Str_BundleFile, full_file_path) is True:
 -                                                                        log.success("%s copied from local cache directory %s.%s\n" % (PackageName, Str_CacheDir, LINE_OVERWRITE_MID) )
 -                                                                else:
 -                                                                        log.err("Couldn't add %s to archive %s.%s\n" % (file, Str_BundleFile, LINE_OVERWRITE_MID) )
 -                                                                        sys.exit(1)
 -                                                        #INFO: If no zip option enabled, simply copy the downloaded package file
 -                                                        # along with the downloaded bug reports.
 -                                                        else:
 -                                                                try:
 -                                                                        shutil.copy(full_file_path, Str_DownloadDir)
 -                                                                        log.success("%s copied from local cache directory %s.%s\n" % (PackageName, Str_CacheDir, LINE_OVERWRITE_MID) )
 -                                                                except shutil.Error:
 -                                                                        log.verbose("%s already available in %s. Skipping copy!!!%s\n" % (file, Str_DownloadDir, LINE_OVERWRITE_MID) )
 -                                                                
 -                                                                if bug_fetched == 1:
 -                                                                        for x in os.listdir(os.curdir):
 -                                                                                if (x.startswith(PackageName) and x.endswith(apt_bug_file_format) ):
 -                                                                                        shutil.move(x, Str_DownloadDir)
 -                                                                                        log.verbose("Moved %s file to %s folder.%s\n" % (x, Str_DownloadDir, LINE_OVERWRITE_FULL) )
 -                                                #INFO: Damn!! The md5chesum didn't match :-(
 -                                                # The file is corrupted and we need to download a new copy from the internet
 -                                                else:
 -                                                        log.verbose("%s checksum mismatch. Skipping file.%s\n" % (file, LINE_OVERWRITE_FULL) )
 -                                                        log.msg("Downloading %s - %s %s\n" % (PackageName, log.calcSize(download_size/1024), LINE_OVERWRITE_MID) )
 -                                                        if FetcherInstance.download_from_web(url, file, Str_DownloadDir) == True:
 -                                                                log.success("\r%s done.%s\n" % (PackageName, LINE_OVERWRITE_FULL) )
 -                                                                
 -                                                                #Add to Str_CacheDir if possible
 -                                                                if Str_CacheDir and os.access(Str_CacheDir, os.W_OK) == True:
 -                                                                        try:
 -                                                                                shutil.copy(file, Str_CacheDir)
 -                                                                                log.verbose("%s copied to local cache directory %s.%s\n" % (file, Str_CacheDir, LINE_OVERWRITE_MID) )
 -                                                                        except shutil.Error:
 -                                                                                log.verbose("Couldn't copy %s to %s.%s\n" % (file, Str_CacheDir, LINE_OVERWRITE_FULL) )
 -                                                                else:
 -                                                                        log.verbose("cache_dir %s is not writeable. Skipping copy to it.\n" % (Str_CacheDir) )
 -                                                                
 -                                                                #Fetch bug reports
 -                                                                if Bool_BugReports:
 -                                                                        log.verbose("Fetching bug reports for package %s.%s\n" % (PackageName, LINE_OVERWRITE_MID) )
 -                                                                        if FetchBugReportsDebian.FetchBugsDebian( PackageName ) in [1, 2]:
 -                                                                                log.verbose( "Fetched bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
 -                                                                        else:
 -                                                                                log.verbose( "Couldn't fetch bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
 -                                                                if Str_BundleFile:
 -                                                                        if FetcherInstance.compress_the_file( Str_BundleFile, file ) != True:
 -                                                                                log.err( "Couldn't archive %s to file %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
 -                                                                                sys.exit( 1 )
 -                                                                        else:
 -                                                                                log.verbose( "%s added to archive %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
 -                                                                                os.unlink( os.path.join( Str_DownloadDir, file ) )
 -                                        #INFO: You're and idiot.
 -                                        # You should NOT disable md5checksum for any files
 -                                        else:
 +                        
 +                        #INFO: find_first_match() returns False or a file name with absolute path
 +                        full_file_path = func(Str_CacheDir, file)
 +                        #INFO: If we find the file in the local Str_CacheDir, we'll execute this block.
 +                        if full_file_path != False:
 +                                # We'll first check for its md5 checksum
 +                                if Bool_DisableMD5Check is False:
 +                                        if FetcherInstance.CheckHashDigest(full_file_path, checksum) is True:
 +                                                log.verbose("Checksum correct for package %s.%s\n" % (PackageName, LINE_OVERWRITE_FULL) )
 +                                                
 +                                                bug_fetched = False
                                                  if Bool_BugReports:
 -                                                        bug_fetched = 0
 -                                                        log.verbose("Fetching bug reports for package %s.%s\n" % (PackageName, LINE_OVERWRITE_MID) )
 -                                                        if FetchBugReportsDebian.FetchBugsDebian( PackageName ) in [1, 2]:
 -                                                                log.verbose( "Fetched bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
 -                                                                bug_fetched = 1
 +                                                        log.verbose("Fetching bug reports for package %s.%s\n" % (PackageName, LINE_OVERWRITE_FULL) )
 +                                                        if FetchBugReportsDebian.FetchBugsDebian(PackageName) in [1,2]:
 +                                                                log.verbose("Fetched bug reports for package %s.%s\n" % (PackageName, LINE_OVERWRITE_FULL) )
 +                                                                bug_fetched = True
                                                          else:
 -                                                                log.verbose( "Couldn't fetch bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
 -                                    
 -                                                #FIXME: Don't know why this was really required. If this has no changes, delete it.
 -                                                #file = full_file_path.split("/")
 -                                                #file = file[len(file) - 1]
 -                                                #file = download_path + "/" + file
 +                                                                log.verbose("Couldn't fetch bug reports for package %s.%s\n" % (PackageName, LINE_OVERWRITE_MID) )
 +                                                                
                                                  if Str_BundleFile:
 -                                                        if FetcherInstance.compress_the_file( Str_BundleFile, file ) != True:
 -                                                                log.err( "Couldn't archive %s to file %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
 -                                                                sys.exit( 1 )
 +                                                        if FetcherInstance.compress_the_file(Str_BundleFile, full_file_path) is True:
 +                                                                log.success("%s copied from local cache directory %s.%s\n" % (PackageName, Str_CacheDir, LINE_OVERWRITE_MID) )
                                                          else:
 -                                                                log.verbose( "%s added to archive %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
 -                                                                os.unlink( os.path.join( Str_DownloadDir, file ) )
 +                                                                log.err("Couldn't add %s to archive %s.%s\n" % (file, Str_BundleFile, LINE_OVERWRITE_MID) )
 +                                                                sys.exit(1)
 +                                                #INFO: If no zip option enabled, simply copy the downloaded package file
 +                                                # along with the downloaded bug reports.
                                                  else:
 -                                                        # Since zip file option is not enabled let's copy the file to the target folder
                                                          try:
 -                                                                shutil.copy( full_file_path, Str_DownloadDir )
 -                                                                log.success( "%s copied from local cache directory %s.%s\n" % ( file, Str_CacheDir, LINE_OVERWRITE_SMALL ) )
 +                                                                shutil.copy(full_file_path, Str_DownloadDir)
 +                                                                log.success("%s copied from local cache directory %s.%s\n" % (PackageName, Str_CacheDir, LINE_OVERWRITE_MID) )
                                                          except shutil.Error:
 -                                                                log.verbose( "%s already available in dest_dir. Skipping copy!!!%s\n" % ( file, LINE_OVERWRITE_SMALL ) )
 -                                    
 -                                                        # And also the bug reports
 -                                                        if bug_fetched == 1:
 -                                                                for x in os.listdir( os.curdir ):
 -                                                                        if ( x.startswith( PackageName ) and x.endswith( apt_bug_file_format ) ):
 -                                                                                shutil.move( x, Str_DownloadDir )
 -                                                                                log.verbose( "Moved %s file to %s folder.%s\n" % ( x, Str_DownloadDir, LINE_OVERWRITE_MID ) )
 -                                        
 -                                else:
 -                                        #INFO: This block gets executed if the file is not found in local Str_CacheDir or Str_CacheDir is None
 -                                        # We go ahead and try to download it from the internet
 -                                        log.verbose( "%s not available in local cache %s.%s\n" % ( file, Str_CacheDir, LINE_OVERWRITE_MID ) )
 -                                        log.msg( "Downloading %s %s - %s %s\n" % ( PackageName, PackageVersion, log.calcSize( download_size / 1024 ), LINE_OVERWRITE_MID ) )
 -                                        if FetcherInstance.download_from_web( url, file, Str_DownloadDir ) == True:
 -                                                #INFO: This block gets executed if md5checksum is allowed
 -                                                if Bool_DisableMD5Check is False:
 -                                                        #INFO: Debian moved to SHA256. So we use that now. Older systems could have md5
 -                                                        log.verbose( "File %s has checksum %s\n" % ( file, checksum ) )
 -                                                        if FetcherInstance.CheckHashDigest( file, checksum ) is True:
 -                                                                if Str_CacheDir and os.access( Str_CacheDir, os.W_OK ) == True:
 -                                                                        try:
 -                                                                                shutil.copy( file, Str_CacheDir )
 -                                                                                log.verbose( "%s copied to local cache directory %s.%s\n" % ( file, Str_CacheDir, LINE_OVERWRITE_MID ) )
 -                                                                        except shutil.Error:
 -                                                                                log.verbose( "%s already available in %s. Skipping copy!!!%s\n" % ( file, Str_CacheDir, LINE_OVERWRITE_MID ) )
 -                                                                else:
 -                                                                        log.verbose( "Str_CacheDir %s is not writeable. Skipping copy to it.\n" % ( Str_CacheDir ) )
 -                                            
 -                                                                if Bool_BugReports:
 -                                                                        log.verbose("Fetching bug reports for package %s.%s\n" % (PackageName, LINE_OVERWRITE_MID) )
 -                                                                        if FetchBugReportsDebian.FetchBugsDebian( PackageName ) in [1, 2]:
 -                                                                                log.verbose( "Fetched bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
 -                                                                        else:
 -                                                                                log.verbose( "Couldn't fetch bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
 -                                            
 -                                                                if Str_BundleFile:
 -                                                                        if FetcherInstance.compress_the_file( Str_BundleFile, file ) != True:
 -                                                                                log.err( "Couldn't archive %s to file %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
 -                                                                                sys.exit( 1 )
 -                                                                        else:
 -                                                                                log.verbose( "%s added to archive %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
 -                                                                                os.unlink( os.path.join( Str_DownloadDir, file ) )
 +                                                                log.verbose("%s already available in %s. Skipping copy!!!%s\n" % (file, Str_DownloadDir, LINE_OVERWRITE_MID) )
 +                                                        
 +                                                        if bug_fetched is True:
 +                                                                for x in os.listdir(os.curdir):
 +                                                                        if (x.startswith(PackageName) and x.endswith(apt_bug_file_format) ):
 +                                                                                try:
 +                                                                                        shutil.move(x, Str_DownloadDir)
 +                                                                                except:
 +                                                                                        #INFO: This should fix DBTS #584427
 +                                                                                        log.verbose("Exception thrown. Most likely it is because the cache_dir and download_dir locations are the same.\n")
 +                                                                                log.verbose("Moved %s file to %s folder.%s\n" % (x, Str_DownloadDir, LINE_OVERWRITE_FULL) )
 +                                        #INFO: Damn!! The md5chesum didn't match :-(
 +                                        # The file is corrupted and we need to download a new copy from the internet
 +                                        else:
 +                                                log.verbose("%s checksum mismatch. Skipping file.%s\n" % (file, LINE_OVERWRITE_FULL) )
 +                                                log.msg("Downloading %s - %s %s\n" % (PackageName, log.calcSize(download_size/1024), LINE_OVERWRITE_MID) )
 +                                                if FetcherInstance.download_from_web(url, file, Str_DownloadDir) == True:
 +                                                        log.success("\r%s done.%s\n" % (PackageName, LINE_OVERWRITE_FULL) )
 +                                                        
 +                                                        #Add to Str_CacheDir if possible
 +                                                        if Str_CacheDir and os.access(Str_CacheDir, os.W_OK) == True:
 +                                                                try:
 +                                                                        shutil.copy(file, Str_CacheDir)
 +                                                                        log.verbose("%s copied to local cache directory %s.%s\n" % (file, Str_CacheDir, LINE_OVERWRITE_MID) )
 +                                                                except shutil.Error:
 +                                                                        log.verbose("Couldn't copy %s to %s.%s\n" % (file, Str_CacheDir, LINE_OVERWRITE_FULL) )
                                                          else:
 -                                                                #INFO MD5 Checksum is incorrect.
 -                                                                log.err( "%s Checksum mismatch.\n" % ( PackageName ) )
 -                                                                errlist.append( PackageName )
 +                                                                log.verbose("cache_dir %s is not writeable. Skipping copy to it.\n" % (Str_CacheDir) )
 +                                                        
 +                                                        #Fetch bug reports
 +                                                        if Bool_BugReports:
 +                                                                log.verbose("Fetching bug reports for package %s.%s\n" % (PackageName, LINE_OVERWRITE_MID) )
 +                                                                if FetchBugReportsDebian.FetchBugsDebian( PackageName ) in [1, 2]:
 +                                                                        log.verbose( "Fetched bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
 +                                                                else:
 +                                                                        log.verbose( "Couldn't fetch bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
 +                                                        if Str_BundleFile:
 +                                                                if FetcherInstance.compress_the_file( Str_BundleFile, file ) != True:
 +                                                                        log.err( "Couldn't archive %s to file %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
 +                                                                        sys.exit( 1 )
 +                                                                else:
 +                                                                        log.verbose( "%s added to archive %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
 +                                                                        os.unlink( os.path.join( Str_DownloadDir, file ) )
 +                                #INFO: You're and idiot.
 +                                # You should NOT disable md5checksum for any files
 +                                else:
 +                                        bug_fetched = False
 +                                        if Bool_BugReports:
 +                                                log.verbose("Fetching bug reports for package %s.%s\n" % (PackageName, LINE_OVERWRITE_MID) )
 +                                                if FetchBugReportsDebian.FetchBugsDebian( PackageName ) in [1, 2]:
 +                                                        log.verbose( "Fetched bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
 +                                                        bug_fetched = True
                                                  else:
 +                                                        log.verbose( "Couldn't fetch bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
 +                            
 +                                        #FIXME: Don't know why this was really required. If this has no changes, delete it.
 +                                        #file = full_file_path.split("/")
 +                                        #file = file[len(file) - 1]
 +                                        #file = download_path + "/" + file
 +                                        if Str_BundleFile:
 +                                                if FetcherInstance.compress_the_file( Str_BundleFile, file ) != True:
 +                                                        log.err( "Couldn't archive %s to file %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
 +                                                        sys.exit( 1 )
 +                                                else:
 +                                                        log.verbose( "%s added to archive %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
 +                                                        os.unlink( os.path.join( Str_DownloadDir, file ) )
 +                                        else:
 +                                                # Since zip file option is not enabled let's copy the file to the target folder
 +                                                try:
 +                                                        shutil.copy( full_file_path, Str_DownloadDir )
 +                                                        log.success( "%s copied from local cache directory %s.%s\n" % ( file, Str_CacheDir, LINE_OVERWRITE_SMALL ) )
 +                                                except shutil.Error:
 +                                                        log.verbose( "%s already available in dest_dir. Skipping copy!!!%s\n" % ( file, LINE_OVERWRITE_SMALL ) )
 +                            
 +                                                # And also the bug reports
 +                                                if bug_fetched is True:
 +                                                        for x in os.listdir( os.curdir ):
 +                                                                if ( x.startswith( PackageName ) and x.endswith( apt_bug_file_format ) ):
 +                                                                        shutil.move( x, Str_DownloadDir )
 +                                                                        log.verbose( "Moved %s file to %s folder.%s\n" % ( x, Str_DownloadDir, LINE_OVERWRITE_MID ) )
 +                                
 +                        else:
 +                                #INFO: This block gets executed if the file is not found in local Str_CacheDir or Str_CacheDir is None
 +                                # We go ahead and try to download it from the internet
 +                                log.verbose( "%s not available in local cache %s.%s\n" % ( file, Str_CacheDir, LINE_OVERWRITE_MID ) )
 +                                log.msg( "Downloading %s %s - %s %s\n" % ( PackageName, PackageVersion, log.calcSize( download_size / 1024 ), LINE_OVERWRITE_MID ) )
 +                                if FetcherInstance.download_from_web( url, file, Str_DownloadDir ) == True:
 +                                        #INFO: This block gets executed if md5checksum is allowed
 +                                        if Bool_DisableMD5Check is False:
 +                                                #INFO: Debian moved to SHA256. So we use that now. Older systems could have md5
 +                                                log.verbose( "File %s has checksum %s\n" % ( file, checksum ) )
 +                                                if FetcherInstance.CheckHashDigest( file, checksum ) is True:
 +                                                        if Str_CacheDir and os.access( Str_CacheDir, os.W_OK ) == True:
 +                                                                try:
 +                                                                        shutil.copy( file, Str_CacheDir )
 +                                                                        log.verbose( "%s copied to local cache directory %s.%s\n" % ( file, Str_CacheDir, LINE_OVERWRITE_MID ) )
 +                                                                except shutil.Error:
 +                                                                        log.verbose( "%s already available in %s. Skipping copy!!!%s\n" % ( file, Str_CacheDir, LINE_OVERWRITE_MID ) )
 +                                                        else:
 +                                                                log.verbose( "Str_CacheDir %s is not writeable. Skipping copy to it.\n" % ( Str_CacheDir ) )
 +                                    
                                                          if Bool_BugReports:
                                                                  log.verbose("Fetching bug reports for package %s.%s\n" % (PackageName, LINE_OVERWRITE_MID) )
                                                                  if FetchBugReportsDebian.FetchBugsDebian( PackageName ) in [1, 2]:
                                                                          log.verbose( "Fetched bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
                                                                  else:
                                                                          log.verbose( "Couldn't fetch bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
 -                                                        
 +                                    
                                                          if Str_BundleFile:
                                                                  if FetcherInstance.compress_the_file( Str_BundleFile, file ) != True:
                                                                          log.err( "Couldn't archive %s to file %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
@@@ -717,36 -745,17 +744,36 @@@
                                                                  else:
                                                                          log.verbose( "%s added to archive %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
                                                                          os.unlink( os.path.join( Str_DownloadDir, file ) )
 -                                            
 -                                                log.success( "\r%s %s done.%s\n" % ( PackageName, PackageVersion, LINE_OVERWRITE_FULL ) )
 +                                                        log.success( "\r%s %s done.%s\n" % ( PackageName, PackageVersion, LINE_OVERWRITE_FULL ) )
 +                                                else:
 +                                                        #INFO MD5 Checksum is incorrect.
 +                                                        log.err( "%s Checksum mismatch.\n" % ( PackageName ) )
 +                                                        errlist.append( PackageName )
                                          else:
 -                                                errlist.append( PackageName )
 +                                                if Bool_BugReports:
 +                                                        log.verbose("Fetching bug reports for package %s.%s\n" % (PackageName, LINE_OVERWRITE_MID) )
 +                                                        if FetchBugReportsDebian.FetchBugsDebian( PackageName ) in [1, 2]:
 +                                                                log.verbose( "Fetched bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
 +                                                        else:
 +                                                                log.verbose( "Couldn't fetch bug reports for package %s.%s\n" % ( PackageName, LINE_OVERWRITE_MID ) )
                                                  
 -                        else:
 -                                #INFO: We are a package update
 -                                PackageName = url
 -                                log.msg("Downloading %s.%s\n" % (PackageName, LINE_OVERWRITE_MID) ) 
 +                                                if Str_BundleFile:
 +                                                        if FetcherInstance.compress_the_file( Str_BundleFile, file ) != True:
 +                                                                log.err( "Couldn't archive %s to file %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
 +                                                                sys.exit( 1 )
 +                                                        else:
 +                                                                log.verbose( "%s added to archive %s.%s\n" % ( file, Str_BundleFile, LINE_OVERWRITE_SMALL ) )
 +                                                                os.unlink( os.path.join( Str_DownloadDir, file ) )
 +                                    
 +                                                log.success( "\r%s %s done.%s\n" % ( PackageName, PackageVersion, LINE_OVERWRITE_FULL ) )
 +                                else:
 +                                        errlist.append( PackageName )
 +                                        
 +                else:
 +                        
 +                        def DownloadPackages(url):
                                  if FetcherInstance.download_from_web(url, file, Str_DownloadDir) == True:
 -                                        log.success("\r%s done.%s\n" % (PackageName, LINE_OVERWRITE_FULL) )
 +                                        log.success("\r%s done.%s\n" % (url, LINE_OVERWRITE_FULL) )
                                          if Str_BundleFile:
                                                  if FetcherInstance.compress_the_file(Str_BundleFile, file) != True:
                                                          log.err("Couldn't archive %s to file %s.%s\n" % (file, Str_BundleFile, LINE_OVERWRITE_MID) )
@@@ -754,52 -763,58 +781,69 @@@
                                                  else:
                                                          log.verbose("%s added to archive %s.%s\n" % (file, Str_BundleFile, LINE_OVERWRITE_FULL) )
                                                          os.unlink(os.path.join(Str_DownloadDir, file) )
 +                                        return True
                                  else:
 -                                        errlist.append(url)
 +                                        return False
 +                                
 +                        #INFO: Handle the multiple Packages formats.
 +                        # See DTBS #583502
 +                        SupportedFormats = ["bz2", "gz", "lzma"]
 +                        
 +                        #INFO: We are a package update
 +                        PackageName = url
 +                        PackageFile = url.split("/")[-1]
 +                        PackageFormat = PackageFile.split(".")[-1]
 +                        if PackageFormat in SupportedFormats:
 +                                SupportedFormats.remove(PackageFormat) #Remove the already tried format
 +                        
 +                        log.msg("Downloading %s.%s\n" % (PackageName, LINE_OVERWRITE_MID) ) 
 +                        if DownloadPackages(url) is False:
 +                                errlist.append(url)
 +                                
 +                                # We could fail with the Packages format of what apt gave us. We can try the rest of the formats that apt or the archive could support
 +                                for Format in SupportedFormats:
 +                                        NewPackageFile = PackageFile.split(".")[0] + "." + Format
 +                                        NewUrl = url.strip(url.split("/")[-1]) + NewPackageFile
 +                                        log.msg("Retry download %s.%s\n" % (NewUrl, LINE_OVERWRITE_MID) ) 
 +                                        if DownloadPackages(NewUrl) is True:
 +                                                break
 +                                        else:
 +                                                errlist.append(NewUrl)
                          
          # Create two Queues for the requests and responses
          requestQueue = Queue.Queue()
          responseQueue = Queue.Queue()
 -        # Pool of NUMTHREADS Threads that run run().
 -        thread_pool = [
 -                       threading.Thread(
 -                                        target=run,
 -                                        args=(requestQueue, responseQueue)
 -                                        )
 -                       for i in range(Int_NumOfThreads)
 -                       ]
 -        
 -        # Start the threads.
 -        for t in thread_pool: t.start()
 +        
 +        
 +        ConnectThread = AptOfflineLib.MyThread(DataFetcher, requestQueue, responseQueue, Int_NumOfThreads)
 +        
 +        ConnectThread.startThreads()
          
+         #REAL_PROGRESS: to calculate the total download size, NOTE: initially this was under the loop that Queued the items
+         if guiBool:
+             for key in FetchData.keys():
+                 for item in FetchData.get(key):
+                     try:
+                         (url, file, download_size, checksum) = stripper(item)
+                         size = int(download_size)
+                         if size == 0:
+                             log.msg("MSG_START")
+                             temp = urllib2.urlopen(url)
+                             headers = temp.info()
+                             size = int(headers['Content-Length'])
+                         totalSize[0] += size
+                     except:
+                         ''' some int parsing problem '''
+             log.msg("MSG_END")
+                 
          # Queue up the requests.
          #for item in raw_data_list: requestQueue.put(item)
          for key in FetchData.keys():
                  for item in FetchData.get(key):
 -                        requestQueue.put( (key, item) )
 -        
 -        # Shut down the threads after all requests end.
 -        # (Put one None "sentinel" for each thread.)
 -        for t in thread_pool: requestQueue.put(None)
 -        
 -        # Don't end the program prematurely.
 -        # (Note that because Queue.get() is blocking by
 -        # defualt this isn't strictly necessary. But if
 -        # you were, say, handling responses in another
 -        # thread, you'd want something like this in your
 -        # main thread.)
 -        for t in thread_pool: t.join()
 +                        ConnectThread.populateQueue( (key, item) )
 +        ConnectThread.stopThreads()
 +        ConnectThread.stopQueue()
 +        
                  
          # Print the failed files
          if len(errlist) > 0:
@@@ -848,7 -863,7 +892,7 @@@ def installer( args )
          
          # install opts
          Str_InstallArg = args.install
 -        Bool_TestWindows = args.test_windows
 +        Bool_TestWindows = args.simulate
          Bool_SkipBugReports = args.skip_bug_reports
          Bool_Untrusted = args.allow_unauthenticated
          Str_InstallSrcPath = args.install_src_path
@@@ -961,13 -976,10 +1005,13 @@@
                  value => subject string
                  '''
                  log.msg( "\n\nFollowing are the list of bugs present.\n" )
 -                for each_bug in dictList.keys():
 +		sortedKeyList = dictList.keys()
 +		sortedKeyList.sort()
 +                for each_bug in sortedKeyList:
 +			pkg_name = each_bug.split( '.' )[-3].split('/')[-1]
                          bug_num = each_bug.split( '.' )[-2]
                          bug_subject = dictList[each_bug]
 -                        log.msg( "%s\t%s\n" % ( bug_num, bug_subject ) )
 +                        log.msg( "%s\t%s\t%s\n" % ( pkg_name, bug_num, bug_subject ) )
              
          def magic_check_and_uncompress( archive_file=None, filename=None):
                  retval = False
@@@ -1002,8 -1014,6 +1046,8 @@@
                          else:
                                  log.err( "Cannot write to target path %s\n" % ( apt_package_target_path ) )
                                  sys.exit( 1 )
 +                elif filename.endswith( apt_bug_file_format ):
 +                        pass
                  elif AptOfflineMagicLib.file( archive_file ) == "ASCII text":
                          filename = os.path.join(apt_update_target_path, filename)
                          if os.access( apt_update_target_path, os.W_OK ):
@@@ -1012,15 -1022,29 +1056,25 @@@
                          else:
                                  log.err( "Cannot write to target path %s\n" % ( apt_update_target_path ) )
                                  sys.exit( 1 )
 -                elif filename.endswith( apt_bug_file_format ):
 -                        retval = False # We intentionally put the bug report files as not printed.
                  else:
                          log.err( "I couldn't understand file type %s.\n" % ( filename ) )
                  
                  if retval:
+                         #CHANGE: track progress
+                         totalSize[0]+=1 
+                         if guiBool:
+                             log.msg("[%d/%d]" % (totalSize[0], totalSize[1]))
+                         #ENDCHANGE
                          log.verbose( "%s file synced to %s.\n" % ( filename, apt_update_target_path ) )
 -                else:
 -                        log.err("Failed to sync %s\n" % (filename) )
+ 
          
          if os.path.isfile(install_file_path):
                  #INFO: For now, we support zip bundles only
                  file = zipfile.ZipFile( install_file_path, "r" )
+                 #CHANGE: for progress tracking
+                 totalSize[1] = len(file.namelist())
+                 totalSize[0] = 0
+                 #ENDCHANGE
                  
                  SrcPkgDict = {}
                  for filename in file.namelist():
@@@ -1089,7 -1113,6 +1143,6 @@@
                                                          shutil.copy2(archive_file, os.path.join(Str_InstallSrcPath, filename) )
                                                          log.msg("Installing src package file %s to %s.\n" % (filename, Str_InstallSrcPath) )
                                                          continue
-                                                 
                                                  magic_check_and_uncompress( archive_file, filename )
                                                  data.file.close()
                                          sys.exit( 0 )
@@@ -1146,7 -1169,7 +1199,7 @@@
                                          shutil.copy2(archive_file, os.path.join(Str_InstallSrcPath, filename) )
                                          log.msg("Installing src package file %s to %s.\n" % (filename, Str_InstallSrcPath) )
                                          continue
-                                 
+                                     
                                  magic_check_and_uncompress( archive_file, filename )
                                  data.file.close()
                          #else:
@@@ -1173,30 -1196,6 +1226,30 @@@
                                  temp.close()
                  
                  bugs_number = {}
 +                
 +                def DirInstallPackages(InstallDirPath):
 +                        for eachfile in os.listdir( InstallDirPath ):
 +                                
 +                                filename = eachfile
 +                                FullFileName = os.path.abspath(os.path.join(InstallDirPath, eachfile) )
 +                        
 +                                if os.path.isdir(FullFileName):
 +                                        log.verbose("Skipping!! %s is a directory\n" % (FullFileName))
 +                                        continue
 +                                #INFO: Take care of Src Pkgs
 +                                found = False
 +                                for item in SrcPkgDict.keys():
 +                                        if filename in SrcPkgDict[item]:
 +                                                found = True
 +                                                break
 +                                if found is True:
 +                                        shutil.copy2(FullFileName, Str_InstallSrcPath)
 +                                        log.msg("Installing src package file %s to %s.\n" % (filename, Str_InstallSrcPath) )
 +                                        continue
 +                                
 +                                magic_check_and_uncompress( FullFileName, filename )
 +                        return True
 +                                
                  if Bool_SkipBugReports:
                          log.verbose("Skipping bug report check as requested")
                  else:
@@@ -1222,18 -1221,25 +1275,18 @@@
                                  if response == "?":
                                          display_options()
                                          response = get_response()
 +                                        
                                  elif response.startswith( 'y' ) or response.startswith( 'Y' ):
 -                                        for eachfile in os.listdir( install_file_path ):
 -                                                
 -                                                #INFO: Take care of Src Pkgs
 -                                                found = False
 -                                                for item in SrcPkgDict.keys():
 -                                                        if filename in SrcPkgDict[item]:
 -                                                                found = True
 -                                                                break
 -                                                if found is True:
 -                                                        shutil.copy2(filename, Str_InstallSrcPath)
 -                                                        log.msg("Installing src package file %s to %s.\n" % (filename, Str_InstallSrcPath) )
 -                                                        continue
 -                                                
 -                                                archive_type = None
 -                                                magic_check_and_uncompress( archive_file, filename )
 +                                        if DirInstallPackages(install_file_path) is True:
 +                                                sys.exit(0)
 +                                        else:
 +                                                log.err("Failed during install operation on %s.\n" % (install_file_path) )
 +                                                sys.exit(1)
 +                                        
                                  elif response.startswith( 'n' ) or response.startswith( 'N' ):
                                          log.err( "Exiting gracefully on user request.\n\n" )
                                          sys.exit( 0 )
 +                                        
                                  elif response.isdigit() is True:
                                          found = False
                                          for full_bug_file_name in bugs_number:
@@@ -1263,8 -1269,28 +1316,8 @@@
                                          sys.exit( 1 )
                  else:
                          log.verbose( "Great!!! No bugs found for all the packages that were downloaded.\n\n" )
 -                        #response = raw_input( "Continue with Installation. Y/N?" )
 -                        #response = response.rstrip( "\r" )
 -                        #if response.startswith( 'y' ) or response.startswith( 'Y' ):
 -                        for eachfile in os.listdir( install_file_path ):
 -                                filename = eachfile
 -                                eachfile = os.path.abspath(os.path.join(install_file_path, eachfile) )
 -                                
 -                                #INFO: Take care of Src Pkgs
 -                                found = False
 -                                for item in SrcPkgDict.keys():
 -                                        if filename in SrcPkgDict[item]:
 -                                                found = True
 -                                                break
 -                                if found is True:
 -                                        shutil.copy2(eachfile, Str_InstallSrcPath)
 -                                        log.msg("Installed src package file %s to %s.\n" % (filename, Str_InstallSrcPath) )
 -                                        continue
 -                                    
 -                                magic_check_and_uncompress( eachfile, filename )
 -                        #else:
 -                        #        log.msg( "Exiting gracefully on user request.\n" )
 -                        #        sys.exit( 0 )
 +                        DirInstallPackages(install_file_path)
 +                        
          if Bool_Untrusted:
                  log.err("Disabling apt gpg check can risk your machine to compromise.\n")
                  for x in os.listdir(apt_update_target_path):
@@@ -1301,8 -1327,8 +1354,8 @@@
                          
  
  def setter(args):
 -        #log.verbose(str(args) )
 -        Str_SetArg = args.set.__str__()
 +        log.verbose(str(args) )
 +        Str_SetArg = args.set
          List_SetInstallPackages = args.set_install_packages
          List_SetInstallSrcPackages = args.set_install_src_packages
          Str_SetInstallRelease = args.set_install_release
@@@ -1310,7 -1336,7 +1363,7 @@@
          Bool_SetUpgrade = args.set_upgrade
          Str_SetUpgradeType = args.upgrade_type
          Bool_SrcBuildDep = args.src_build_dep
 -        Bool_SetterErrors = False
 +        Bool_TestWindows = args.simulate
          
          if Bool_SetUpdate is False and Bool_SetUpgrade is False and List_SetInstallPackages is None \
          and List_SetInstallSrcPackages is None:
@@@ -1323,219 -1349,7 +1376,219 @@@
          if Default_Operation:
                  Bool_SetUpdate = True
                  Bool_SetUpgrade = True
 +                
 +        class AptManip:
 +                def __init__(self, OutputFile, Simulate=False, AptType="apt"):
 +                        
 +                        self.WriteTo = OutputFile
 +                        self.Simulate = Simulate
 +                        
 +                        if AptType == "apt":
 +                                self.apt = "apt-get"
 +                        elif AptType == "aptitude":
 +                                self.apt = "aptitude"
 +                        elif AptType == "python-apt":
 +                                #TODO:
 +                                pass
 +                        else:
 +                                self.apt = "apt-get"
 +                                
 +                def __Simulate(self):
 +                        if self.Simulate is True:
 +                                pass
 +                
 +                def __ExecSystemCmd(self, CommandString):
 +                        
 +                        if self.Simulate:
 +                                return True
 +                        else:
 +                                if os.system( CommandString ) != 0:
 +                                        return False
 +                                return True
 +                
 +                def Update(self):
 +                        if self.apt == "apt-get":
 +                                self.__AptGetUpdate()
 +                        elif self.apt == "aptitude":
 +                                pass
 +                        else:
 +                                log.err("Method not supported")
 +                                sys.exit(1)
 +                                
 +                                
 +                def Upgrade(self, UpgradeType="upgrade", ReleaseType=None):
 +                        if self.apt == "apt-get":
 +                                self.__AptGetUpgrade(UpgradeType, ReleaseType)
 +                        elif self.apt == "aptitude":
 +                                pass
 +                        else:
 +                                log.err("Method not supported")
 +                                sys.exit(1)
 +                
 +                def InstallPackages(self, PackageList, ReleaseType):
 +                        if self.apt == "apt-get":
 +                                self.__AptInstallPackage(PackageList, ReleaseType)
 +                        else:
 +                                log.err("Method not supported")
 +                                sys.exit(1)
 +                                
 +                def InstallSrcPackages(self, SrcPackageList, ReleaseType, BuildDependency):
 +                        if self.apt == "apt-get":
 +                                self.__AptInstallSrcPackages(SrcPackageList, ReleaseType, BuildDependency)
 +                        else:
 +                                log.err("Method not supported")
 +                                sys.exit(1)
 +                        
 +                        
 +                def __FixAptSigs(self):
 +                        for file in os.listdir(apt_update_target_path):
 +                                if file.endswith(".gpg.reverify"):
 +                                        sig_file = file.rstrip(".reverify")
 +                                        log.verbose("Recovering gpg signature %s.\n" % (file) )
 +                                        file = os.path.join(apt_update_target_path, file)
 +                                        os.rename(file, os.path.join(apt_update_final_path + sig_file) )
 +                                        
 +                                        
 +                def __AptGetUpdate(self):
 +                        log.msg("\nGenerating database of files that are needed for an update.\n")
 +                
 +                        #FIXME: Unicode Fix
 +                        # This is only a workaround.
 +                        # When using locales, we get translation files. But apt doesn't extract the URI properly.
 +                        # Once the extraction problem is root-caused, we can fix this easily.
 +                        os.environ['__apt_set_update'] = self.WriteTo
 +                        try:
 +                                old_environ = os.environ['LANG']
 +                        except KeyError:
 +                                old_environ = "C"
 +                        os.environ['LANG'] = "C"
 +                        log.verbose( "Set environment variable for LANG from %s to %s temporarily.\n" % ( old_environ, os.environ['LANG'] ) )
 +                        
 +                        if self.__ExecSystemCmd('/usr/bin/apt-get -qq --print-uris --simulate update >> $__apt_set_update') is False:
 +                                log.err( "FATAL: Something is wrong with the apt system.\n" )
 +                        log.verbose( "Set environment variable for LANG back to its original from %s to %s.\n" % ( os.environ['LANG'], old_environ ) )
 +                        os.environ['LANG'] = old_environ
 +                        
 +                        log.verbose("Calling __FixAptSigs to fix the apt sig problem")
 +                        self.__FixAptSigs()
 +                                
 +                def __AptitudeUpdate(self):
 +                        pass
 +                
 +                def __PythonAptUpdate(self):
 +                        pass
 +                
 +                def __AptGetUpgrade(self, UpgradeType="upgrade", ReleaseType=None):
 +                        self.ReleaseType = ReleaseType
 +                        
 +                        os.environ['__apt_set_upgrade'] = self.WriteTo
 +                        
 +                        if ReleaseType is not None:
 +                                os.environ['__apt_set_install_release'] = self.ReleaseType
 +                                if UpgradeType == "upgrade":
 +                                        log.msg( "\nGenerating database of files that are needed for an upgrade.\n" )
 +                                        
 +                                        if self.__ExecSystemCmd('/usr/bin/apt-get -qq --print-uris -t $__apt_set_install_release upgrade >> $__apt_set_upgrade') is False:
 +                                                log.err( "FATAL: Something is wrong with the apt system.\n" )
 +                                                        
 +                                elif Str_SetUpgradeType == "dist-upgrade":
 +                                        log.msg( "\nGenerating database of files that are needed for a dist-upgrade.\n" )
 +                                        
 +                                        if self.__ExecSystemCmd( '/usr/bin/apt-get -qq --print-uris -t $__apt_set_install_release dist-upgrade >> $__apt_set_upgrade' ) is False:
 +                                                log.err( "FATAL: Something is wrong with the apt system.\n" )
 +                                                
 +                                elif Str_SetUpgradeType == "dselect-upgrade":
 +                                        log.msg( "\nGenerating database of files that are needed for a dselect-upgrade.\n" )
 +                                        if self.__ExecSystemCmd( '/usr/bin/apt-get -qq --print-uris -t $__apt_set_install_release dselect-upgrade >> $__apt_set_upgrade' )  is False:
 +                                                log.err( "FATAL: Something is wrong with the apt system.\n" )
 +                                else:
 +                                        log.err( "Invalid upgrade argument type selected\nPlease use one of, upgrade/dist-upgrade/dselect-upgrade\n" )
 +                                        
 +                        else:
 +                                
 +                                if UpgradeType == "upgrade":
 +                                        log.msg( "\nGenerating database of files that are needed for an upgrade.\n" )
 +                                        
 +                                        if self.__ExecSystemCmd('/usr/bin/apt-get -qq --print-uris upgrade >> $__apt_set_upgrade') is False:
 +                                                log.err( "FATAL: Something is wrong with the apt system.\n" )
 +                                                        
 +                                elif Str_SetUpgradeType == "dist-upgrade":
 +                                        log.msg( "\nGenerating database of files that are needed for a dist-upgrade.\n" )
 +                                        
 +                                        if self.__ExecSystemCmd( '/usr/bin/apt-get -qq --print-uris dist-upgrade >> $__apt_set_upgrade' ) is False:
 +                                                log.err( "FATAL: Something is wrong with the apt system.\n" )
 +                                                
 +                                elif Str_SetUpgradeType == "dselect-upgrade":
 +                                        log.msg( "\nGenerating database of files that are needed for a dselect-upgrade.\n" )
 +                                        if self.__ExecSystemCmd( '/usr/bin/apt-get -qq --print-uris dselect-upgrade >> $__apt_set_upgrade' )  is False:
 +                                                log.err( "FATAL: Something is wrong with the apt system.\n" )
 +                                else:
 +                                        log.err( "Invalid upgrade argument type selected\nPlease use one of, upgrade/dist-upgrade/dselect-upgrade\n" )
 +                                
 +                def __AptInstallPackage(self, PackageList=None, ReleaseType=None):
 +                        
 +                        self.package_list = ''
 +                        self.ReleaseType = ReleaseType
 +                        
 +                        for pkg in PackageList:
 +                                self.package_list += pkg + ', '
 +                        log.msg( "\nGenerating database of package %s and its dependencies.\n" % (self.package_list) )
 +                        
 +                        os.environ['__apt_set_install'] = self.WriteTo
 +                        os.environ['__apt_set_install_packages'] = ''                   # Build an empty variable
          
 +                        #INFO: This is improper way of getting the args, the name of the packages.
 +                        # But since optparse doesn't have the implementation in place at the moment, we're using it.
 +                        # Once fixed, this will be changed.
 +                        # For details look at the parser.add_option line above.
 +                        for x in PackageList:
 +                                os.environ['__apt_set_install_packages'] += x + ' '
 +                        
 +                        if self.ReleaseType is not None:
 +                                os.environ['__apt_set_install_release'] = self.ReleaseType
 +                                if self.__ExecSystemCmd( '/usr/bin/apt-get -qq --print-uris -t $__apt_set_install_release install $__apt_set_install_packages >> $__apt_set_install' ) is False:
 +                                        log.err( "FATAL: Something is wrong with the apt system.\n" )
 +                        else:
 +                                #FIXME: Find a more Pythonic implementation
 +                                if self.__ExecSystemCmd( '/usr/bin/apt-get -qq --print-uris install $__apt_set_install_packages >> $__apt_set_install' ) is False:
 +                                        log.err( "FATAL: Something is wrong with the apt system.\n" )
 +                                        
 +                def __AptInstallSrcPackages(self, SrcPackageList=None, ReleaseType=None, BuildDependency=False):
 +                        
 +                        self.package_list = ''
 +                        self.ReleaseType = ReleaseType
 +                        
 +                        for pkg in SrcPackageList:
 +                                self.package_list += pkg + ', '
 +                        log.msg( "\nGenerating database of source packages %s.\n" % (self.package_list) )
 +                        
 +                        os.environ['__apt_set_install'] = self.WriteTo
 +                        os.environ['__apt_set_install_src_packages'] = ''               # Build an empty variable
 +                        
 +                        for x in SrcPackageList:
 +                                os.environ['__apt_set_install_src_packages'] += x + ' '
 +                                
 +                        if self.ReleaseType is not None:
 +                                os.environ['__apt_set_install_release'] = self.ReleaseType
 +                                if self.__ExecSystemCmd( '/usr/bin/apt-get -qq --print-uris -t $__apt_set_install_release source $__apt_set_install_src_packages >> $__apt_set_install' ) is False:
 +                                        log.err( "FATAL: Something is wrong with the apt system.\n" )
 +                        else:
 +                                #FIXME: Find a more Pythonic implementation
 +                                if self.__ExecSystemCmd( '/usr/bin/apt-get -qq --print-uris source $__apt_set_install_src_packages >> $__apt_set_install' )  is False:
 +                                        log.err( "FATAL: Something is wrong with the apt system.\n" )
 +                        
 +                        if BuildDependency:
 +                                log.msg("Generating Build-Dependency for source packages %s.\n" % (self.package_list) )
 +                                if self.ReleaseType is not None:
 +                                        os.environ['__apt_set_install_release'] = self.ReleaseType
 +                                        if self.__ExecSystemCmd( '/usr/bin/apt-get -qq --print-uris -t $__apt_set_install_release build-dep $__apt_set_install_src_packages >> $__apt_set_install' ) is False:
 +                                                log.err( "FATAL: Something is wrong with the apt system.\n" )
 +                                else:
 +                                        if self.__ExecSystemCmd( '/usr/bin/apt-get -qq --print-uris build-dep $__apt_set_install_src_packages >> $__apt_set_install' ) is False:
 +                                                log.err( "FATAL: Something is wrong with the apt system.\n" )
 +                                
 +                
 +                                
          #FIXME: We'll use python-apt library to make it cleaner.
          # For now, we need to set markers using shell variables.
          if os.path.isfile(Str_SetArg):
@@@ -1544,24 -1358,36 +1597,24 @@@
                  except OSError:
                          log.err("Cannot remove file %s.\n" % (Str_SetArg) )
          
 +        
 +        #Instantiate Apt based on what we have. For now, fall to apt only
 +        AptInst = AptManip(Str_SetArg, Simulate=Bool_TestWindows, AptType="apt")
 +        
          if Bool_SetUpdate:
                  if platform.system() in supported_platforms:
 -                        if os.geteuid() != 0:
 +                        if not Bool_TestWindows and os.geteuid() != 0:
                                  log.err("This option requires super-user privileges. Execute as root or use sudo/su\n")
                                  sys.exit(1)
                          else:
 -                                log.msg("\nGenerating database of files that are needed for an update.\n")
 -                        
 -                                #FIXME: Unicode Fix
 -                                # This is only a workaround.
 -                                # When using locales, we get translation files. But apt doesn't extract the URI properly.
 -                                # Once the extraction problem is root-caused, we can fix this easily.
 -                                os.environ['__apt_set_update'] = Str_SetArg
 -                                try:
 -                                        old_environ = os.environ['LANG']
 -                                except KeyError:
 -                                        old_environ = "C"
 -                                os.environ['LANG'] = "C"
 -                                log.verbose( "Set environment variable for LANG from %s to %s temporarily.\n" % ( old_environ, os.environ['LANG'] ) )
 -                                if os.system( '/usr/bin/apt-get -qq --print-uris update >> $__apt_set_update' ) != 0:
 -                                        log.err( "FATAL: Something is wrong with the apt system.\n" )
 -                                        Bool_SetterErrors = True
 -                                log.verbose( "Set environment variable for LANG back to its original from %s to %s.\n" % ( os.environ['LANG'], old_environ ) )
 -                                os.environ['LANG'] = old_environ
 +                                AptInst.Update()
                  else:
                          log.err( "This argument is supported only on Unix like systems with apt installed\n" )
                          sys.exit( 1 )
 +                        
          if Bool_SetUpgrade:
                  if platform.system() in supported_platforms:
 -                        if os.geteuid() != 0:
 +                        if not Bool_TestWindows and os.geteuid() != 0:
                                  log.err( "This option requires super-user privileges. Execute as root or use sudo/su" )
                                  sys.exit(1)
                          #TODO: Use a more Pythonic way for it
@@@ -1597,11 -1423,23 +1650,11 @@@
                                                                  install_file.write( uri + ' ' + file + ' ' + size + ' ' + checksum + "\n" )
                                                                  dup_records.append( checksum.__str__() )
                                  else:
 -                                        log.msg( "\nGenerating database of files that are needed for an upgrade.\n" )
 -                                        os.environ['__apt_set_upgrade'] = Str_SetArg
 -                                        if os.system( '/usr/bin/apt-get -qq --print-uris upgrade >> $__apt_set_upgrade' ) != 0:
 -                                                log.err( "FATAL: Something is wrong with the apt system.\n" )
 -                                                Bool_SetterErrors = True
 +                                        AptInst.Upgrade("upgrade", ReleaseType=Str_SetInstallRelease)
                          elif Str_SetUpgradeType == "dist-upgrade":
 -                                log.msg( "\nGenerating database of files that are needed for a dist-upgrade.\n" )
 -                                os.environ['__apt_set_upgrade'] = Str_SetArg
 -                                if os.system( '/usr/bin/apt-get -qq --print-uris dist-upgrade >> $__apt_set_upgrade' ) != 0:
 -                                        log.err( "FATAL: Something is wrong with the apt system.\n" )
 -                                        Bool_SetterErrors = True
 +                                AptInst.Upgrade("dist-upgrade")
                          elif Str_SetUpgradeType == "dselect-upgrade":
 -                                log.msg( "\nGenerating database of files that are needed for a dselect-upgrade.\n" )
 -                                os.environ['__apt_set_upgrade'] = Str_SetArg
 -                                if os.system( '/usr/bin/apt-get -qq --print-uris dselect-upgrade >> $__apt_set_upgrade' ) != 0:
 -                                        log.err( "FATAL: Something is wrong with the apt system.\n" )
 -                                        Bool_SetterErrors = True
 +                                AptInst.Upgrade("dselect-upgrade")
                          else:
                                  log.err( "Invalid upgrade argument type selected\nPlease use one of, upgrade/dist-upgrade/dselect-upgrade\n" )
                  else:
@@@ -1610,21 -1448,82 +1663,21 @@@
                  
          if List_SetInstallPackages != None and List_SetInstallPackages != []:
                  if platform.system() in supported_platforms:
 -                        if os.geteuid() != 0:
 +                        if not Bool_TestWindows and os.geteuid() != 0:
                                  log.err( "This option requires super-user privileges. Execute as root or use sudo/su\n" )
                                  sys.exit(1)
 -                        package_list = ''
 -                        for pkg in List_SetInstallPackages:
 -                                package_list += pkg + ', '
 -                        log.msg( "\nGenerating database of package %s and its dependencies.\n" % (package_list) )
 -                        os.environ['__apt_set_install'] = Str_SetArg
 -                        os.environ['__apt_set_install_packages'] = ''
 -        
 -                        #INFO: This is improper way of getting the args, the name of the packages.
 -                        # But since optparse doesn't have the implementation in place at the moment, we're using it.
 -                        # Once fixed, this will be changed.
 -                        # For details look at the parser.add_option line above.
 -                        for x in List_SetInstallPackages:
 -                                os.environ['__apt_set_install_packages'] += x + ' '
 -                        
 -                        if Str_SetInstallRelease:
 -                                os.environ['__apt_set_install_release'] = Str_SetArg
 -                                if os.system( '/usr/bin/apt-get -qq --print-uris -t $__apt_set_install_release install $__apt_set_install_packages >> $__apt_set_install' ) != 0:
 -                                        log.err( "FATAL: Something is wrong with the apt system.\n" )
 -                                        Bool_SetterErrors = True
 -                        else:
 -                                #FIXME: Find a more Pythonic implementation
 -                                if os.system( '/usr/bin/apt-get -qq --print-uris install $__apt_set_install_packages >> $__apt_set_install' ) != 0:
 -                                        log.err( "FATAL: Something is wrong with the apt system.\n" )
 -                                        Bool_SetterErrors = True
 +                                
 +                        AptInst.InstallPackages(List_SetInstallPackages, Str_SetInstallRelease)
                  else:
                          log.err( "This argument is supported only on Unix like systems with apt installed\n" )
                          sys.exit( 1 )
          
          if List_SetInstallSrcPackages != None and List_SetInstallSrcPackages != []:
                  if platform.system() in supported_platforms:
 -                        package_list = ''
 -                        for pkg in List_SetInstallSrcPackages:
 -                                package_list += pkg + ', '
 -                        log.msg( "\nGenerating database of source packages %s.\n" % (package_list) )
 -                        os.environ['__apt_set_install'] = Str_SetArg
 -                        os.environ['__apt_set_install_src_packages'] = ''
 -                        
 -                        for x in List_SetInstallSrcPackages:
 -                                os.environ['__apt_set_install_src_packages'] += x + ' '
 -                                
 -                        if Str_SetInstallRelease:
 -                                os.environ['__apt_set_install_release'] = Str_SetArg
 -                                if os.system( '/usr/bin/apt-get -qq --print-uris -t $__apt_set_install_release source $__apt_set_install_src_packages >> $__apt_set_install' ) != 0:
 -                                        log.err( "FATAL: Something is wrong with the apt system.\n" )
 -                                        Bool_SetterErrors = True
 -                        else:
 -                                #FIXME: Find a more Pythonic implementation
 -                                if os.system( '/usr/bin/apt-get -qq --print-uris source $__apt_set_install_src_packages >> $__apt_set_install' ) != 0:
 -                                        log.err( "FATAL: Something is wrong with the apt system.\n" )
 -                                        Bool_SetterErrors = True
 -                        
 -                        if Bool_SrcBuildDep:
 -                                log.msg("Generating Build-Dependency for source packages %s.\n" % (package_list) )
 -                                if Str_SetInstallRelease:
 -                                        os.environ['__apt_set_install_release'] = Str_SetArg
 -                                        if os.system( '/usr/bin/apt-get -qq --print-uris -t $__apt_set_install_release build-dep $__apt_set_install_src_packages >> $__apt_set_install' ) != 0:
 -                                                log.err( "FATAL: Something is wrong with the apt system.\n" )
 -                                                Bool_SetterErrors = True
 -                                else:
 -                                        #FIXME: Find a more Pythonic implementation
 -                                        if os.system( '/usr/bin/apt-get -qq --print-uris build-dep $__apt_set_install_src_packages >> $__apt_set_install' ) != 0:
 -                                                log.err( "FATAL: Something is wrong with the apt system.\n" )
 -                                
 +                        AptInst.InstallSrcPackages(List_SetInstallSrcPackages, Str_SetInstallRelease, Bool_SrcBuildDep)
                  else:
                          log.err( "This argument is supported only on Unix like systems with apt installed\n" )
                          sys.exit( 1 )
 -                        
 -        if (not Bool_SetterErrors):
 -            log.msg("Completed\n")
 -            return True
 -        else:
 -            log.msg("FATAL: Incomplete\n")
 -            return False
          
  def gui(args):
          Bool_GUI = args.gui
@@@ -1661,18 -1560,12 +1714,18 @@@ def main()
          # Global options
          global_options = argparse.ArgumentParser(add_help=False)
          global_options.add_argument("--verbose", dest="verbose", help="Enable verbose messages", action="store_true" )
 -        global_options.add_argument("--test-windows", dest="test_windows", help="This switch is used while doing testing on windows.",
 +        global_options.add_argument("--simulate", dest="simulate", help="Just simulate. Very helpful when debugging",
                              action="store_true" )
          
 -        parser = argparse.ArgumentParser( prog=app_name, version=app_name + " - " + version,
 -                                          description="Offline APT Package Manager",
 +	if argparse.__version__ >= 1.1:
 +		parser = argparse.ArgumentParser( prog=app_name, description="Offline APT Package Manager" + ' - ' + version,
                                            epilog=copyright + " - " + terminal_license, parents=[global_options])
 +		parser.add_argument("-v", "--version", action='version', version=version)
 +	else:
 +		# Remain backward compatible with older argparse versions 
 +		parser = argparse.ArgumentParser( prog=app_name, version=app_name + " - " + version,
 +				description="Offline APT Package Manager", epilog=copyright + " - " + terminal_license,
 +				parents=[global_options])
          
          # We need subparsers for set/get/install
          subparsers = parser.add_subparsers()
@@@ -1774,11 -1667,7 +1827,11 @@@
                  # Sanitize the options/arguments
                  #
          	# Global opts
 -        	
 +        	Bool_Verbose = args.verbose
 +        	Bool_TestWindows = args.simulate
 +                
 +        	global log
 +        	log = AptOfflineLib.Log( Bool_Verbose, lock=True )
          	log.verbose(str(args) + "\n")
          
          	args.func(args)

-- 
Offline APT Package Manager



More information about the apt-offline-devel mailing list