Merge lp:~pitti/aptdaemon/pkcompat-enhancements into lp:aptdaemon
- pkcompat-enhancements
- Merge into main
Proposed by
Martin Pitt
Status: | Merged |
---|---|
Merged at revision: | 823 |
Proposed branch: | lp:~pitti/aptdaemon/pkcompat-enhancements |
Merge into: | lp:aptdaemon |
Diff against target: |
218 lines (+102/-15) 3 files modified
README.PackageKit (+2/-2) aptdaemon/pkcompat.py (+27/-9) tests/test_pk.py (+73/-4) |
To merge this branch: | bzr merge lp:~pitti/aptdaemon/pkcompat-enhancements |
Related bugs: | |
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Vogt | Approve | ||
Review via email: mp+108156@code.launchpad.net |
Commit message
Description of the change
Implement RepoEnable() for enable==True.
It does not yet implement removing a repository (enable==False), as that is
more tricky to do.
To post a comment you must log in.
Revision history for this message
Martin Pitt (pitti) wrote : | # |
Pushed to trunk, thanks!
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'README.PackageKit' | |||
2 | --- README.PackageKit 2012-05-31 09:36:38 +0000 | |||
3 | +++ README.PackageKit 2012-05-31 13:11:18 +0000 | |||
4 | @@ -51,14 +51,14 @@ | |||
5 | 51 | - GetDistroUpgrades | 51 | - GetDistroUpgrades |
6 | 52 | - UpgradeSystem | 52 | - UpgradeSystem |
7 | 53 | - WhatProvides (no builtin handling, only plugins) | 53 | - WhatProvides (no builtin handling, only plugins) |
8 | 54 | - RepoEnable: (only enabling, not disabling) | ||
9 | 54 | 55 | ||
10 | 55 | Not yet supported roles: | 56 | Not yet supported roles: |
11 | 56 | 57 | ||
12 | 57 | - GetCategories: Curently groups are still used, would be nice to reuse the | 58 | - GetCategories: Curently groups are still used, would be nice to reuse the |
13 | 58 | categories from software-center | 59 | categories from software-center |
14 | 59 | - GetRepoList: not implemented in the worker | 60 | - GetRepoList: not implemented in the worker |
17 | 60 | - RepoEnable: not implemented in the worker) | 61 | - RepoSetData: not implemented in the worker |
16 | 61 | - RepoSetData: not implemented in the worker) | ||
18 | 62 | - InstallFiles: not implemented in the worker | 62 | - InstallFiles: not implemented in the worker |
19 | 63 | - SimulateInstallFiles: not implemented in the worker | 63 | - SimulateInstallFiles: not implemented in the worker |
20 | 64 | sessioninstaller. | 64 | sessioninstaller. |
21 | 65 | 65 | ||
22 | === modified file 'aptdaemon/pkcompat.py' | |||
23 | --- aptdaemon/pkcompat.py 2012-05-13 02:22:25 +0000 | |||
24 | +++ aptdaemon/pkcompat.py 2012-05-31 13:11:18 +0000 | |||
25 | @@ -262,6 +262,7 @@ | |||
26 | 262 | pk_enums.ROLE_SEARCH_GROUP, | 262 | pk_enums.ROLE_SEARCH_GROUP, |
27 | 263 | pk_enums.ROLE_SEARCH_FILE, | 263 | pk_enums.ROLE_SEARCH_FILE, |
28 | 264 | pk_enums.ROLE_WHAT_PROVIDES, | 264 | pk_enums.ROLE_WHAT_PROVIDES, |
29 | 265 | pk_enums.ROLE_REPO_ENABLE, | ||
30 | 265 | pk_enums.ROLE_DOWNLOAD_PACKAGES] | 266 | pk_enums.ROLE_DOWNLOAD_PACKAGES] |
31 | 266 | if META_RELEASE_SUPPORT: | 267 | if META_RELEASE_SUPPORT: |
32 | 267 | SUPPORTED_ROLES.append(pk_enums.ROLE_GET_DISTRO_UPGRADES) | 268 | SUPPORTED_ROLES.append(pk_enums.ROLE_GET_DISTRO_UPGRADES) |
33 | @@ -1776,18 +1777,21 @@ | |||
34 | 1776 | self.role = pk_enums.ROLE_REPO_SET_DATA | 1777 | self.role = pk_enums.ROLE_REPO_SET_DATA |
35 | 1777 | GObject.idle_add(self._fail_not_implemented) | 1778 | GObject.idle_add(self._fail_not_implemented) |
36 | 1778 | 1779 | ||
40 | 1779 | @dbus.service.method(PACKAGEKIT_TRANS_DBUS_INTERFACE, | 1780 | @dbus_deferred_method(PACKAGEKIT_TRANS_DBUS_INTERFACE, |
41 | 1780 | in_signature="sb", out_signature="", | 1781 | in_signature="sb", out_signature="", |
42 | 1781 | sender_keyword="sender") | 1782 | sender_keyword="sender") |
43 | 1782 | def RepoEnable(self, repo_id, enabled, sender): | 1783 | def RepoEnable(self, repo_id, enabled, sender): |
44 | 1783 | """This method enables the repository specified. | 1784 | """This method enables the repository specified. |
45 | 1784 | 1785 | ||
46 | 1785 | :param repo_id: | 1786 | :param repo_id: |
48 | 1786 | A repository identifier, e.g. fedora-development-debuginfo | 1787 | A repository identifier, e.g. fedora-development-debuginfo or an |
49 | 1788 | apt source ("deb http://... unstable main") | ||
50 | 1787 | :param enabled: true if enabled, false if disabled. | 1789 | :param enabled: true if enabled, false if disabled. |
51 | 1788 | """ | 1790 | """ |
52 | 1789 | self.role = pk_enums.ROLE_REPO_ENABLE | 1791 | self.role = pk_enums.ROLE_REPO_ENABLE |
54 | 1790 | GObject.idle_add(self._fail_not_implemented) | 1792 | kwargs = {"repo_id": repo_id, |
55 | 1793 | "enabled": enabled} | ||
56 | 1794 | return self._run_query(kwargs, sender) | ||
57 | 1791 | 1795 | ||
58 | 1792 | @dbus.service.method(PACKAGEKIT_TRANS_DBUS_INTERFACE, | 1796 | @dbus.service.method(PACKAGEKIT_TRANS_DBUS_INTERFACE, |
59 | 1793 | in_signature="s", out_signature="", | 1797 | in_signature="s", out_signature="", |
60 | @@ -1981,6 +1985,8 @@ | |||
61 | 1981 | self.download_packages(trans, **trans.kwargs) | 1985 | self.download_packages(trans, **trans.kwargs) |
62 | 1982 | elif trans.pktrans.role == pk_enums.ROLE_WHAT_PROVIDES: | 1986 | elif trans.pktrans.role == pk_enums.ROLE_WHAT_PROVIDES: |
63 | 1983 | self.what_provides(trans, **trans.kwargs) | 1987 | self.what_provides(trans, **trans.kwargs) |
64 | 1988 | elif trans.pktrans.role == pk_enums.ROLE_REPO_ENABLE: | ||
65 | 1989 | self.repo_enable(trans, **trans.kwargs) | ||
66 | 1984 | else: | 1990 | else: |
67 | 1985 | raise TransactionFailed(aptd_enums.ERROR_UNKNOWN, | 1991 | raise TransactionFailed(aptd_enums.ERROR_UNKNOWN, |
68 | 1986 | "Role %s isn't supported", | 1992 | "Role %s isn't supported", |
69 | @@ -2556,10 +2562,7 @@ | |||
70 | 2556 | trans.emit_files(id, files) | 2562 | trans.emit_files(id, files) |
71 | 2557 | 2563 | ||
72 | 2558 | def what_provides(self, trans, filters, type, values): | 2564 | def what_provides(self, trans, filters, type, values): |
77 | 2559 | """Emit all dependencies of the given package ids. | 2565 | """Emit all packages which provide the given type and search value.""" |
74 | 2560 | |||
75 | 2561 | Doesn't support recursive dependency resolution. | ||
76 | 2562 | """ | ||
78 | 2563 | self._init_plugins() | 2566 | self._init_plugins() |
79 | 2564 | 2567 | ||
80 | 2565 | supported_type = False | 2568 | supported_type = False |
81 | @@ -2580,6 +2583,21 @@ | |||
82 | 2580 | raise TransactionFailed(aptd_enums.ERROR_NOT_SUPPORTED, | 2583 | raise TransactionFailed(aptd_enums.ERROR_NOT_SUPPORTED, |
83 | 2581 | "Query type '%s' is not supported" % type) | 2584 | "Query type '%s' is not supported" % type) |
84 | 2582 | 2585 | ||
85 | 2586 | def repo_enable(self, trans, repo_id, enabled): | ||
86 | 2587 | """Enable or disable a repository.""" | ||
87 | 2588 | |||
88 | 2589 | if not enabled: | ||
89 | 2590 | raise TransactionFailed(aptd_enums.ERROR_NOT_SUPPORTED, | ||
90 | 2591 | "Disabling repositories is not implemented") | ||
91 | 2592 | |||
92 | 2593 | fields = repo_id.split() | ||
93 | 2594 | if len(fields) < 3 or fields[0] not in ('deb', 'deb-src'): | ||
94 | 2595 | raise TransactionFailed(aptd_enums.ERROR_NOT_SUPPORTED, | ||
95 | 2596 | "Unknown repository ID format: %s" % repo_id) | ||
96 | 2597 | |||
97 | 2598 | self.add_repository(trans, fields[0], fields[1], fields[2], | ||
98 | 2599 | fields[3:], '', None) | ||
99 | 2600 | |||
100 | 2583 | 2601 | ||
101 | 2584 | # Helpers | 2602 | # Helpers |
102 | 2585 | 2603 | ||
103 | 2586 | 2604 | ||
104 | === modified file 'tests/test_pk.py' | |||
105 | --- tests/test_pk.py 2012-05-12 16:04:00 +0000 | |||
106 | +++ tests/test_pk.py 2012-05-31 13:11:18 +0000 | |||
107 | @@ -57,7 +57,6 @@ | |||
108 | 57 | 57 | ||
109 | 58 | def test_install(self): | 58 | def test_install(self): |
110 | 59 | """Test installing a package.""" | 59 | """Test installing a package.""" |
111 | 60 | self.chroot.add_test_repository() | ||
112 | 61 | pkg_name = "silly-depend-base" | 60 | pkg_name = "silly-depend-base" |
113 | 62 | 61 | ||
114 | 63 | client = pk.Client() | 62 | client = pk.Client() |
115 | @@ -93,7 +92,6 @@ | |||
116 | 93 | 92 | ||
117 | 94 | def test_download(self): | 93 | def test_download(self): |
118 | 95 | """Test downloading packages.""" | 94 | """Test downloading packages.""" |
119 | 96 | self.chroot.add_test_repository() | ||
120 | 97 | pkg_filename = "silly-base_0.1-0update1_all.deb" | 95 | pkg_filename = "silly-base_0.1-0update1_all.deb" |
121 | 98 | pkg_id = "silly-base;0.1-0update1;all;" | 96 | pkg_id = "silly-base;0.1-0update1;all;" |
122 | 99 | temp_dir = tempfile.mkdtemp(prefix="aptd-download-test-") | 97 | temp_dir = tempfile.mkdtemp(prefix="aptd-download-test-") |
123 | @@ -109,7 +107,6 @@ | |||
124 | 109 | 107 | ||
125 | 110 | def test_get_updates(self): | 108 | def test_get_updates(self): |
126 | 111 | """Test getting updates.""" | 109 | """Test getting updates.""" |
127 | 112 | self.chroot.add_test_repository() | ||
128 | 113 | pkg = "silly-base_0.1-0_all.deb" | 110 | pkg = "silly-base_0.1-0_all.deb" |
129 | 114 | self.chroot.install_debfile(os.path.join(REPO_PATH, pkg), True) | 111 | self.chroot.install_debfile(os.path.join(REPO_PATH, pkg), True) |
130 | 115 | 112 | ||
131 | @@ -129,7 +126,6 @@ | |||
132 | 129 | 126 | ||
133 | 130 | def test_get_updates_security(self): | 127 | def test_get_updates_security(self): |
134 | 131 | """Test if security updates are detected correctly.""" | 128 | """Test if security updates are detected correctly.""" |
135 | 132 | self.chroot.add_test_repository() | ||
136 | 133 | self.chroot.add_repository(os.path.join(aptdaemon.test.get_tests_dir(), | 129 | self.chroot.add_repository(os.path.join(aptdaemon.test.get_tests_dir(), |
137 | 134 | "repo/security")) | 130 | "repo/security")) |
138 | 135 | pkg = "silly-base_0.1-0_all.deb" | 131 | pkg = "silly-base_0.1-0_all.deb" |
139 | @@ -318,6 +314,79 @@ | |||
140 | 318 | self.assertTrue("plasma" in str(e), e) | 314 | self.assertTrue("plasma" in str(e), e) |
141 | 319 | self.assertTrue("not supported" in str(e), e) | 315 | self.assertTrue("not supported" in str(e), e) |
142 | 320 | 316 | ||
143 | 317 | def test_repo_enable(self): | ||
144 | 318 | """Test adding a repository.""" | ||
145 | 319 | client = pk.Client() | ||
146 | 320 | |||
147 | 321 | # create test update repo | ||
148 | 322 | repo = tempfile.mkdtemp() | ||
149 | 323 | self.addCleanup(shutil.rmtree, repo) | ||
150 | 324 | with open(os.path.join(repo, 'Packages'), 'w') as f: | ||
151 | 325 | f.write('''Package: silly-new | ||
152 | 326 | Priority: extra | ||
153 | 327 | Section: admin | ||
154 | 328 | Installed-Size: 44 | ||
155 | 329 | Maintainer: Sebastian Heinlein <devel@glatzor.de> | ||
156 | 330 | Architecture: all | ||
157 | 331 | Source: silly-new (0.1-0) | ||
158 | 332 | Version: 1.2.3 | ||
159 | 333 | Filename: %s/silly-base_0.1-0update1_all.deb | ||
160 | 334 | Size: 1934 | ||
161 | 335 | MD5sum: 8e20af56a63a1e0cf40db3b0d07e7989 | ||
162 | 336 | SHA1: 7ce87423d9c7a734478c464021994944d07fbf1b | ||
163 | 337 | SHA256: d3693c0e3e7a9519b2833fdf1301c7e03e0620edf15b95b4c7329d9eb0bee553 | ||
164 | 338 | Description: new package from a third-party repo | ||
165 | 339 | ''' % self.chroot.path) | ||
166 | 340 | |||
167 | 341 | # without the new repo, we do not have it yet | ||
168 | 342 | self.assertRaises(GLib.GError, client.resolve, pk.FilterEnum.NONE, | ||
169 | 343 | ['silly-new'], None, lambda p, t, d: True, None) | ||
170 | 344 | |||
171 | 345 | # now add the new repo | ||
172 | 346 | apt_source = 'deb file://%s /' % repo | ||
173 | 347 | res = client.repo_enable(apt_source, True, None, | ||
174 | 348 | lambda p, t, d: True, None) | ||
175 | 349 | self.assertEqual(res.get_exit_code(), pk.ExitEnum.SUCCESS) | ||
176 | 350 | |||
177 | 351 | with open(os.path.join(self.chroot.path, 'etc', 'apt', 'sources.list')) as f: | ||
178 | 352 | for line in f: | ||
179 | 353 | if line.strip() == apt_source: | ||
180 | 354 | break | ||
181 | 355 | else: | ||
182 | 356 | self.fail('did not find newly added repository in sources.list') | ||
183 | 357 | |||
184 | 358 | # should not actually download the indexes yet | ||
185 | 359 | self.assertRaises(GLib.GError, client.resolve, pk.FilterEnum.NONE, | ||
186 | 360 | ['silly-new'], None, lambda p, t, d: True, None) | ||
187 | 361 | |||
188 | 362 | res = client.refresh_cache(False, None, lambda p, t, d: True, None) | ||
189 | 363 | self.assertEqual(res.get_exit_code(), pk.ExitEnum.SUCCESS) | ||
190 | 364 | |||
191 | 365 | # we should now see the new package | ||
192 | 366 | res = client.resolve(pk.FilterEnum.NONE, ['silly-new'], None, | ||
193 | 367 | lambda p, t, d: True, None) | ||
194 | 368 | self.assertEqual(res.get_exit_code(), pk.ExitEnum.SUCCESS) | ||
195 | 369 | packages = res.get_package_array() | ||
196 | 370 | self.assertEqual(len(packages), 1) | ||
197 | 371 | self.assertEqual(packages[0].get_name(), "silly-new") | ||
198 | 372 | self.assertEqual(packages[0].get_version(), "1.2.3") | ||
199 | 373 | self.assertEqual(packages[0].get_info(), pk.info_enum_from_string("available")) | ||
200 | 374 | |||
201 | 375 | def test_repo_enable_errors(self): | ||
202 | 376 | """Test errors when adding a repository.""" | ||
203 | 377 | client = pk.Client() | ||
204 | 378 | |||
205 | 379 | try: | ||
206 | 380 | client.repo_enable('bogus', True, None, lambda p, t, d: True, None) | ||
207 | 381 | except GLib.GError as e: | ||
208 | 382 | self.assertTrue('format' in str(e)) | ||
209 | 383 | self.assertTrue('bogus' in str(e)) | ||
210 | 384 | |||
211 | 385 | try: | ||
212 | 386 | client.repo_enable('deb http://example.com', True, None, lambda p, t, d: True, None) | ||
213 | 387 | except GLib.GError as e: | ||
214 | 388 | self.assertTrue('format' in str(e), e) | ||
215 | 389 | self.assertTrue('http://example.com' in str(e), e) | ||
216 | 321 | 390 | ||
217 | 322 | @unittest.skipIf(sys.version_info.major < 3, "Python3 only") | 391 | @unittest.skipIf(sys.version_info.major < 3, "Python3 only") |
218 | 323 | def setUp(): | 392 | def setUp(): |
Looks good to me, thanks pitti.