diff options
author | Jonathan Dieter <jdieter@gmail.com> | 2007-03-29 19:43:26 +0300 |
---|---|---|
committer | Jonathan Dieter <jdieter@gmail.com> | 2007-03-29 19:43:26 +0300 |
commit | 5ea857b0e948b687785b8e55e08866c6171fb715 (patch) | |
tree | b819860880b50d41f31ba627d0261dd64b9667b1 /yum-presto/shared/prestoTransaction.py | |
parent | b1147b441a7f4873f39c5ce337d516b2cd1483eb (diff) | |
download | presto-5ea857b0e948b687785b8e55e08866c6171fb715.tar.gz presto-5ea857b0e948b687785b8e55e08866c6171fb715.tar.xz presto-5ea857b0e948b687785b8e55e08866c6171fb715.zip |
Split server and client
Signed-off-by: Jonathan Dieter <jdieter@gmail.com>
Diffstat (limited to 'yum-presto/shared/prestoTransaction.py')
-rw-r--r-- | yum-presto/shared/prestoTransaction.py | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/yum-presto/shared/prestoTransaction.py b/yum-presto/shared/prestoTransaction.py new file mode 100644 index 0000000..3d387a4 --- /dev/null +++ b/yum-presto/shared/prestoTransaction.py @@ -0,0 +1,97 @@ +# 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() + + is_local = False + + # Set p_repo to be packages delta repository or set to False if + # there is no delta repository + try: + p_repo = newpkg.po.repo.p_repo + drpm_enabled = p_repo.enabled + + po = newpkg.po + if hasattr(po, 'pkgtype') and po.pkgtype == 'local': + is_local = True + else: + local = po.localPkg() + if os.path.exists(local): + cursize = os.stat(local)[6] + totsize = long(po.size) + if not po.verifyLocalPkg(): + if cursize >= totsize: # otherwise keep it around for regetting + os.unlink(local) + else: + conduit.info(5, "using local copy of %s" % po) + is_local = True + + except: + conduit.info(5, "No Presto repository information for %s.%s %i:%s-%s" % (newpkg.name, newpkg.arch, int(newpkg.epoch), newpkg.version, newpkg.release)) + drpm_enabled = False + is_local = False + + chosen_drpm = None + + # 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) + + if installed == []: + is_installed = False + else: + is_installed = True + + + if is_installed and drpm_enabled and not is_local: + 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] + chosen_drpm['baseurl'] = p_repo.baseurl[0] + except: + conduit.info(5, "Verification of %s failed" % seq) + + return (chosen_drpm, installed, is_local, drpm_enabled) |