| Trees | Indices | Help |
|---|
|
|
1 # Client code for Update Agent
2 # Copyright (c) 2011--2016 Red Hat, Inc. Distributed under GPLv2.
3 #
4 # Author: Simon Lukasik
5 # Lukas Durfina
6 #
7
8 import os
9 import apt
10 import gettext
11 t = gettext.translation('rhn-client-tools', fallback=True)
12 # Python 3 translations don't have a ugettext method
13 if not hasattr(t, 'ugettext'):
14 t.ugettext = t.gettext
15 _ = t.ugettext
16
17
18 # FIXME: After Debian bug 187019 is resolved
20 cache = apt.Cache()
21 missing_packages = []
22 for package in packages:
23 pkg = cache[package[0]]
24 if pkg == None or not pkg.is_installed:
25 missing_packages.append(package)
26
27 return [], missing_packages
28
30 epoch = ''
31 release = 'X'
32 if version.find(':') != -1:
33 epoch, version = version.split(':')
34 if version.find('-') != -1:
35 tmp = version.split('-')
36 version = '-'.join(tmp[:-1])
37 release = tmp[-1]
38 return version, release, epoch
39
41 dir = '/var/lib/dpkg/info'
42 files = [ '%s.list' % pkg_name,
43 '%s:%s.list' % (pkg_name, pkg_arch) ]
44 # In edge cases, pkg_name can include the arch but the .list file does not
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 #FIXME: Using Apt cache might not be an ultimate solution.
54 # It could be better to parse /var/lib/dpkg/status manually.
55 # Apt cache might not contain all the packages.
56 -def getInstalledPackageList(msgCallback = None, progressCallback = None,
57 getArch=None, getInfo = None):
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
| Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Wed Mar 4 07:37:49 2020 | http://epydoc.sourceforge.net |