Re: RPM Updates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2007-01-29 at 14:20 -0700, Ashley M. Kirchner wrote:
>     Would someone please tell me how's this done?

use the attached script. worked for me.

> -- 
> W | It's not a bug - it's an undocumented feature.
>   +--------------------------------------------------------------------
>   Ashley M. Kirchner <mailto:ashley@xxxxxxxxxx>   .   303.442.6410 x130
>   IT Director / SysAdmin / Websmith             .     800.441.3873 x130
>   Photo Craft Imaging                       .     3550 Arapahoe Ave. #6
>   http://www.pcraft.com ..... .  .    .       Boulder, CO 80303, U.S.A.
> 
#!/usr/bin/python -tt

import sys
sys.path.insert(0,'/usr/share/yum-cli')
import cli

def findDupes(my):
    """takes a yum base object prints out a list of package duplicates.
       These typically happen when an update transaction is left half-completed"""
       
    # iterate rpmdb.pkglist
    # put each package into name.arch dicts with lists as the po
    # look for any keys with a > 1 length list of pos where the name
    # of the package is not kernel and/or does not provide a kernel-module
    pkgdict = {}
    refined = {}
    dupes = []
    
    for (n,a,e,v,r) in my.rpmdb.simplePkgList():
        if not pkgdict.has_key((n,a)):
            pkgdict[(n,a)] = []
        pkgdict[(n,a)].append((e,v,r))
    
    for (n,a) in pkgdict.keys():
        if len(pkgdict[(n,a)]) > 1:
            refined[(n,a)] = pkgdict[(n,a)]
    
    del pkgdict
    
    return refined
    

def setupOldDupes(my):
    """remove all the older duplicates"""

    dupedict = findDupes(my)
    removedupes = []
    for (n,a) in dupedict.keys():
        if n.startswith('kernel'):
            continue
        if n.startswith('gpg-pubkey'):
            continue
        (e,v,r) = dupedict[(n,a)][0]
        lowpo = my.getInstalledPackageObject((n,a,e,v,r))

        for (e,v,r) in dupedict[(n,a)][1:]:
            po = my.getInstalledPackageObject((n,a,e,v,r))
            if po.EVR < lowpo.EVR:
                lowpo = po
                
        removedupes.append(lowpo)

    for po in removedupes:
        my.remove(po)
    
    return len(removedupes)

def main():
    my = cli.YumBaseCli()
    my.doGenericSetup()

    #something here to set -y or not
    num = setupOldDupes(my)
    if num < 1:
        print 'no dupes to remove'
        sys.exit(0)

    my.buildTransaction()
    my.doTransaction()

    sys.exit(0)


if __name__ == "__main__":
  main()


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux