fff
  #   !li~?Jrţt? (    !#! /usr/bin/python -tt

#!/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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import yum

import os

from optparse import OptionParser
from optparse import SUPPRESS_HELP

version = "1.0.0"


def _get_npkgs(self, args):
    pkgs = []
    for arg in args:
        if (arg.endswith('.rpm') and (yum.misc.re_remote_url(arg) or
                                      os.path.exists(arg))):
            thispkg = yum.packages.YumUrlPackage(self, self.ts, arg)
            pkgs.append(thispkg)
        elif self.conf.showdupesfromrepos:
            pkgs.extend(self.pkgSack.returnPackages(patterns=[arg]))
        else:                
            try:
                pkgs.extend(self.pkgSack.returnNewestByName(patterns=[arg]))
            except yum.Errors.PackageSackError:
                pass
    return pkgs

def _get_opkgs(self, npkgs, old_packages):
    if old_packages:
        return _get_npkgs(self, old_packages)
    pkg_names = set((pkg.name for pkg in npkgs))
    return self.rpmdb.searchNames(pkg_names)

def _get_oreqs(pkg, reqs):
    oreqs = {}
    for req in reqs:
        (r,f,v) = req
        if r.startswith('rpmlib('):
            continue

        if r not in oreqs:
            oreqs[r] = set([req])
        else:
            oreqs[r].add(req)
    return oreqs

def _get_reqs(pkg, reqs, oreqs, self_prov_check=True):
    nreqs = set()
    creqs = set()

    for req in reqs:
        (r,f,v) = req
        if r.startswith('rpmlib('):
            continue

        if r in oreqs and req in oreqs[r]:
            continue

        if (r in pkg.provides_names or
            (r[0] == '/' and r in (pkg.filelist + pkg.dirlist +
                                   pkg.ghostlist))):
            if not f or pkg.checkPrco('provides', req):
                continue

        if r in oreqs:
            creqs.add(req)
        else:
            nreqs.add(req)

    return nreqs, creqs


def _print_reqs(yb, pkg, reqs, used_repos):
    out_reqs = {}
    for req in reqs:
        (r,f,v) = req
        seen = {}
        out_reqs[req] = []
        for pkg in sorted(yb.rpmdb.searchProvides(req)):
            key = (pkg.name, pkg.arch)
            if key in seen and not yb.conf.showdupesfromrepos:
                continue
            seen[key] = pkg
            out_reqs[req].append(pkg)
            used_repos.append(pkg.ui_from_repo)
        for pkg in sorted(yb.pkgSack.searchProvides(req)):
            key = (pkg.name, pkg.arch)
            if key in seen and not yb.conf.showdupesfromrepos:
                continue
            seen[key] = pkg
            out_reqs[req].append(pkg)
            used_repos.append(pkg.ui_from_repo)
    done = set()
    for req in sorted(out_reqs):
        if req in done:
            continue
        done.add(req)
        print " ", yum.misc.prco_tuple_to_string(req)
        for oreq in sorted(out_reqs):
            if oreq in done:
                continue
            if req == oreq:
                continue
            if out_reqs[oreq] == out_reqs[req]:
                print " ", yum.misc.prco_tuple_to_string(oreq)
                done.add(oreq)
        for pkg in out_reqs[req]:
            print "   ", pkg, pkg.ui_from_repo

def _print_sum(title, used_repos, ind=" ", end=' '):
    if not used_repos:
        return

    print title
    crepos = {}
    installed = 0
    available = 0
    for urepo in used_re