1 """Handles differences between different distributions
2
3 Authors: Dave Malcolm <dmalcolm@redhat.com>, Zack Cerza <zcerza@redhat.com>"""
4 __author__ = "Dave Malcolm <dmalcolm@redhat.com>, Zack Cerza <zcerza@redhat.com>"
5
6 import os
7 import re
8 from version import Version
9 from logging import debugLogger as logger
10
12 """
13 This distribution is not supported.
14 """
15 PATCH_MESSAGE = "Please send patches to dogtail-devel-list@gnome.org"
16
19
22
24 """
25 Error finding the requested package.
26 """
27 pass
28
29 global packageDb
30 global distro
31
33 """
34 Class to abstract the details of whatever software package database is in
35 use (RPM, APT, etc)
36 """
38 self.prefix = '/usr'
39 self.localePrefixes = [self.prefix + '/share/locale']
40
42 """
43 Method to get the version of an installed package as a Version
44 instance (or raise an exception if not found)
45
46 Note: does not know about distributions' internal revision numbers.
47 """
48 raise NotImplementedError
49
51 """
52 Method to get a list of filenames owned by the package, or raise an
53 exception if not found.
54 """
55 raise NotImplementedError
56
58 """
59 Method to get a list of all .mo files on the system, optionally for a
60 specific locale.
61 """
62 moFiles = {}
63
64 def appendIfMoFile(moFiles, dirName, fNames):
65 import re
66 for fName in fNames:
67 if re.match('(.*)\\.mo', fName):
68 moFiles[dirName + '/' + fName] = None
69
70 for localePrefix in self.localePrefixes:
71 if locale: localePrefix = localePrefix + '/' + locale
72 os.path.walk(localePrefix, appendIfMoFile, moFiles)
73
74 return moFiles.keys()
75
77 """
78 Method to get a list of unique package names that this package
79 is dependent on, or raise an exception if the package is not
80 found.
81 """
82 raise NotImplementedError
83
87
94
96 import rpm
97 ts = rpm.TransactionSet()
98 for header in ts.dbMatch("name", packageName):
99 return header["filenames"]
100 raise PackageNotFoundError, packageName
101
103 import rpm
104 ts = rpm.TransactionSet()
105 for header in ts.dbMatch("name", packageName):
106
107
108 result = {}
109
110
111
112
113
114 for requirement in header[rpm.RPMTAG_REQUIRES]:
115
116
117 for depPackageHeader in ts.dbMatch("provides", requirement):
118 depName = depPackageHeader['name']
119 if depName!=packageName:
120
121 result[depName]=None
122 return result.keys()
123 raise PackageNotFoundError, packageName
124
129
131 if not self.cache:
132 import apt_pkg
133 apt_pkg.init()
134 self.cache = apt_pkg.GetCache()
135 packages = self.cache.Packages
136 for package in packages:
137 if package.Name == packageName:
138 import re
139 verString = re.match('.*Ver:\'(.*)-.*\' Section:', str(package.CurrentVer)).group(1)
140 return Version.fromString(verString)
141 raise PackageNotFoundError, packageName
142
144 files = []
145 list = os.popen('dpkg -L %s' % packageName).readlines()
146 if not list:
147 raise PackageNotFoundError, packageName
148 else:
149 for line in list:
150 file = line.strip()
151 if file: files.append(file)
152 return files
153
155
156
157 result = {}
158 if not self.cache:
159 import apt_pkg
160 apt_pkg.init()
161 self.cache = apt_pkg.GetCache()
162 packages = self.cache.Packages
163 for package in packages:
164 if package.Name == packageName:
165 current = package.CurrentVer
166 if not current:
167 raise PackageNotFoundError, packageName
168 depends = current.DependsList
169 list = depends['Depends']
170 for dependency in list:
171 name = dependency[0].TargetPkg.Name
172
173 result[name] = None
174 return result.keys()
175
180
184
186
187
188 import sys
189 sys.path.append ('/usr/lib/portage/pym')
190 import portage
191
192
193
194 gentooPackageName = portage.db["/"]["vartree"].dbapi.match(packageName)[0].split('/')[1];
195
196
197 upstreamVersion = portage.pkgsplit(gentooPackageName)[1]
198
199 return Version.fromString(upstreamVersion);
200
204
206 import conary
207 from conaryclient import ConaryClient
208 client = ConaryClient()
209 dbVersions = client.db.getTroveVersionList(packageName)
210 if not len(dbVersions):
211 raise PackageNotFoundError, packageName
212 return dbVersions[0].trailingRevision().asString().split("-")[0]
213
214
215
216
220
223 PackageDb.__init__(self)
224 prefixes = []
225 prefixes.append(os.environ['LD_LIBRARY_PATH'])
226 prefixes.append(os.environ['XDG_CONFIG_DIRS'])
227 prefixes.append(os.environ['PKG_CONFIG_PATH'])
228 self.prefix = os.path.commonprefix(prefixes)
229 self.localePrefixes.append(self.prefix + '/share/locale')
230
232 result = {}
233 lines = os.popen('jhbuild list ' + packageName).readlines()
234 for line in lines:
235 if line:
236 result[line.strip()] = None
237 return result.keys()
238
240 """
241 Class representing a distribution.
242
243 Scripts may want to do arbitrary logic based on whichever distro is in use
244 (e.g. handling differences in names of packages, distribution-specific
245 patches, etc.)
246
247 We can either create methods in the Distro class to handle these, or we
248 can use constructs like isinstance(distro, Ubuntu) to handle this. We can
249 even create hierarchies of distro subclasses to handle this kind of thing
250 (could get messy fast though)
251 """
252
256
259
263
267
271
275
279
283
287
316
317 distro = detectDistro()
318 packageDb = distro.packageDb
319