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
=== modified file 'djlibdep/api.py'
--- djlibdep/api.py 2012-10-17 14:14:57 +0000
+++ djlibdep/api.py 2012-10-29 12:19:42 +0000
@@ -32,6 +32,24 @@
32 return deps32 return deps
3333
3434
35def insert_packages(db, libs):
36 """Update the database with package mappings from ``libs``.
37
38 :param db: A ``PackageDatabase`` object.
39 :param libs: An iterable of ``(package, library, architecture)``.
40 """
41 # XXX: Can change this to insert multiple rows at once.
42 for package, library, architecture in libs:
43 db.insert_new_library(package, library, package, architecture)
44
45
46def update_packages(db, architecture, libs):
47 db._store.execute(
48 'DELETE FROM libdep WHERE architecture = ?', (unicode(architecture),))
49 insert_packages(
50 db, ((package, library, architecture) for (package, library) in libs))
51
52
35def get_summary():53def get_summary():
36 db = get_dependency_database()54 db = get_dependency_database()
37 return {55 return {
3856
=== modified file 'djlibdep/aptfile.py'
--- djlibdep/aptfile.py 2012-10-26 15:27:18 +0000
+++ djlibdep/aptfile.py 2012-10-29 12:19:42 +0000
@@ -21,6 +21,13 @@
2121
22from fixtures import TempDir22from fixtures import TempDir
2323
24from .api import update_packages
25
26
27SUPPORTED_ARCHITECTURES = ['i386', 'amd64']
28DEFAULT_ARCHIVE = 'http://archive.ubuntu.com/ubuntu'
29DEFAULT_SUITE = 'oneiric'
30
2431
25def get_contents_url(archive, suite, architecture):32def get_contents_url(archive, suite, architecture):
26 """Get the URL for a contents file.33 """Get the URL for a contents file.
@@ -150,3 +157,14 @@
150 with gzip.open(contents_path, 'r') as contents:157 with gzip.open(contents_path, 'r') as contents:
151 for package, library in iter_libraries_in_contents(contents):158 for package, library in iter_libraries_in_contents(contents):
152 yield package, library159 yield package, library
160
161
162def update_from_contents(db, archive, suite, architecture):
163 """Update the database with Contents from an archive."""
164 update_packages(
165 db, architecture, iter_library_packages(archive, suite, architecture))
166
167
168def update_database(db):
169 for architecture in SUPPORTED_ARCHITECTURES:
170 update_from_contents(db, DEFAULT_ARCHIVE, DEFAULT_SUITE, architecture)
153171
=== modified file 'djlibdep/tests/test_api.py'
--- djlibdep/tests/test_api.py 2012-10-12 14:32:39 +0000
+++ djlibdep/tests/test_api.py 2012-10-29 12:19:42 +0000
@@ -22,6 +22,8 @@
22 get_total_rows,22 get_total_rows,
23 get_unique_libraries,23 get_unique_libraries,
24 get_unique_dependencies,24 get_unique_dependencies,
25 insert_packages,
26 update_packages,
25 )27 )
26from .helpers import (28from .helpers import (
27 populate_sample_data,29 populate_sample_data,
@@ -71,6 +73,41 @@
71 self.assertEqual({'unknown': {}}, result)73 self.assertEqual({'unknown': {}}, result)
7274
7375
76class TestDatabaseInsert(TestCase, WithDatabase):
77
78 def test_single_entry(self):
79 db = self.get_package_db()
80 insert_packages(db, [('libfoo', 'libfoo.so.1', 'i386')])
81 result = get_binaries_for_libraries(db, ['libfoo.so.1'], ['i386'])
82 self.assertEqual({'i386': {'libfoo.so.1': ['libfoo']}}, result)
83
84 def test_multiple_entries(self):
85 db = self.get_package_db()
86 insert_packages(
87 db, [('libfoo', 'libfoo.so.1', 'i386'),
88 ('libbar', 'libfoo.so.1', 'i386'),
89 ])
90 result = get_binaries_for_libraries(db, ['libfoo.so.1'], ['i386'])
91 self.assertEqual(
92 {'i386': {'libfoo.so.1': ['libbar', 'libfoo']}}, result)
93
94
95class TestDatabaseUpdate(TestCase, WithDatabase):
96
97 def test_nothing_there(self):
98 db = self.get_package_db()
99 update_packages(db, 'i386', [('libfoo', 'libfoo.so.1')])
100 result = get_binaries_for_libraries(db, ['libfoo.so.1'], ['i386'])
101 self.assertEqual({'i386': {'libfoo.so.1': ['libfoo']}}, result)
102
103 def test_overrides(self):
104 db = self.get_package_db()
105 update_packages(db, 'i386', [('libfoo', 'libfoo.so.1')])
106 update_packages(db, 'i386', [('libbar', 'libfoo.so.1')])
107 result = get_binaries_for_libraries(db, ['libfoo.so.1'], ['i386'])
108 self.assertEqual({'i386': {'libfoo.so.1': ['libbar']}}, result)
109
110
74SAMPLE_DATA = [111SAMPLE_DATA = [
75 ('libfoo-bin', {'i386': {'libfoo': 'libfoo-bin'}}),112 ('libfoo-bin', {'i386': {'libfoo': 'libfoo-bin'}}),
76 ('libbar-bin', {'i386': {'libbar': 'libbar-bin'}}),113 ('libbar-bin', {'i386': {'libbar': 'libbar-bin'}}),

Subscribers

People subscribed via source and target branches