Ticket #96: yum_list.py

File yum_list.py, 2.2 KB (added by Alex Taylor, 10 years ago)

Python script using YUM API

Line 
1#! /usr/bin/python -tt
2
3import os
4import sys
5import yum
6
7yb = yum.YumBase()
8yb.setCacheDir()
9yb.conf.cache = os.geteuid() != 1
10
11try:
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:])
30except yum.Errors.YumBaseError as exc:
31 what, why, other = exc.value
32 print 'Error:', what, why
33
34if 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
39if 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
45if what == '':
46 pl = yb.doPackageLists(pkgnarrow='updates',patterns=sys.argv[1:])
47if 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
53if what == '':
54 pl = yb.doPackageLists(pkgnarrow='recent',patterns=sys.argv[1:])
55if 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
61if 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
67if 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