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

发布于 2021-01-29 14:09:49

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’ the only way to do this?

关注者
0
被浏览
144
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    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
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看