Merge lp:~jml/libdep-service/update-apt-file into lp:libdep-service

Proposed by Jonathan Lange
Status: Merged
Approved by: James Westby
Approved revision: 76
Merged at revision: 72
Proposed branch: lp:~jml/libdep-service/update-apt-file
Merge into: lp:libdep-service
Diff against target: 116 lines (+73/-0)
3 files modified
djlibdep/api.py (+18/-0)
djlibdep/aptfile.py (+18/-0)
djlibdep/tests/test_api.py (+37/-0)
To merge this branch: bzr merge lp:~jml/libdep-service/update-apt-file
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Review via email: mp+131887@code.launchpad.net

Commit message

Simplistic approach to updating the database

Description of the change

Simplistic approach to updating the database.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Looks good.

Thanks,

James

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'djlibdep/api.py'
2--- djlibdep/api.py 2012-10-17 14:14:57 +0000
3+++ djlibdep/api.py 2012-10-29 12:19:42 +0000
4@@ -32,6 +32,24 @@
5 return deps
6
7
8+def insert_packages(db, libs):
9+ """Update the database with package mappings from ``libs``.
10+
11+ :param db: A ``PackageDatabase`` object.
12+ :param libs: An iterable of ``(package, library, architecture)``.
13+ """
14+ # XXX: Can change this to insert multiple rows at once.
15+ for package, library, architecture in libs:
16+ db.insert_new_library(package, library, package, architecture)
17+
18+
19+def update_packages(db, architecture, libs):
20+ db._store.execute(
21+ 'DELETE FROM libdep WHERE architecture = ?', (unicode(architecture),))
22+ insert_packages(
23+ db, ((package, library, architecture) for (package, library) in libs))
24+
25+
26 def get_summary():
27 db = get_dependency_database()
28 return {
29
30=== modified file 'djlibdep/aptfile.py'
31--- djlibdep/aptfile.py 2012-10-26 15:27:18 +0000
32+++ djlibdep/aptfile.py 2012-10-29 12:19:42 +0000
33@@ -21,6 +21,13 @@
34
35 from fixtures import TempDir
36
37+from .api import update_packages
38+
39+
40+SUPPORTED_ARCHITECTURES = ['i386', 'amd64']
41+DEFAULT_ARCHIVE = 'http://archive.ubuntu.com/ubuntu'
42+DEFAULT_SUITE = 'oneiric'
43+
44
45 def get_contents_url(archive, suite, architecture):
46 """Get the URL for a contents file.
47@@ -150,3 +157,14 @@
48 with gzip.open(contents_path, 'r') as contents:
49 for package, library in iter_libraries_in_contents(contents):
50 yield package, library
51+
52+
53+def update_from_contents(db, archive, suite, architecture):
54+ """Update the database with Contents from an archive."""
55+ update_packages(
56+ db, architecture, iter_library_packages(archive, suite, architecture))
57+
58+
59+def update_database(db):
60+ for architecture in SUPPORTED_ARCHITECTURES:
61+ update_from_contents(db, DEFAULT_ARCHIVE, DEFAULT_SUITE, architecture)
62
63=== modified file 'djlibdep/tests/test_api.py'
64--- djlibdep/tests/test_api.py 2012-10-12 14:32:39 +0000
65+++ djlibdep/tests/test_api.py 2012-10-29 12:19:42 +0000
66@@ -22,6 +22,8 @@
67 get_total_rows,
68 get_unique_libraries,
69 get_unique_dependencies,
70+ insert_packages,
71+ update_packages,
72 )
73 from .helpers import (
74 populate_sample_data,
75@@ -71,6 +73,41 @@
76 self.assertEqual({'unknown': {}}, result)
77
78
79+class TestDatabaseInsert(TestCase, WithDatabase):
80+
81+ def test_single_entry(self):
82+ db = self.get_package_db()
83+ insert_packages(db, [('libfoo', 'libfoo.so.1', 'i386')])
84+ result = get_binaries_for_libraries(db, ['libfoo.so.1'], ['i386'])
85+ self.assertEqual({'i386': {'libfoo.so.1': ['libfoo']}}, result)
86+
87+ def test_multiple_entries(self):
88+ db = self.get_package_db()
89+ insert_packages(
90+ db, [('libfoo', 'libfoo.so.1', 'i386'),
91+ ('libbar', 'libfoo.so.1', 'i386'),
92+ ])
93+ result = get_binaries_for_libraries(db, ['libfoo.so.1'], ['i386'])
94+ self.assertEqual(
95+ {'i386': {'libfoo.so.1': ['libbar', 'libfoo']}}, result)
96+
97+
98+class TestDatabaseUpdate(TestCase, WithDatabase):
99+
100+ def test_nothing_there(self):
101+ db = self.get_package_db()
102+ update_packages(db, 'i386', [('libfoo', 'libfoo.so.1')])
103+ result = get_binaries_for_libraries(db, ['libfoo.so.1'], ['i386'])
104+ self.assertEqual({'i386': {'libfoo.so.1': ['libfoo']}}, result)
105+
106+ def test_overrides(self):
107+ db = self.get_package_db()
108+ update_packages(db, 'i386', [('libfoo', 'libfoo.so.1')])
109+ update_packages(db, 'i386', [('libbar', 'libfoo.so.1')])
110+ result = get_binaries_for_libraries(db, ['libfoo.so.1'], ['i386'])
111+ self.assertEqual({'i386': {'libfoo.so.1': ['libbar']}}, result)
112+
113+
114 SAMPLE_DATA = [
115 ('libfoo-bin', {'i386': {'libfoo': 'libfoo-bin'}}),
116 ('libbar-bin', {'i386': {'libbar': 'libbar-bin'}}),

Subscribers

People subscribed via source and target branches