| 1 | #! /usr/bin/python -tt
|
|---|
| 2 |
|
|---|
| 3 | import os
|
|---|
| 4 | import sys
|
|---|
| 5 | import yum
|
|---|
| 6 |
|
|---|
| 7 | yb = yum.YumBase()
|
|---|
| 8 | yb.setCacheDir()
|
|---|
| 9 | yb.conf.cache = os.geteuid() != 1
|
|---|
| 10 |
|
|---|
| 11 | try:
|
|---|
| 12 | if len(sys.argv) > 1 and sys.argv[1] in ['all',
|
|---|
| 13 | 'installed',
|
|---|
| 14 | 'available',
|
|---|
| 15 | 'updates',
|
|---|
| 16 | 'recent',
|
|---|
| 17 | 'obsoletes',
|
|---|
| 18 | 'extras']:
|
|---|
| 19 | what = sys.argv[1]
|
|---|
| 20 | if len(sys.argv) < 3:
|
|---|
| 21 | pl = yb.doPackageLists(pkgnarrow=what)
|
|---|
| 22 | else:
|
|---|
| 23 | pl = yb.doPackageLists(pkgnarrow=what, patterns=sys.argv[2:])
|
|---|
| 24 | else:
|
|---|
| 25 | what = ''
|
|---|
| 26 | if len(sys.argv) < 2:
|
|---|
| 27 | pl = yb.doPackageLists()
|
|---|
| 28 | else:
|
|---|
| 29 | pl = yb.doPackageLists(patterns=sys.argv[1:])
|
|---|
| 30 | except yum.Errors.YumBaseError as exc:
|
|---|
| 31 | what, why, other = exc.value
|
|---|
| 32 | print 'Error:', what, why
|
|---|
| 33 |
|
|---|
| 34 | if pl.installed:
|
|---|
| 35 | print "Installed Packages"
|
|---|
| 36 | for pkg in sorted(pl.installed):
|
|---|
| 37 | print pkg.name, pkg.version + "-" + pkg.release, pkg.repoid, pkg.summary
|
|---|
| 38 | print
|
|---|
| 39 | if pl.available:
|
|---|
| 40 | print "Available Packages"
|
|---|
| 41 | for pkg in sorted(pl.available):
|
|---|
| 42 | print pkg.name, pkg.version + "-" + pkg.release, pkg.repo, pkg.summary
|
|---|
| 43 | print
|
|---|
| 44 |
|
|---|
| 45 | if what == '':
|
|---|
| 46 | pl = yb.doPackageLists(pkgnarrow='updates',patterns=sys.argv[1:])
|
|---|
| 47 | if pl.updates:
|
|---|
| 48 | print "Updated Packages"
|
|---|
| 49 | for pkg in sorted(pl.updates):
|
|---|
| 50 | print pkg.name, pkg.version + "-" + pkg.release, pkg.repo
|
|---|
| 51 | print
|
|---|
| 52 |
|
|---|
| 53 | if what == '':
|
|---|
| 54 | pl = yb.doPackageLists(pkgnarrow='recent',patterns=sys.argv[1:])
|
|---|
| 55 | if pl.recent:
|
|---|
| 56 | print "Recently Added Packages"
|
|---|
| 57 | for pkg in sorted(pl.recent):
|
|---|
| 58 | print pkg.name, pkg.version + "-" + pkg.release, pkg.repo
|
|---|
| 59 | print
|
|---|
| 60 |
|
|---|
| 61 | if pl.obsoletes:
|
|---|
| 62 | print "Obsolete Packages"
|
|---|
| 63 | for pkg in sorted(pl.obsoletes):
|
|---|
| 64 | print pkg.name, pkg.version + "-" + pkg.release, pkg.repo, pkg.summary
|
|---|
| 65 | print
|
|---|
| 66 |
|
|---|
| 67 | if pl.extras:
|
|---|
| 68 | print "Extra Packages"
|
|---|
| 69 | for pkg in sorted(pl.extras):
|
|---|
| 70 | print pkg.name, pkg.version + "-" + pkg.release, pkg.repo, pkg.summary
|
|---|
| 71 | print
|
|---|
| 72 |
|
|---|