From eee8adadcd4fc3c0d7deea4a8ada73b4278c61f4 Mon Sep 17 00:00:00 2001 From: Ahmed Kamal Date: Wed, 14 Feb 2007 00:23:16 +0200 Subject: Implement drpmIsWorthKeeping, and only generate a drpm if it's not already there. --- server.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/server.py b/server.py index c7bfe4c..c3651fc 100755 --- a/server.py +++ b/server.py @@ -26,6 +26,8 @@ DEBUG = False #### Utils.setdebug(DEBUG) SUFFIX='drpm' +DRPMWORTHKEEPINGTHRESH=0.5 +DEBUG=0 def genDeltaRPM(ts, newrpm, oldrpm): (f1,n1,e1,v1,r1) = newrpm @@ -39,9 +41,31 @@ def genDeltaRPM(ts, newrpm, oldrpm): deltaCommand = 'makedeltarpm %s %s %s' % (f2, f1, deltaRPMName) if DEBUG: print "DEBUG " + deltaCommand - (code, out) = commands.getstatusoutput(deltaCommand) - if code: - raise Exception("genDeltaRPM: exitcode was %s - Reported Error: %s" % (code, out)) + # If the drpm doesn't exists, make it, else skip it + if not os.path.exists(deltaRPMName): + (code, out) = commands.getstatusoutput(deltaCommand) + if code: + #raise Exception("genDeltaRPM: exitcode was %s - Reported Error: %s" % (code, out)) + print "Error genDeltaRPM for %s: exitcode was %s - Reported Error: %s" % (n1, code, out) + # Check whether or not we should keep the drpm + if not drpmIsWorthKeeping(deltaRPMName, f1): + if DEBUG: + print 'deleting %s' % (deltaRPMName) + try: + os.unlink(deltaRPMName) + except Exception, e: + print "Error deleting deltarpm %s" % (deltaRPMName), str(e) + else: + if DEBUG: + print "DEBUG skipping %s" % (deltaRPMName) + +def drpmIsWorthKeeping(deltaRPMName, newrpm): + newsize = os.path.getsize(newrpm) + drpmsize = os.path.getsize(deltaRPMName) + # Delete the drpm if it's too fat + if drpmsize > DRPMWORTHKEEPINGTHRESH * newsize: + return 0 + return 1 def pruneRepo(keep,whitelist,srcdir): ts = rpmUtils.transaction.initReadOnlyTransaction() -- cgit