diff options
Diffstat (limited to 'yum-presto/presto.py')
-rw-r--r-- | yum-presto/presto.py | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/yum-presto/presto.py b/yum-presto/presto.py index ebdef4d..cf37458 100644 --- a/yum-presto/presto.py +++ b/yum-presto/presto.py @@ -37,6 +37,8 @@ import yum.Errors import yum.misc from urlgrabber.grabber import URLGrabError +complete_download_size = 0 +total_download_size = 0 requires_api_version = '2.1' plugin_type = (TYPE_CORE,) @@ -58,6 +60,7 @@ def applyDelta(deltarpmfile, newrpmfile, arch): def reconstruct(conduit, rpmlocal, rpmarch, deltalocal): retlist = "" + global actual_download_size if not applyDelta(deltalocal, rpmlocal, rpmarch): retlist += "Error rebuilding rpm from %s! Will download full package.\n" % os.path.basename(deltalocal) @@ -66,6 +69,12 @@ def reconstruct(conduit, rpmlocal, rpmarch, deltalocal): except: pass else: + # Calculate new download size + rpm_size = os.stat(rpmlocal)[6] + drpm_size = os.stat(deltalocal)[6] + + actual_download_size = actual_download_size - rpm_size + drpm_size + # Check to see whether or not we should keep the drpms # FIXME: Is there any way to see whether or not a Boolean option was not set? if conduit.confBool('main', 'neverkeepdeltas'): @@ -121,6 +130,8 @@ class ReconstructionThread(threading.Thread): def getDelta(po, presto, rpmdb): """Does the package have a reasonable delta for us to use?""" + global complete_download_size + global actual_download_size # local packages don't make sense to use a delta for... if hasattr(po, 'pkgtype') and po.pkgtype == 'local': @@ -148,6 +159,8 @@ def getDelta(po, presto, rpmdb): cursize = os.stat(local)[6] totsize = long(po.size) if po.verifyLocalPkg(): # we've got it. + actual_download_size -= cursize + complete_download_size -= cursize return None if cursize < totsize: # we have part of the file; do a reget return None @@ -351,6 +364,45 @@ class PrestoParser(object): def getDeltas(self): return self.deltainfo +def format_number(number, SI=False, space=''): + """Turn numbers into human-readable metric-like numbers""" + symbols = ['', # (none) + 'K', # kilo + 'M', # mega + 'G', # giga + 'T', # tera + 'P', # peta + 'E', # exa + 'Z', # zetta + 'Y'] # yotta + + if SI: step = 1000.0 + else: step = 1024.0 + + thresh = 999 + depth = 0 + + # we want numbers between + while number > thresh: + depth = depth + 1 + number = number / step + + # just in case someone needs more than 1000 yottabytes! + diff = depth - len(symbols) + 1 + if diff > 0: + depth = depth - diff + number = number * thresh**depth + + if type(number) == type(1) or type(number) == type(1L): + format = '%i%s%s' + elif number < 9.95: + # must use 9.95 for proper sizing. For example, 9.99 will be + # rounded to 10.0 with the .1f format string (which is too long) + format = '%.1f%s%s' + else: + format = '%.0f%s%s' + + return(format % (number, space, symbols[depth])) # Configuration stuff def config_hook(conduit): @@ -376,12 +428,20 @@ def postreposetup_hook(conduit): else: conduit.info(5, '--disablepresto specified - Presto disabled') - def predownload_hook(conduit): + global complete_download_size + global actual_download_size + opts, commands = conduit.getCmdLine() if (opts and opts.disablepresto) or len(conduit.getDownloadPackages()) == 0: return + # Get download size, to calculate accurate download savings + pkglist = conduit.getDownloadPackages() + for po in pkglist: + complete_download_size += int(po.size) + actual_download_size = complete_download_size + conduit.info(2, "Downloading DeltaRPMs:") # Download deltarpms @@ -397,4 +457,14 @@ def predownload_hook(conduit): errstring += ' %s: %s\n' % (key, error) raise PluginYumExit(errstring) -# FIXME: would be good to give an idea to people of what they saved +def posttrans_hook(conduit): + global complete_download_size + global actual_download_size + + if complete_download_size > 0: + drpm_string = format_number(actual_download_size) + rpm_string = format_number(complete_download_size) + + conduit.info(2, "Size of all updates downloaded from Presto-enabled repositories: %s" % drpm_string) + conduit.info(2, "Size of updates that would have been downloaded if Presto wasn't enabled: %s" % rpm_string) + conduit.info(2, "This is a savings of %i percent" % (100 - ((actual_download_size * 100) / complete_download_size))) |