0
  #   ˆl–ß=¿J *j"TíÀ3q¦”Å£Ã„dº×ÁÀ ?÷     #!/usr/bin/python -tt
# 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 2004 Duke University

import rpmUtils
import rpmUtils.miscutils
import rpmUtils.arch

def _vertup_cmp(tup1, tup2):
    return rpmUtils.miscutils.compareEVR(tup1, tup2)
class Updates:
    """
    This class computes and keeps track of updates and obsoletes.
    initialize, add installed packages, add available packages (both as
    unique lists of name, arch, ver, rel, epoch tuples), add an optional dict
    of obsoleting packages with obsoletes and what they obsolete ie::
        foo, i386, 0, 1.1, 1: bar >= 1.1.
    """

    def __init__(self, instlist, availlist):

        self.installed = instlist # list of installed pkgs (n, a, e, v, r)
        self.available = availlist # list of available pkgs (n, a, e, v, r)

        self.rawobsoletes = {} # dict of obsoleting package->[what it obsoletes]
        self._obsoletes_by_name = None
        self.obsoleted_dict = {}  # obsoleted pkgtup -> [ obsoleting pkgtups ]
        self.obsoleting_dict = {} # obsoleting pkgtup -> [ obsoleted pkgtups ]

        self.exactarch = 1 # don't change archs by default
        self.exactarchlist = set(['kernel', 'kernel-smp', 'glibc',
                                  'kernel-hugemem',
                                  'kernel-enterprise', 'kernel-bigmem',
                                  'kernel-BOOT'])
                              
        self.myarch = rpmUtils.arch.canonArch # set this if you want to
                                              # test on some other arch
                                              # otherwise leave it alone
        self._is_multilib = rpmUtils.arch.isMultiLibArch(self.myarch)
        
        self._archlist = rpmUtils.arch.getArchList(self.myarch)

        self._multilib_compat_arches = rpmUtils.arch.getMultiArchInfo(self.myarch)

        # make some dicts from installed and available
        self.installdict = self.makeNADict(self.installed, 1)
        self.availdict = self.makeNADict(self.available, 0, # Done in doUpdate
                                         filter=self.installdict)

        # holder for our updates dict
        self.updatesdict = {}
        self.updating_dict = {}
        #debug, ignore me
        self.debug = 0
        self.obsoletes = {}

    def _delFromDict(self, dict_, keys, value):
        for key in keys:
            if key not in dict_:
                continue
            dict_[key] = filter(value.__ne__, dict_[key])
            if not dict_[key]:
                del dict_[key]

    def _delFromNADict(self, dict_, pkgtup):
        (n, a, e, v, r) = pkgtup
        for aa in (a, None):
            if (n, aa) in dict_:
                dict_[(n, aa)] = filter((e,v,r).__ne__, dict_[(n, aa)])
                if not dict_[(n, aa)]:
                    del dict_[(n, aa)]

    def delPackage(self, pkgtup):
        """remove available pkgtup that is no longer available"""
        if pkgtup not in self.available:
            return
        self.available.remove(pkgtup)
        self._delFromNADict(self.availdict, pkgtup)

        self._delFromDict(self.updating_dict, self.updatesdict.get(pkgtup, []), pkgtup)
        self._delFromDict(self.updatesdict, self.updating_dict.get(pkgtup, []), pkgtup)

        if pkgtup in self.rawobsoletes:
            if self._obsoletes_by_name:
                for name,