Merge lp:~pitti/aptdaemon/pkcompat-enhancements into lp:aptdaemon

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
Reviewer Review Type Date Requested Status
Michael Vogt Approve
Review via email: mp+108156@code.launchpad.net

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
Michael Vogt (mvo) wrote :

Looks good to me, thanks pitti.

review: Approve
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 - GetDistroUpgrades
6 - UpgradeSystem
7 - WhatProvides (no builtin handling, only plugins)
8+ - RepoEnable: (only enabling, not disabling)
9
10 Not yet supported roles:
11
12 - GetCategories: Curently groups are still used, would be nice to reuse the
13 categories from software-center
14 - GetRepoList: not implemented in the worker
15- - RepoEnable: not implemented in the worker)
16- - RepoSetData: not implemented in the worker)
17+ - RepoSetData: not implemented in the worker
18 - InstallFiles: not implemented in the worker
19 - SimulateInstallFiles: not implemented in the worker
20 sessioninstaller.
21
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 pk_enums.ROLE_SEARCH_GROUP,
27 pk_enums.ROLE_SEARCH_FILE,
28 pk_enums.ROLE_WHAT_PROVIDES,
29+ pk_enums.ROLE_REPO_ENABLE,
30 pk_enums.ROLE_DOWNLOAD_PACKAGES]
31 if META_RELEASE_SUPPORT:
32 SUPPORTED_ROLES.append(pk_enums.ROLE_GET_DISTRO_UPGRADES)
33@@ -1776,18 +1777,21 @@
34 self.role = pk_enums.ROLE_REPO_SET_DATA
35 GObject.idle_add(self._fail_not_implemented)
36
37- @dbus.service.method(PACKAGEKIT_TRANS_DBUS_INTERFACE,
38- in_signature="sb", out_signature="",
39- sender_keyword="sender")
40+ @dbus_deferred_method(PACKAGEKIT_TRANS_DBUS_INTERFACE,
41+ in_signature="sb", out_signature="",
42+ sender_keyword="sender")
43 def RepoEnable(self, repo_id, enabled, sender):
44 """This method enables the repository specified.
45
46 :param repo_id:
47- A repository identifier, e.g. fedora-development-debuginfo
48+ A repository identifier, e.g. fedora-development-debuginfo or an
49+ apt source ("deb http://... unstable main")
50 :param enabled: true if enabled, false if disabled.
51 """
52 self.role = pk_enums.ROLE_REPO_ENABLE
53- GObject.idle_add(self._fail_not_implemented)
54+ kwargs = {"repo_id": repo_id,
55+ "enabled": enabled}
56+ return self._run_query(kwargs, sender)
57
58 @dbus.service.method(PACKAGEKIT_TRANS_DBUS_INTERFACE,
59 in_signature="s", out_signature="",
60@@ -1981,6 +1985,8 @@
61 self.download_packages(trans, **trans.kwargs)
62 elif trans.pktrans.role == pk_enums.ROLE_WHAT_PROVIDES:
63 self.what_provides(trans, **trans.kwargs)
64+ elif trans.pktrans.role == pk_enums.ROLE_REPO_ENABLE:
65+ self.repo_enable(trans, **trans.kwargs)
66 else:
67 raise TransactionFailed(aptd_enums.ERROR_UNKNOWN,
68 "Role %s isn't supported",
69@@ -2556,10 +2562,7 @@
70 trans.emit_files(id, files)
71
72 def what_provides(self, trans, filters, type, values):
73- """Emit all dependencies of the given package ids.
74-
75- Doesn't support recursive dependency resolution.
76- """
77+ """Emit all packages which provide the given type and search value."""
78 self._init_plugins()
79
80 supported_type = False
81@@ -2580,6 +2583,21 @@
82 raise TransactionFailed(aptd_enums.ERROR_NOT_SUPPORTED,
83 "Query type '%s' is not supported" % type)
84
85+ def repo_enable(self, trans, repo_id, enabled):
86+ """Enable or disable a repository."""
87+
88+ if not enabled:
89+ raise TransactionFailed(aptd_enums.ERROR_NOT_SUPPORTED,
90+ "Disabling repositories is not implemented")
91+
92+ fields = repo_id.split()
93+ if len(fields) < 3 or fields[0] not in ('deb', 'deb-src'):
94+ raise TransactionFailed(aptd_enums.ERROR_NOT_SUPPORTED,
95+ "Unknown repository ID format: %s" % repo_id)
96+
97+ self.add_repository(trans, fields[0], fields[1], fields[2],
98+ fields[3:], '', None)
99+
100
101 # Helpers
102
103
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
109 def test_install(self):
110 """Test installing a package."""
111- self.chroot.add_test_repository()
112 pkg_name = "silly-depend-base"
113
114 client = pk.Client()
115@@ -93,7 +92,6 @@
116
117 def test_download(self):
118 """Test downloading packages."""
119- self.chroot.add_test_repository()
120 pkg_filename = "silly-base_0.1-0update1_all.deb"
121 pkg_id = "silly-base;0.1-0update1;all;"
122 temp_dir = tempfile.mkdtemp(prefix="aptd-download-test-")
123@@ -109,7 +107,6 @@
124
125 def test_get_updates(self):
126 """Test getting updates."""
127- self.chroot.add_test_repository()
128 pkg = "silly-base_0.1-0_all.deb"
129 self.chroot.install_debfile(os.path.join(REPO_PATH, pkg), True)
130
131@@ -129,7 +126,6 @@
132
133 def test_get_updates_security(self):
134 """Test if security updates are detected correctly."""
135- self.chroot.add_test_repository()
136 self.chroot.add_repository(os.path.join(aptdaemon.test.get_tests_dir(),
137 "repo/security"))
138 pkg = "silly-base_0.1-0_all.deb"
139@@ -318,6 +314,79 @@
140 self.assertTrue("plasma" in str(e), e)
141 self.assertTrue("not supported" in str(e), e)
142
143+ def test_repo_enable(self):
144+ """Test adding a repository."""
145+ client = pk.Client()
146+
147+ # create test update repo
148+ repo = tempfile.mkdtemp()
149+ self.addCleanup(shutil.rmtree, repo)
150+ with open(os.path.join(repo, 'Packages'), 'w') as f:
151+ f.write('''Package: silly-new
152+Priority: extra
153+Section: admin
154+Installed-Size: 44
155+Maintainer: Sebastian Heinlein <devel@glatzor.de>
156+Architecture: all
157+Source: silly-new (0.1-0)
158+Version: 1.2.3
159+Filename: %s/silly-base_0.1-0update1_all.deb
160+Size: 1934
161+MD5sum: 8e20af56a63a1e0cf40db3b0d07e7989
162+SHA1: 7ce87423d9c7a734478c464021994944d07fbf1b
163+SHA256: d3693c0e3e7a9519b2833fdf1301c7e03e0620edf15b95b4c7329d9eb0bee553
164+Description: new package from a third-party repo
165+''' % self.chroot.path)
166+
167+ # without the new repo, we do not have it yet
168+ self.assertRaises(GLib.GError, client.resolve, pk.FilterEnum.NONE,
169+ ['silly-new'], None, lambda p, t, d: True, None)
170+
171+ # now add the new repo
172+ apt_source = 'deb file://%s /' % repo
173+ res = client.repo_enable(apt_source, True, None,
174+ lambda p, t, d: True, None)
175+ self.assertEqual(res.get_exit_code(), pk.ExitEnum.SUCCESS)
176+
177+ with open(os.path.join(self.chroot.path, 'etc', 'apt', 'sources.list')) as f:
178+ for line in f:
179+ if line.strip() == apt_source:
180+ break
181+ else:
182+ self.fail('did not find newly added repository in sources.list')
183+
184+ # should not actually download the indexes yet
185+ self.assertRaises(GLib.GError, client.resolve, pk.FilterEnum.NONE,
186+ ['silly-new'], None, lambda p, t, d: True, None)
187+
188+ res = client.refresh_cache(False, None, lambda p, t, d: True, None)
189+ self.assertEqual(res.get_exit_code(), pk.ExitEnum.SUCCESS)
190+
191+ # we should now see the new package
192+ res = client.resolve(pk.FilterEnum.NONE, ['silly-new'], None,
193+ lambda p, t, d: True, None)
194+ self.assertEqual(res.get_exit_code(), pk.ExitEnum.SUCCESS)
195+ packages = res.get_package_array()
196+ self.assertEqual(len(packages), 1)
197+ self.assertEqual(packages[0].get_name(), "silly-new")
198+ self.assertEqual(packages[0].get_version(), "1.2.3")
199+ self.assertEqual(packages[0].get_info(), pk.info_enum_from_string("available"))
200+
201+ def test_repo_enable_errors(self):
202+ """Test errors when adding a repository."""
203+ client = pk.Client()
204+
205+ try:
206+ client.repo_enable('bogus', True, None, lambda p, t, d: True, None)
207+ except GLib.GError as e:
208+ self.assertTrue('format' in str(e))
209+ self.assertTrue('bogus' in str(e))
210+
211+ try:
212+ client.repo_enable('deb http://example.com', True, None, lambda p, t, d: True, None)
213+ except GLib.GError as e:
214+ self.assertTrue('format' in str(e), e)
215+ self.assertTrue('http://example.com' in str(e), e)
216
217 @unittest.skipIf(sys.version_info.major < 3, "Python3 only")
218 def setUp():

Subscribers

People subscribed via source and target branches

to status/vote changes: