Merge lp:~jml/pkgme/remove-binary-backend into lp:pkgme
- remove-binary-backend
- Merge into trunk
Proposed by
Jonathan Lange
Status: | Merged |
---|---|
Approved by: | James Westby |
Approved revision: | 76 |
Merged at revision: | 75 |
Proposed branch: | lp:~jml/pkgme/remove-binary-backend |
Merge into: | lp:pkgme |
Diff against target: |
857 lines (+0/-800) 9 files modified
pkgme/backends/binary/build_depends (+0/-14) pkgme/backends/binary/depends (+0/-11) pkgme/backends/binary/extra_files (+0/-36) pkgme/backends/binary/package_name (+0/-17) pkgme/backends/binary/want (+0/-15) pkgme/binary.py (+0/-249) pkgme/tests/__init__.py (+0/-2) pkgme/tests/test_binary.py (+0/-339) pkgme/tests/test_binary_backend.py (+0/-117) |
To merge this branch: | bzr merge lp:~jml/pkgme/remove-binary-backend |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Westby | Approve | ||
Review via email: mp+71023@code.launchpad.net |
Commit message
Description of the change
This branch removes the binary backend from pkgme.
There are several reasons why this is a good idea, or at least, not a bad one.
* As it stands in trunk, the binary backend needs a devportal-
* As it stands in lp:~jml/pkgme/improve-auto-depends, it also needs a 1.5 GB database. Any functioning implementation will need a database of similar size, or access to an external service that provides such a database
* pkgme allows for third-party backends, so why not use that
To post a comment you must log in.
- 76. By Jonathan Lange
-
Remove data files.
Revision history for this message
James Westby (james-w) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed directory 'pkgme/backends/binary' |
2 | === removed file 'pkgme/backends/binary/build_depends' |
3 | --- pkgme/backends/binary/build_depends 2011-07-18 11:08:14 +0000 |
4 | +++ pkgme/backends/binary/build_depends 1970-01-01 00:00:00 +0000 |
5 | @@ -1,14 +0,0 @@ |
6 | -#!/usr/bin/python |
7 | - |
8 | -import os |
9 | - |
10 | -from pkgme.binary import guess_dependencies |
11 | - |
12 | - |
13 | -def main(): |
14 | - path = os.getcwd() |
15 | - print ', '.join(guess_dependencies(path)) |
16 | - |
17 | - |
18 | -if __name__ == '__main__': |
19 | - main() |
20 | |
21 | === removed file 'pkgme/backends/binary/depends' |
22 | --- pkgme/backends/binary/depends 2011-07-18 11:08:14 +0000 |
23 | +++ pkgme/backends/binary/depends 1970-01-01 00:00:00 +0000 |
24 | @@ -1,11 +0,0 @@ |
25 | -#!/usr/bin/python |
26 | - |
27 | -from pkgme.binary import DEPENDS |
28 | - |
29 | - |
30 | -def main(): |
31 | - print DEPENDS |
32 | - |
33 | - |
34 | -if __name__ == '__main__': |
35 | - main() |
36 | |
37 | === removed file 'pkgme/backends/binary/extra_files' |
38 | --- pkgme/backends/binary/extra_files 2011-07-18 11:08:14 +0000 |
39 | +++ pkgme/backends/binary/extra_files 1970-01-01 00:00:00 +0000 |
40 | @@ -1,36 +0,0 @@ |
41 | -#!/usr/bin/python |
42 | - |
43 | -import json |
44 | -import os |
45 | -import sys |
46 | - |
47 | -from pkgme.binary import ( |
48 | - CATEGORIES, |
49 | - get_desktop_file, |
50 | - get_install_file, |
51 | - METADATA_FILE, |
52 | - PACKAGE_NAME, |
53 | - TAGLINE, |
54 | - ) |
55 | - |
56 | - |
57 | -def main(): |
58 | - with open(METADATA_FILE) as f: |
59 | - metadata = json.load(f) |
60 | - package_name = metadata[PACKAGE_NAME] |
61 | - path = os.getcwd() |
62 | - install_file = get_install_file(package_name, path, True) |
63 | - desktop_file = get_desktop_file( |
64 | - package_name, path, |
65 | - tagline=metadata.get(TAGLINE, ''), |
66 | - categories=metadata.get(CATEGORIES, '')) |
67 | - json.dump( |
68 | - { |
69 | - # XXX: Hardcoded literal attack! |
70 | - 'debian/install': install_file, |
71 | - 'debian/%s.desktop' % (package_name,): desktop_file.get_contents(), |
72 | - }, sys.stdout) |
73 | - |
74 | - |
75 | -if __name__ == '__main__': |
76 | - main() |
77 | |
78 | === removed file 'pkgme/backends/binary/package_name' |
79 | --- pkgme/backends/binary/package_name 2011-07-18 11:08:14 +0000 |
80 | +++ pkgme/backends/binary/package_name 1970-01-01 00:00:00 +0000 |
81 | @@ -1,17 +0,0 @@ |
82 | -#!/usr/bin/python |
83 | - |
84 | -import json |
85 | -from pkgme.binary import ( |
86 | - METADATA_FILE, |
87 | - PACKAGE_NAME, |
88 | - ) |
89 | - |
90 | - |
91 | -def main(): |
92 | - with open(METADATA_FILE) as f: |
93 | - metadata = json.load(f) |
94 | - print metadata[PACKAGE_NAME] |
95 | - |
96 | - |
97 | -if __name__ == '__main__': |
98 | - main() |
99 | |
100 | === removed file 'pkgme/backends/binary/want' |
101 | --- pkgme/backends/binary/want 2011-07-13 13:18:03 +0000 |
102 | +++ pkgme/backends/binary/want 1970-01-01 00:00:00 +0000 |
103 | @@ -1,15 +0,0 @@ |
104 | -#!/usr/bin/python |
105 | - |
106 | -import os |
107 | - |
108 | -from pkgme.binary import METADATA_FILE |
109 | - |
110 | -def main(): |
111 | - if os.path.exists(METADATA_FILE): |
112 | - print 10 |
113 | - else: |
114 | - print 0 |
115 | - |
116 | - |
117 | -if __name__ == '__main__': |
118 | - main() |
119 | |
120 | === removed file 'pkgme/binary.py' |
121 | --- pkgme/binary.py 2011-07-15 16:30:18 +0000 |
122 | +++ pkgme/binary.py 1970-01-01 00:00:00 +0000 |
123 | @@ -1,249 +0,0 @@ |
124 | -"""Things to help package binary tarballs. |
125 | - |
126 | -HIGHLY EXPERIMENTAL. USE AT YOUR OWN PERIL. |
127 | - |
128 | -At the moment, we are assuming a great many things about these binary |
129 | -tarballs. |
130 | - |
131 | -* That they represent some sort of application to be run from an Ubuntu |
132 | - desktop |
133 | - |
134 | -* Specifically, that although they might have many executables, only one is |
135 | - the "main executable" mentioned in the 'desktop' file |
136 | - |
137 | -* They are written in C or C++ and that all dependencies can be determined |
138 | - by inspecting the included object files |
139 | - |
140 | -* That the entire contents of the tarball can be copied into |
141 | - /opt/<package-name> and run from there |
142 | - |
143 | -* That we have a metadata file, called 'devportal-metadata.json', in JSON, |
144 | - that specifies: |
145 | - * package_name |
146 | - |
147 | -The expectation is that this metadata file is generated from the developer |
148 | -portal. |
149 | -""" |
150 | - |
151 | -# XXX: No idea about architecture |
152 | - |
153 | -__all__ = [ |
154 | - 'get_install_file', |
155 | - 'guess_executable', |
156 | - 'iter_executables', |
157 | - 'METADATA_FILE', |
158 | - ] |
159 | - |
160 | - |
161 | -import os |
162 | -import subprocess |
163 | - |
164 | -from pkgme.info_elements import ( |
165 | - ApplicationName, |
166 | - Categories, |
167 | - Executable, |
168 | - PackageName, |
169 | - TagLine, |
170 | - ) |
171 | -from pkgme.package_files import ( |
172 | - DEBIAN_DIR, |
173 | - Desktop, |
174 | - ) |
175 | -from pkgme.project_info import DictInfo |
176 | - |
177 | - |
178 | -METADATA_FILE = 'devportal-metadata.json' |
179 | - |
180 | -# Keys found in the metadata file. |
181 | -CATEGORIES = 'categories' |
182 | -# It's called package_name in the database, so this probably makes sense. |
183 | -PACKAGE_NAME = 'package_name' |
184 | -TAGLINE = 'tagline' |
185 | - |
186 | - |
187 | -# Always depend on these. |
188 | -# |
189 | -# XXX: jml just doing this because iamfuzz does. Need to either experiment or |
190 | -# consult expert. |
191 | -DEPENDS = '${shlibs:Depends}, ${misc:Depends}' |
192 | - |
193 | -# XXX: No idea about how icons will be there. Ignoring for now. |
194 | - |
195 | -def guess_executable(package_name, executables): |
196 | - """ |
197 | - From a list of executables, guess which one is likely to be the main |
198 | - executable. |
199 | - """ |
200 | - |
201 | - # The lower the score, the more likely it is to be the right executable. |
202 | - |
203 | - def score_name(name): |
204 | - # Names that match exactly are good. |
205 | - return -int(name.lower() == package_name.lower()) |
206 | - |
207 | - def score_path(executable): |
208 | - # The deeper the path, the less likely it is to be the one. |
209 | - return executable.count('/') |
210 | - |
211 | - def rank(executable): |
212 | - name = os.path.basename(executable) |
213 | - # The alpha-sorting of the base name is a tie-breaker. |
214 | - return score_name(name), score_path(executable), name |
215 | - |
216 | - try: |
217 | - return sorted(executables, key=rank)[0] |
218 | - except IndexError: |
219 | - return None |
220 | - |
221 | - |
222 | -def iter_executables(path): |
223 | - """Iterate through all executable files under 'path'. |
224 | - |
225 | - Paths yielded will be relative to 'path'. Directories will *not* be |
226 | - yielded. "Executable" is determined by filesystem permissions. |
227 | - """ |
228 | - for root, dirs, files in os.walk(path): |
229 | - for filename in files: |
230 | - file_path = os.path.join(root, filename) |
231 | - if os.access(file_path, os.X_OK): |
232 | - yield os.path.relpath(file_path, path) |
233 | - |
234 | - |
235 | -def get_install_file(package_name, path, include_desktop=False): |
236 | - """Generate the install file for 'package_name'.""" |
237 | - lines = [] |
238 | - # Sorting not actually needed for functionality, but makes the tests more |
239 | - # reliable. |
240 | - for filename in sorted(os.listdir(path)): |
241 | - if filename in (DEBIAN_DIR, METADATA_FILE): |
242 | - # We don't want to install the 'debian/' directory or the metadata |
243 | - # file. |
244 | - continue |
245 | - lines.append('%s opt/%s' % (filename, package_name)) |
246 | - if include_desktop: |
247 | - lines.append( |
248 | - 'debian/%s.desktop usr/share/application' % (package_name,)) |
249 | - # Ending the file with a newline is basic good manners. |
250 | - lines.append('') |
251 | - return '\n'.join(lines) |
252 | - |
253 | - |
254 | -def get_desktop_file(package_name, path, tagline=None, categories=None): |
255 | - executable = guess_executable(package_name, iter_executables(path)) |
256 | - info = { |
257 | - PackageName.name: package_name, |
258 | - ApplicationName.name: package_name.capitalize(), |
259 | - Executable.name: '/opt/%s/%s' % (package_name, executable), |
260 | - TagLine.name: tagline, |
261 | - Categories.name: categories, |
262 | - } |
263 | - return Desktop.from_info(DictInfo(info)) |
264 | - |
265 | - |
266 | -def get_file_type(path): |
267 | - return get_file_types([path])[0] |
268 | - |
269 | - |
270 | -def get_file_types(paths): |
271 | - paths = list(paths) |
272 | - if not paths: |
273 | - return [] |
274 | - cmd = ['file', '-b'] + paths |
275 | - return subprocess.Popen( |
276 | - cmd, stdout=subprocess.PIPE).communicate()[0].splitlines() |
277 | - |
278 | - |
279 | -def ldd(binary_paths): |
280 | - # ldd has output of the form: |
281 | - # |
282 | - # path/to/elf/object: |
283 | - # linux-vdso.so.1 => (0x00007fff4a7ff000) |
284 | - # libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7472623000) |
285 | - # /lib64/ld-linux-x86-64.so.2 (0x00007f74729e5000) |
286 | - # |
287 | - # i.e. |
288 | - # <name> => <path> (<address>) |
289 | - # |
290 | - # where <name> and <path> are both optional. If <name> is not given, then |
291 | - # there is no arrow (=>). |
292 | - binary_paths = list(binary_paths) |
293 | - if not binary_paths: |
294 | - return {} |
295 | - cmd = ['ldd'] + binary_paths |
296 | - output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] |
297 | - libraries = {} |
298 | - current = [] |
299 | - if len(binary_paths) == 1: |
300 | - libraries[binary_paths[0]] = current |
301 | - for line in output.splitlines(): |
302 | - if line.endswith(':'): |
303 | - current.sort() |
304 | - current = libraries[line.strip(':')] = [] |
305 | - continue |
306 | - # Last token is always irrelevant hex address. |
307 | - tokens = line.split()[:-1] |
308 | - name, path = None, None |
309 | - if '=>' in tokens: |
310 | - name = tokens[0] |
311 | - if len(tokens) > 2: |
312 | - path = tokens[2] |
313 | - else: |
314 | - path = tokens[0] |
315 | - current.append((name, path)) |
316 | - current.sort() |
317 | - return libraries |
318 | - |
319 | - |
320 | -def get_shared_library_dependencies(paths): |
321 | - # XXX: Not sure which of these is more useful. Specifically, if the |
322 | - # library isn't installed on the system, then I don't know whether it will |
323 | - # appear in ldd as the library_path. -- jml |
324 | - libraries = ldd(paths) |
325 | - for libs in libraries.values(): |
326 | - for name, library_path in libs: |
327 | - if library_path: |
328 | - yield library_path |
329 | - |
330 | - |
331 | -def find_shared_library_dependencies(path): |
332 | - return set(get_shared_library_dependencies(iter_binaries(path))) |
333 | - |
334 | - |
335 | -def iter_binaries(path): |
336 | - |
337 | - def is_binary(file_type): |
338 | - return file_type.startswith('ELF') |
339 | - |
340 | - for root, dirs, files in os.walk(path): |
341 | - paths = [os.path.join(root, filename) for filename in files] |
342 | - types = get_file_types(paths) |
343 | - for file_path, file_type in zip(paths, types): |
344 | - if is_binary(file_type): |
345 | - yield file_path |
346 | - |
347 | - |
348 | -def apt_file(filename): |
349 | - # XXX: Assumes apt-file update has been run. |
350 | - |
351 | - # XXX: Passing the full file name since it seems the least likely to yield |
352 | - # multiple dependencies. If 'get_shared_library_dependencies' ought to |
353 | - # return just the names, then this will have to change to be a regex, and |
354 | - # we'll need to think about ambiguity resolution much sooner. |
355 | - # cmd = ['apt-file', 'find', '-x', '/%s$' % (filename,)] |
356 | - |
357 | - # XXX: Currently matching badly due to architecture. |
358 | - cmd = ['apt-file', 'find', '-F', filename] |
359 | - output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] |
360 | - for line in output.splitlines(): |
361 | - yield line.split(': ')[0] |
362 | - |
363 | - |
364 | -def guess_dependencies(path): |
365 | - deps = set() |
366 | - # XXX: ldd probably is recursive. This means it finds *all* the libraries |
367 | - # that are needed. However, we only need to specify the top-level |
368 | - # libraries (e.g. libc6 should almost never be a dependency). |
369 | - for library in find_shared_library_dependencies(path): |
370 | - for dep in apt_file(library): |
371 | - deps.add(dep) |
372 | - return deps |
373 | |
374 | === modified file 'pkgme/tests/__init__.py' |
375 | --- pkgme/tests/__init__.py 2011-08-01 16:48:11 +0000 |
376 | +++ pkgme/tests/__init__.py 2011-08-10 12:24:37 +0000 |
377 | @@ -7,8 +7,6 @@ |
378 | def test_suite(): |
379 | module_names = [ |
380 | 'pkgme.tests.test_backend', |
381 | - 'pkgme.tests.test_binary', |
382 | - 'pkgme.tests.test_binary_backend', |
383 | 'pkgme.tests.test_distutils_command', |
384 | 'pkgme.tests.test_info_elements', |
385 | 'pkgme.tests.test_package_files', |
386 | |
387 | === removed file 'pkgme/tests/foo.data' |
388 | Binary files pkgme/tests/foo.data 2011-07-15 16:26:43 +0000 and pkgme/tests/foo.data 1970-01-01 00:00:00 +0000 differ |
389 | === removed file 'pkgme/tests/hello' |
390 | Binary files pkgme/tests/hello 2011-07-15 09:49:16 +0000 and pkgme/tests/hello 1970-01-01 00:00:00 +0000 differ |
391 | === removed file 'pkgme/tests/simple.so.1' |
392 | Binary files pkgme/tests/simple.so.1 2011-07-15 09:49:16 +0000 and pkgme/tests/simple.so.1 1970-01-01 00:00:00 +0000 differ |
393 | === removed file 'pkgme/tests/test_binary.py' |
394 | --- pkgme/tests/test_binary.py 2011-07-15 16:30:18 +0000 |
395 | +++ pkgme/tests/test_binary.py 1970-01-01 00:00:00 +0000 |
396 | @@ -1,339 +0,0 @@ |
397 | -import os |
398 | - |
399 | -from fixtures import TestWithFixtures |
400 | -from testtools import TestCase |
401 | -from testtools.matchers import StartsWith |
402 | - |
403 | -from pkgme.binary import ( |
404 | - apt_file, |
405 | - find_shared_library_dependencies, |
406 | - get_desktop_file, |
407 | - get_file_type, |
408 | - get_file_types, |
409 | - get_install_file, |
410 | - get_shared_library_dependencies, |
411 | - guess_dependencies, |
412 | - guess_executable, |
413 | - iter_binaries, |
414 | - iter_executables, |
415 | - ldd, |
416 | - METADATA_FILE, |
417 | - ) |
418 | -from pkgme.package_files import DEBIAN_DIR |
419 | -from pkgme.testing import ( |
420 | - AreDesktopValuesFor, |
421 | - TempdirFixture, |
422 | - ) |
423 | - |
424 | - |
425 | -class BinaryTests(TestCase, TestWithFixtures): |
426 | - |
427 | - def test_metadata_file(self): |
428 | - self.assertEqual('devportal-metadata.json', METADATA_FILE) |
429 | - |
430 | - |
431 | -class InstallFileTests(TestCase, TestWithFixtures): |
432 | - |
433 | - def test_install_file(self): |
434 | - # The install file instructs debhelper to copy everything in the |
435 | - # top-level to /opt/<package-name>. |
436 | - tempdir = self.useFixture(TempdirFixture()) |
437 | - tempdir.touch('some-file') |
438 | - install_file = get_install_file('package-name', tempdir.path) |
439 | - self.assertEqual("some-file opt/package-name\n", install_file) |
440 | - |
441 | - def test_install_file_many_files_and_directories(self): |
442 | - # The install file instructs debhelper to copy everything in the |
443 | - # top-level to /opt/<package-name>. |
444 | - tempdir = self.useFixture(TempdirFixture()) |
445 | - tempdir.touch('some-file') |
446 | - tempdir.mkdir('directory') |
447 | - install_file = get_install_file('package-name', tempdir.path) |
448 | - self.assertEqual( |
449 | - "directory opt/package-name\n" |
450 | - "some-file opt/package-name\n", |
451 | - install_file) |
452 | - |
453 | - def test_skip_debian(self): |
454 | - # The install file instructs debhelper to copy everything in the |
455 | - # top-level to /opt/<package-name>, except for the 'debian' directory. |
456 | - tempdir = self.useFixture(TempdirFixture()) |
457 | - tempdir.touch('some-file') |
458 | - tempdir.mkdir('directory') |
459 | - tempdir.mkdir(DEBIAN_DIR) |
460 | - install_file = get_install_file('package-name', tempdir.path) |
461 | - self.assertEqual( |
462 | - "directory opt/package-name\n" |
463 | - "some-file opt/package-name\n", |
464 | - install_file) |
465 | - |
466 | - def test_skip_metadata(self): |
467 | - # The install file instructs debhelper to copy everything in the |
468 | - # top-level to /opt/<package-name>, except for the 'debian' directory |
469 | - # and the metadata file. |
470 | - tempdir = self.useFixture(TempdirFixture()) |
471 | - tempdir.touch('some-file') |
472 | - tempdir.mkdir('directory') |
473 | - tempdir.touch(METADATA_FILE) |
474 | - install_file = get_install_file('package-name', tempdir.path) |
475 | - self.assertEqual( |
476 | - "directory opt/package-name\n" |
477 | - "some-file opt/package-name\n", |
478 | - install_file) |
479 | - |
480 | - def test_include_desktop_file(self): |
481 | - tempdir = self.useFixture(TempdirFixture()) |
482 | - tempdir.touch('some-file') |
483 | - install_file = get_install_file( |
484 | - 'package-name', tempdir.path, include_desktop=True) |
485 | - self.assertEqual( |
486 | - "some-file opt/package-name\n" |
487 | - "debian/package-name.desktop usr/share/application\n", |
488 | - install_file) |
489 | - |
490 | - |
491 | -class DesktopFileTests(TestCase): |
492 | - |
493 | - def test_executable_is_best_guess(self): |
494 | - package_name = self.getUniqueString() |
495 | - tempdir = self.useFixture(TempdirFixture()) |
496 | - tempdir.mkdir('whatever') |
497 | - tempdir.touch('whatever/not-the-best', 0755) |
498 | - tempdir.touch('the-best', 0755) |
499 | - desktop_file = get_desktop_file(package_name, tempdir.path) |
500 | - self.assertThat( |
501 | - {'Exec': '/opt/%s/the-best' % (package_name,)}, |
502 | - AreDesktopValuesFor(desktop_file)) |
503 | - |
504 | - def test_app_name_is_capitalized_package_name(self): |
505 | - # We don't have any information on the package name, so try to guess |
506 | - # the application name. |
507 | - tempdir = self.useFixture(TempdirFixture()) |
508 | - package_name = self.getUniqueString() |
509 | - desktop_file = get_desktop_file(package_name, tempdir.path) |
510 | - self.assertThat( |
511 | - {'Name': package_name.capitalize()}, |
512 | - AreDesktopValuesFor(desktop_file)) |
513 | - |
514 | - def test_category_and_tagline_are_specified(self): |
515 | - # We just pass the category and comment through. |
516 | - tempdir = self.useFixture(TempdirFixture()) |
517 | - package_name = self.getUniqueString() |
518 | - tagline = self.getUniqueString() |
519 | - categories = self.getUniqueString() |
520 | - desktop_file = get_desktop_file( |
521 | - package_name, tempdir.path, tagline=tagline, categories=categories) |
522 | - self.assertThat( |
523 | - {'Comment': tagline, 'Categories': categories}, |
524 | - AreDesktopValuesFor(desktop_file)) |
525 | - |
526 | - |
527 | -class FindExecutableTests(TestCase, TestWithFixtures): |
528 | - |
529 | - def test_only_one_file_and_it_is_executable(self): |
530 | - # If there is only one file and it's executable, find that. |
531 | - tempdir = self.useFixture(TempdirFixture()) |
532 | - tempdir.touch('some-file', mode=0755) |
533 | - executables = list(iter_executables(tempdir.path)) |
534 | - self.assertEqual(['some-file'], executables) |
535 | - |
536 | - def test_no_files_at_all(self): |
537 | - # iter_executables finds no executables if there are no files at all. |
538 | - tempdir = self.useFixture(TempdirFixture()) |
539 | - executables = list(iter_executables(tempdir.path)) |
540 | - self.assertEqual([], executables) |
541 | - |
542 | - def test_no_executable_files(self): |
543 | - # If there are no executable files, iter_executables returns None. |
544 | - tempdir = self.useFixture(TempdirFixture()) |
545 | - tempdir.touch('some-file', mode=0644) |
546 | - executables = list(iter_executables(tempdir.path)) |
547 | - self.assertEqual([], executables) |
548 | - |
549 | - def test_directory_is_not_executable_file(self): |
550 | - # A directory does not count as an executable file. |
551 | - tempdir = self.useFixture(TempdirFixture()) |
552 | - tempdir.mkdir('directory') |
553 | - executables = list(iter_executables(tempdir.path)) |
554 | - self.assertEqual([], executables) |
555 | - |
556 | - def test_finds_executable_in_nested_directory(self): |
557 | - # Even if the file is in some nested directory, we are able to find |
558 | - # it. |
559 | - tempdir = self.useFixture(TempdirFixture()) |
560 | - tempdir.mkdir('directory') |
561 | - tempdir.touch('directory/my-executable', mode=0755) |
562 | - executables = list(iter_executables(tempdir.path)) |
563 | - self.assertEqual(['directory/my-executable'], executables) |
564 | - |
565 | - def test_multiple_executables(self): |
566 | - # If there are many executables, iter_executables finds them all. |
567 | - tempdir = self.useFixture(TempdirFixture()) |
568 | - tempdir.touch('some-file', mode=0755) |
569 | - tempdir.touch('another-file', mode=0755) |
570 | - executables = sorted(list(iter_executables(tempdir.path))) |
571 | - self.assertEqual(['another-file', 'some-file'], executables) |
572 | - |
573 | - |
574 | -class GuessExecutableTests(TestCase): |
575 | - |
576 | - def test_no_executables(self): |
577 | - # If there are no executables to select from, then return None, |
578 | - # indicating the fact. |
579 | - executable = guess_executable('package-name', iter([])) |
580 | - self.assertIs(None, executable) |
581 | - |
582 | - def test_only_one_executable(self): |
583 | - # If there's only one executable, then return that, since it's |
584 | - # probably the main executable for the package. |
585 | - executable = guess_executable('package-name', ['whatever']) |
586 | - self.assertEqual('whatever', executable) |
587 | - |
588 | - def test_exact_package_name_match(self): |
589 | - # If there are many executables, but one of them has the same name as |
590 | - # the package, then that is probably the main executable. |
591 | - executable = guess_executable( |
592 | - 'package-name', ['whatever', 'package-name']) |
593 | - self.assertEqual('package-name', executable) |
594 | - |
595 | - def test_exact_package_name_match_in_subdir(self): |
596 | - # If there are many executables, but one of them has the same name as |
597 | - # the package, then that is probably the main executable, even if it |
598 | - # is in a sub-directory. |
599 | - executable = guess_executable( |
600 | - 'package-name', ['whatever', 'subdir/package-name', 'foo']) |
601 | - self.assertEqual('subdir/package-name', executable) |
602 | - |
603 | - def test_multiple_exact_matches(self): |
604 | - # If there are many executables that have the same name as the |
605 | - # package, then the one that is the least nested is our best guess. |
606 | - executable = guess_executable( |
607 | - 'package-name', [ |
608 | - 'whatever', 'a/b/c/d/e/subdir/package-name', 'foo', |
609 | - 'subdir/package-name']) |
610 | - self.assertEqual('subdir/package-name', executable) |
611 | - |
612 | - def test_different_case_match(self): |
613 | - # If one of the executables has the same name as the package, but |
614 | - # spelled with different case, then that is our best guess. |
615 | - executable = guess_executable( |
616 | - 'packagename', [ |
617 | - 'whatever', 'a/b/c/d/e/subdir/packagename', 'foo', |
618 | - 'subdir/PackageName']) |
619 | - self.assertEqual('subdir/PackageName', executable) |
620 | - |
621 | - def test_many_executables(self): |
622 | - # If there are many executables, and their names have no particular |
623 | - # relationship to the package name, then just pick the top-most |
624 | - # one. If there's more than one, take the alphabetically sorted. |
625 | - executable = guess_executable( |
626 | - 'package-name', ['dir/x', 'dir/sub/y', 'z', 'a']) |
627 | - self.assertEqual('a', executable) |
628 | - |
629 | - |
630 | -class GetFileTypeTests(TestCase): |
631 | - |
632 | - def test_plain_text(self): |
633 | - tempdir = self.useFixture(TempdirFixture()) |
634 | - tempdir.create_file('foo.txt', 'boring content\n') |
635 | - file_type = get_file_type(tempdir.abspath('foo.txt')) |
636 | - self.assertEqual('ASCII text', file_type) |
637 | - |
638 | - def test_data(self): |
639 | - file_type = get_file_type( |
640 | - os.path.join(os.path.dirname(__file__), 'foo.data')) |
641 | - self.assertEqual('data', file_type) |
642 | - |
643 | - def test_elf_binary(self): |
644 | - binary_path = os.path.join(os.path.dirname(__file__), 'hello') |
645 | - file_type = get_file_type(binary_path) |
646 | - self.assertThat(file_type, StartsWith('ELF')) |
647 | - |
648 | - def test_elf_library(self): |
649 | - binary_path = os.path.join(os.path.dirname(__file__), 'simple.so.1') |
650 | - file_type = get_file_type(binary_path) |
651 | - self.assertThat(file_type, StartsWith('ELF')) |
652 | - |
653 | - def test_multiple(self): |
654 | - tempdir = self.useFixture(TempdirFixture()) |
655 | - tempdir.create_file('foo.txt', 'boring content\n') |
656 | - file_types = get_file_types( |
657 | - [tempdir.abspath('foo.txt'), |
658 | - os.path.join(os.path.dirname(__file__), 'foo.data')]) |
659 | - self.assertEqual(['ASCII text', 'data'], file_types) |
660 | - |
661 | - def test_no_files_given(self): |
662 | - self.assertEqual([], get_file_types([])) |
663 | - self.assertEqual([], get_file_types(iter([]))) |
664 | - |
665 | - |
666 | -class IterBinariesTests(TestCase): |
667 | - |
668 | - def test_no_binaries(self): |
669 | - tempdir = self.useFixture(TempdirFixture()) |
670 | - self.assertEqual([], list(iter_binaries(tempdir.path))) |
671 | - |
672 | - def test_some_binaries(self): |
673 | - path = os.path.dirname(os.path.dirname(__file__)) |
674 | - binaries = sorted(iter_binaries(path)) |
675 | - self.assertEqual( |
676 | - [os.path.join(os.path.dirname(__file__), 'hello'), |
677 | - os.path.join(os.path.dirname(__file__), 'simple.so.1')], |
678 | - binaries) |
679 | - |
680 | - |
681 | -class GetSharedLibraryDependenciesTests(TestCase): |
682 | - |
683 | - def test_ldd_none(self): |
684 | - deps = ldd([]) |
685 | - self.assertEqual({}, deps) |
686 | - |
687 | - def test_ldd(self): |
688 | - hello = os.path.join(os.path.dirname(__file__), 'hello') |
689 | - deps = ldd([hello]) |
690 | - self.assertEqual( |
691 | - {hello: [(None, '/lib64/ld-linux-x86-64.so.2'), |
692 | - ('libc.so.6', '/lib/x86_64-linux-gnu/libc.so.6'), |
693 | - ('linux-vdso.so.1', None)]}, |
694 | - deps) |
695 | - |
696 | - def test_ldd_multiple(self): |
697 | - hello = os.path.join(os.path.dirname(__file__), 'hello') |
698 | - simple = os.path.join(os.path.dirname(__file__), 'simple.so.1') |
699 | - deps = ldd([hello, simple]) |
700 | - self.assertEqual( |
701 | - {hello: [(None, '/lib64/ld-linux-x86-64.so.2'), |
702 | - ('libc.so.6', '/lib/x86_64-linux-gnu/libc.so.6'), |
703 | - ('linux-vdso.so.1', None)], |
704 | - simple: [(None, '/lib64/ld-linux-x86-64.so.2'), |
705 | - ('libc.so.6', '/lib/x86_64-linux-gnu/libc.so.6'), |
706 | - ('linux-vdso.so.1', None)]}, |
707 | - deps) |
708 | - |
709 | - def test_get_shared_library_dependencies(self): |
710 | - hello = os.path.join(os.path.dirname(__file__), 'hello') |
711 | - deps = sorted(get_shared_library_dependencies([hello])) |
712 | - self.assertEqual( |
713 | - ['/lib/x86_64-linux-gnu/libc.so.6', |
714 | - '/lib64/ld-linux-x86-64.so.2', |
715 | - ], deps) |
716 | - |
717 | - def test_find_shared_library_dependencies(self): |
718 | - deps = find_shared_library_dependencies(os.path.dirname(__file__)) |
719 | - self.assertEqual( |
720 | - set(['/lib/x86_64-linux-gnu/libc.so.6', |
721 | - '/lib64/ld-linux-x86-64.so.2']), deps) |
722 | - |
723 | - |
724 | -class AptFileTests(TestCase): |
725 | - |
726 | - def test_full_file(self): |
727 | - packages = list(apt_file('/usr/lib32/libasound.so.2')) |
728 | - self.assertEqual(['lib32asound2'], packages) |
729 | - |
730 | - |
731 | -class GuessDependenciesTests(TestCase): |
732 | - |
733 | - def test_guess_dependencies(self): |
734 | - deps = guess_dependencies(os.path.dirname(__file__)) |
735 | - self.assertEqual(set(['libc6']), deps) |
736 | |
737 | === removed file 'pkgme/tests/test_binary_backend.py' |
738 | --- pkgme/tests/test_binary_backend.py 2011-07-18 11:08:14 +0000 |
739 | +++ pkgme/tests/test_binary_backend.py 1970-01-01 00:00:00 +0000 |
740 | @@ -1,117 +0,0 @@ |
741 | -import json |
742 | -import os |
743 | -import shutil |
744 | - |
745 | -from fixtures import TestWithFixtures |
746 | -from testtools import TestCase |
747 | - |
748 | -from pkgme.backend import ExternalHelpersBackend, get_backend_dir |
749 | -from pkgme.binary import ( |
750 | - CATEGORIES, |
751 | - DEPENDS, |
752 | - get_desktop_file, |
753 | - get_install_file, |
754 | - guess_dependencies, |
755 | - METADATA_FILE, |
756 | - PACKAGE_NAME, |
757 | - TAGLINE, |
758 | - ) |
759 | -from pkgme.info_elements import ( |
760 | - BuildDepends, |
761 | - Depends, |
762 | - ExtraFiles, |
763 | - PackageName, |
764 | - ) |
765 | -from pkgme.testing import TempdirFixture |
766 | - |
767 | - |
768 | -BACKEND_NAME = 'binary' |
769 | - |
770 | -backend_dir = get_backend_dir(__file__, BACKEND_NAME) |
771 | - |
772 | - |
773 | -class BinaryBackendTests(TestCase, TestWithFixtures): |
774 | - |
775 | - def test_want_with_metadata(self): |
776 | - # If we detect a binary, then we score 10. The way we determine if |
777 | - # something is a binary is if it has a devportal-metadata.json in its |
778 | - # top-level. |
779 | - tempdir = self.useFixture(TempdirFixture()) |
780 | - tempdir.touch(METADATA_FILE) |
781 | - backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir) |
782 | - self.assertEqual(10, backend.want(tempdir.path)) |
783 | - |
784 | - def test_want_without_metadata(self): |
785 | - # If we do *not* detect a binary, then we score 0. The way we |
786 | - # determine if something is a binary is if it has a |
787 | - # devportal-metadata.json in its top-level. |
788 | - tempdir = self.useFixture(TempdirFixture()) |
789 | - backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir) |
790 | - self.assertEqual(0, backend.want(tempdir.path)) |
791 | - |
792 | - def test_package_name(self): |
793 | - # The binary backend gets the package name from the metadata file. |
794 | - tempdir = self.useFixture(TempdirFixture()) |
795 | - tempdir.create_file(METADATA_FILE, json.dumps({PACKAGE_NAME: 'foo'})) |
796 | - backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir) |
797 | - info = backend.get_info(tempdir.path) |
798 | - self.assertEqual( |
799 | - {PackageName.name: "foo"}, info.get_all([PackageName.name])) |
800 | - |
801 | - def test_build_depends(self): |
802 | - tempdir = self.useFixture(TempdirFixture()) |
803 | - tempdir.create_file(METADATA_FILE, json.dumps({PACKAGE_NAME: 'foo'})) |
804 | - shutil.copy( |
805 | - os.path.join(os.path.dirname(__file__), 'hello'), |
806 | - tempdir.path) |
807 | - backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir) |
808 | - info = backend.get_info(tempdir.path) |
809 | - deps = ', '.join(guess_dependencies(tempdir.path)) |
810 | - self.assertEqual( |
811 | - {BuildDepends.name: deps}, info.get_all([BuildDepends.name])) |
812 | - |
813 | - def test_depends(self): |
814 | - tempdir = self.useFixture(TempdirFixture()) |
815 | - tempdir.create_file(METADATA_FILE, json.dumps({PACKAGE_NAME: 'foo'})) |
816 | - backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir) |
817 | - info = backend.get_info(tempdir.path) |
818 | - self.assertEqual({Depends.name: DEPENDS}, info.get_all([Depends.name])) |
819 | - |
820 | - def test_extra_files_install_file(self): |
821 | - # We create an 'install' file that tells debhelper to just copy |
822 | - # everything to opt. |
823 | - tempdir = self.useFixture(TempdirFixture()) |
824 | - package_name = self.getUniqueString() |
825 | - tempdir.create_file(METADATA_FILE, json.dumps({PACKAGE_NAME: package_name})) |
826 | - backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir) |
827 | - info = backend.get_info(tempdir.path) |
828 | - extra_files = info.get_all([ExtraFiles.name])[ExtraFiles.name] |
829 | - install_file = json.loads(extra_files)['debian/install'] |
830 | - self.assertEqual( |
831 | - get_install_file(package_name, tempdir.path, True), |
832 | - install_file) |
833 | - |
834 | - def test_extra_files_desktop_file(self): |
835 | - # We create an 'install' file that tells debhelper to just copy |
836 | - # everything to opt. |
837 | - tempdir = self.useFixture(TempdirFixture()) |
838 | - package_name = self.getUniqueString() |
839 | - tagline = self.getUniqueString() |
840 | - categories = self.getUniqueString() |
841 | - metadata = { |
842 | - PACKAGE_NAME: package_name, |
843 | - TAGLINE: tagline, |
844 | - CATEGORIES: categories, |
845 | - } |
846 | - tempdir.create_file(METADATA_FILE, json.dumps(metadata)) |
847 | - # We need to create an executable in order to be able to generate a |
848 | - # desktop. |
849 | - tempdir.touch('executable', 0755) |
850 | - expected_desktop_file = get_desktop_file( |
851 | - package_name, tempdir.path, tagline=tagline, |
852 | - categories=categories).get_contents() |
853 | - backend = ExternalHelpersBackend(BACKEND_NAME, backend_dir) |
854 | - info = backend.get_info(tempdir.path) |
855 | - extra_files = info.get_all([ExtraFiles.name])[ExtraFiles.name] |
856 | - desktop = json.loads(extra_files)['debian/%s.desktop' % (package_name,)] |
857 | - self.assertEqual(expected_desktop_file, desktop) |