summaryrefslogtreecommitdiffstats
path: root/share-presto/prestoTransaction.py
diff options
context:
space:
mode:
Diffstat (limited to 'share-presto/prestoTransaction.py')
-rw-r--r--share-presto/prestoTransaction.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/share-presto/prestoTransaction.py b/share-presto/prestoTransaction.py
new file mode 100644
index 0000000..5b7e3d4
--- /dev/null
+++ b/share-presto/prestoTransaction.py
@@ -0,0 +1,65 @@
+# author: Jonathan Dieter <jdieter@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Copyright 2005 Duke University
+
+import os
+import deltarpm
+
+def find_available_drpms(conduit, newpkg):
+ """Find any applicable drpms for newpkg
+ newpkg is a TransactionMember"""
+
+ rpmdb = conduit.getRpmDB()
+
+ # Saves us some typing
+ p_repo = newpkg.po.repo.p_repo
+ chosen_drpm = None
+
+ if p_repo.enabled:
+ # Don't try to download deltarpm if full rpm already exists
+ if not os.path.exists(newpkg.po.localpath):
+ # First part of key when matching drpms
+ key1 = "%s*%s*%i*%s*%s" % (newpkg.name, newpkg.arch, int(newpkg.epoch), newpkg.version, newpkg.release)
+
+ # Find any installed packages that match the ones we want to download
+ installed = rpmdb.searchNevra(newpkg.name, None, None, None, newpkg.arch)
+
+ for oldpkg in installed:
+ # Generate second part of key for matching drpms, then full key
+ key2 = "%s*%s*%i*%s*%s" % (oldpkg.name, oldpkg.arch, int(oldpkg.epoch), oldpkg.version, oldpkg.release)
+ key = "%s!!%s" % (key1, key2)
+
+ # Check whether we have a matching drpm
+ if p_repo.deltalist.has_key(key):
+ # Check whether or not we already have a matching drpm, then choose smallest of the two if we do
+ if chosen_drpm == None or p_repo.deltalist[key]['size'] < chosen_drpm['size']:
+
+ # Get sequence code for drpm
+ sequence = p_repo.deltalist[key]['sequence']
+ if int(oldpkg.epoch) == 0:
+ seq = "%s-%s-%s-%s" % (oldpkg.name, oldpkg.version, oldpkg.release, sequence)
+ else:
+ seq = "%s-%i:%s-%s-%s" % (oldpkg.name, int(oldpkg.epoch), oldpkg.version, oldpkg.release, sequence)
+ drpm = deltarpm.DeltaRpmWrapper(conduit)
+
+ # Attempt to apply sequence code for drpm. If this fails, drpm will not apply cleanly, so
+ # don't even try to download it.
+ try:
+ drpm.verifySequence(seq)
+ chosen_drpm = p_repo.deltalist[key]
+ except:
+ conduit.info(5, "Verification of %s failed" % seq)
+ return chosen_drpm