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
11
13
14 """
15 This distribution is not supported.
16 """
17 PATCH_MESSAGE = "Please send patches to dogtail-devel-list@gnome.org"
18
21
24
25
27
28 """
29 Error finding the requested package.
30 """
31 pass
32
33 global packageDb
34 global distro
35
36
38
39 """
40 Class to abstract the details of whatever software package database is in
41 use (RPM, APT, etc)
42 """
43
45 self.prefix = '/usr'
46 self.localePrefixes = [self.prefix + '/share/locale']
47
49 """
50 Method to get the version of an installed package as a Version
51 instance (or raise an exception if not found)
52
53 Note: does not know about distributions' internal revision numbers.
54 """
55 raise NotImplementedError
56
58 """
59 Method to get a list of filenames owned by the package, or raise an
60 exception if not found.
61 """
62 raise NotImplementedError
63
65 """
66 Method to get a list of all .mo files on the system, optionally for a
67 specific locale.
68 """
69 moFiles = {}
70
71 def appendIfMoFile(moFiles, dirName, fNames):
72 import re
73 for fName in fNames:
74 if re.match('(.*)\\.mo', fName):
75 moFiles[dirName + '/' + fName] = None
76
77 for localePrefix in self.localePrefixes:
78 if locale:
79 localePrefix = localePrefix + '/' + locale
80 os.path.walk(localePrefix, appendIfMoFile, moFiles)
81
82 return moFiles.keys()
83
85 """
86 Method to get a list of unique package names that this package
87 is dependent on, or raise an exception if the package is not
88 found.
89 """
90 raise NotImplementedError
91
92
94
97
99 import rpm
100 ts = rpm.TransactionSet()
101 for header in ts.dbMatch("name", packageName):
102 return Version.fromString(header["version"])
103 raise PackageNotFoundError(packageName)
104
106 import rpm
107 ts = rpm.TransactionSet()
108 for header in ts.dbMatch("name", packageName):
109 return header["filenames"]
110 raise PackageNotFoundError(packageName)
111
113 import rpm
114 ts = rpm.TransactionSet()
115 for header in ts.dbMatch("name", packageName):
116
117
118 result = {}
119
120
121
122
123
124 for requirement in header[rpm.RPMTAG_REQUIRES]:
125
126
127 for depPackageHeader in ts.dbMatch("provides", requirement):
128 depName = depPackageHeader['name']
129 if depName != packageName:
130
131 result[depName] = None
132 return result.keys()
133 raise PackageNotFoundError(packageName)
134
135
137
141
143 if not self.cache:
144 import apt_pkg
145 apt_pkg.init()
146 self.cache = apt_pkg.GetCache()
147 packages = self.cache.Packages
148 for package in packages:
149 if package.Name == packageName:
150 verString = re.match(
151 '.*Ver:\'(.*)-.*\' Section:', str(package.CurrentVer)).group(1)
152 return Version.fromString(verString)
153 raise PackageNotFoundError(packageName)
154
156 files = []
157 list = os.popen('dpkg -L %s' % packageName).readlines()
158 if not list:
159 raise PackageNotFoundError(packageName)
160 else:
161 for line in list:
162 file = line.strip()
163 if file:
164 files.append(file)
165 return files
166
168
169
170 result = {}
171 if not self.cache:
172 import apt_pkg
173 apt_pkg.init()
174 self.cache = apt_pkg.GetCache()
175 packages = self.cache.Packages
176 for package in packages:
177 if package.Name == packageName:
178 current = package.CurrentVer
179 if not current:
180 raise PackageNotFoundError(packageName)
181 depends = current.DependsList
182 list = depends['Depends']
183 for dependency in list:
184 name = dependency[0].TargetPkg.Name
185
186 result[name] = None
187 return result.keys()
188
189
195
196
198
201
203
204
205 import sys
206 sys.path.append('/usr/lib/portage/pym')
207 import portage
208
209
210
211 gentooPackageName = portage.db["/"][
212 "vartree"].dbapi.match(packageName)[0].split('/')[1]
213
214
215 upstreamVersion = portage.pkgsplit(gentooPackageName)[1]
216
217 return Version.fromString(upstreamVersion)
218
219
221
224
226 from conaryclient import ConaryClient
227 client = ConaryClient()
228 dbVersions = client.db.getTroveVersionList(packageName)
229 if not len(dbVersions):
230 raise PackageNotFoundError(packageName)
231 return dbVersions[0].trailingRevision().asString().split("-")[0]
232
233
234
235
236
237
239
242
243
245
247 PackageDb.__init__(self)
248 prefixes = []
249 prefixes.append(os.environ['LD_LIBRARY_PATH'])
250 prefixes.append(os.environ['XDG_CONFIG_DIRS'])
251 prefixes.append(os.environ['PKG_CONFIG_PATH'])
252 self.prefix = os.path.commonprefix(prefixes)
253 self.localePrefixes.append(self.prefix + '/share/locale')
254
256 result = {}
257 lines = os.popen('jhbuild list ' + packageName).readlines()
258 for line in lines:
259 if line:
260 result[line.strip()] = None
261 return result.keys()
262
263
265
266 """
267 Class representing a distribution.
268
269 Scripts may want to do arbitrary logic based on whichever distro is in use
270 (e.g. handling differences in names of packages, distribution-specific
271 patches, etc.)
272
273 We can either create methods in the Distro class to handle these, or we
274 can use constructs like isinstance(distro, Ubuntu) to handle this. We can
275 even create hierarchies of distro subclasses to handle this kind of thing
276 (could get messy fast though)
277 """
278
279
281
284
285
287 pass
288
289
291
294
295
300
301
303
306
307
309
312
313
315
318
319
321
324
325
327
330
331
360
361 distro = detectDistro()
362 packageDb = distro.packageDb
363