Given an rpm package name, query the yum database for updates

前端 未结 2 1199
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-18 04:02

I was imagining a 3-line Python script to do this but the yum Python API is impenetrable. Is this even possible?

Is writing a wrapper for \'yum list package-name\'

相关标签:
2条回答
  • 2020-12-18 04:33

    http://fpaste.org/paste/2453

    and there are many examples of the yum api and some guides to getting started with it here:

    http://yum.baseurl.org/#DeveloperDocumentationExamples

    0 讨论(0)
  • 2020-12-18 04:35

    As Seth points out, you can use the updates APIs to ask if something is available as an update. For something that's close to what the "yum list" does you probably want to use the doPackageLists(). Eg.

    import os, sys
    import yum
    
    yb = yum.YumBase()
    yb.conf.cache = os.geteuid() != 1
    pl = yb.doPackageLists(patterns=sys.argv[1:])
    if pl.installed:
        print "Installed Packages"
        for pkg in sorted(pl.installed):
            print pkg
    if pl.available:
        print "Available Packages"
        for pkg in sorted(pl.available):
            print pkg, pkg.repo
    if pl.reinstall_available:
        print "Re-install Available Packages"
        for pkg in sorted(pl.reinstall_available):
            print pkg, pkg.repo
    
    0 讨论(0)
提交回复
热议问题