1
2
3
4
5
6
7
8 import os
9 import apt
10 import gettext
11 t = gettext.translation('rhn-client-tools', fallback=True)
12
13 if not hasattr(t, 'ugettext'):
14 t.ugettext = t.gettext
15 _ = t.ugettext
16
17
18
28
39
41 dir = '/var/lib/dpkg/info'
42 files = [ '%s.list' % pkg_name,
43 '%s:%s.list' % (pkg_name, pkg_arch) ]
44
45 if ':' in pkg_name:
46 files.append('%s.list' % (pkg_name[:pkg_name.index(':')]))
47 for f in files:
48 path = os.path.join(dir,f)
49 if os.path.isfile(path):
50 return os.path.getmtime(path)
51 return 0
52
53
54
55
58 """ Return list of packages. Package is dict with following keys:
59 name, epoch, version, release and optionaly arch.
60 """
61 if msgCallback != None:
62 msgCallback(_("Getting list of packages installed on the system"))
63 cache = apt.Cache()
64
65 total = 0
66 for pkg in cache:
67 if pkg.installed != None:
68 total += 1
69
70 count = 0
71 pkg_list = []
72 for pkg in cache:
73 if pkg.installed == None:
74 continue
75 version, release, epoch = parseVRE(pkg.installed.version)
76 package = {
77 'name': pkg.name,
78 'epoch': epoch,
79 'version': version,
80 'release': release,
81 'arch': pkg.installed.architecture + '-deb',
82 'installtime': installTime(pkg.name, pkg.installed.architecture)
83 }
84 pkg_list.append(package)
85
86 if progressCallback != None:
87 progressCallback(count, total)
88 count = count + 1
89
90 pkg_list.sort()
91 return pkg_list
92
95