Merge lp:~mvo/software-center/system-wide-license-key-fixes into lp:software-center

Proposed by Michael Vogt
Status: Merged
Merged at revision: 2570
Proposed branch: lp:~mvo/software-center/system-wide-license-key-fixes
Merge into: lp:software-center
Diff against target: 279 lines (+71/-21)
8 files modified
debian/control (+1/-0)
softwarecenter/backend/installbackend_impl/aptd.py (+17/-8)
softwarecenter/db/application.py (+2/-0)
softwarecenter/ui/gtk3/app.py (+3/-0)
softwarecenter/ui/gtk3/session/appmanager.py (+6/-1)
softwarecenter/ui/gtk3/views/purchaseview.py (+9/-1)
softwarecenter/version.py (+2/-2)
test/test_aptd.py (+31/-9)
To merge this branch: bzr merge lp:~mvo/software-center/system-wide-license-key-fixes
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Michael Vogt Pending
Review via email: mp+83323@code.launchpad.net

Description of the change

This branch adds support for installing system-wide license keys via aptdaemon.

To post a comment you must log in.
Revision history for this message
Gary Lasker (gary-lasker) wrote :

Hi mvo, this looks fine to me, very nice! I did notice that version.py is bumped, but that may be on purpose for the new RELEASE value?

I tested using the unit test only, and expect that we will get thorough testing with the server-side by QA very soon after we get this merged.

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2011-11-07 10:04:33 +0000
3+++ debian/control 2011-11-24 16:27:53 +0000
4@@ -23,6 +23,7 @@
5 ${misc:Depends},
6 app-install-data (>= 0.4.0),
7 aptdaemon (>= 0.40),
8+ software-center-aptdaemon-plugins,
9 humanity-icon-theme|gnome-icon-theme,
10 gir1.2-glib-2.0 (>= 1.31),
11 gir1.2-gtk-3.0,
12
13=== modified file 'softwarecenter/backend/installbackend_impl/aptd.py'
14--- softwarecenter/backend/installbackend_impl/aptd.py 2011-09-29 18:26:52 +0000
15+++ softwarecenter/backend/installbackend_impl/aptd.py 2011-11-24 16:27:53 +0000
16@@ -450,10 +450,8 @@
17 yield policykit1.check_authorization_by_name(name, action, flags=flags)
18
19 @inline_callbacks
20- def add_license_key(self, license_key, license_key_path, pkgname):
21- """ add a license key for a purchase. Note that currently only
22- system wide license keys are supported.
23- """
24+ def add_license_key(self, license_key, license_key_path, license_key_oauth, pkgname):
25+ """ add a license key for a purchase. """
26 self._logger.debug(
27 "adding license_key for pkg '%s' of len: %i" % (
28 pkgname, len(license_key)))
29@@ -475,11 +473,13 @@
30 else:
31 # system-wide keys
32 try:
33+ self._logger.info("adding license key for '%s'" % pkgname)
34+ server = "ubuntu-production"
35 trans = yield self.aptd_client.add_license_key(
36- license_key, pkgname)
37+ pkgname, license_key_oauth, server)
38 yield self._run_transaction(trans, None, None, None)
39 except Exception as e:
40- self._logger.error("add_repository: '%s'" % e)
41+ self._logger.error("add_license_key: '%s'" % e)
42
43 @inline_callbacks
44 def add_repo_add_key_and_install_app(self,
45@@ -489,6 +489,7 @@
46 iconname,
47 license_key,
48 license_key_path,
49+ json_oauth_token=None,
50 purchase=True):
51 """
52 a convenience method that combines all of the steps needed
53@@ -531,6 +532,7 @@
54 'sc_add_repo_and_install_try' : "1",
55 'sc_add_repo_and_install_license_key' : license_key or "",
56 'sc_add_repo_and_install_license_key_path' : license_key_path or "",
57+ 'sc_add_repo_and_install_license_key_token' : json_oauth_token or "",
58 }
59
60 self._logger.info("add_sources_list_entry()")
61@@ -593,6 +595,7 @@
62 deb_line = trans.meta_data["sc_add_repo_and_install_deb_line"]
63 license_key = trans.meta_data["sc_add_repo_and_install_license_key"]
64 license_key_path = trans.meta_data["sc_add_repo_and_install_license_key_path"]
65+ license_key_oauth = trans.meta_data["sc_add_repo_and_install_license_key_token"]
66 release_filename = release_filename_in_lists_from_deb_line(deb_line)
67 lists_dir = apt_pkg.config.find_dir("Dir::State::lists")
68 release_signature = os.path.join(lists_dir, release_filename)+".gpg"
69@@ -626,10 +629,16 @@
70 self._logger.info("run_transaction()")
71 yield self._run_transaction(trans, app.pkgname, app.appname,
72 "", metadata)
73- if license_key:
74- yield self.add_license_key(license_key, license_key_path, app.pkgname)
75 except Exception as error:
76 self._on_trans_error(error, app.pkgname)
77+ # add license_key
78+ # FIXME: aptd fails if there is a license_key_path already
79+ # but I wonder if we should ease that restriction
80+ if license_key and not os.path.exists(license_key_path):
81+ res = yield self.add_license_key(
82+ license_key, license_key_path, license_key_oauth,
83+ app.pkgname)
84+
85 else:
86 # download failure
87 # ok, here is the fun! we can not reload() immediately, because
88
89=== modified file 'softwarecenter/db/application.py'
90--- softwarecenter/db/application.py 2011-11-13 09:21:58 +0000
91+++ softwarecenter/db/application.py 2011-11-24 16:27:53 +0000
92@@ -669,6 +669,8 @@
93 details.append(" installation_date: %s" % self.installation_date)
94 details.append(" purchase_date: %s" % self.purchase_date)
95 details.append(" license: %s" % self.license)
96+ details.append(" license_key: %s" % self.license_key[0:3] + len(license_key)*"*")
97+ details.append(" license_key_path: %s" % self.license_key_path)
98 details.append(" maintenance_status: %s" % self.maintenance_status)
99 details.append(" pkg_state: %s" % self.pkg_state)
100 details.append(" price: %s" % self.price)
101
102=== modified file 'softwarecenter/ui/gtk3/app.py'
103--- softwarecenter/ui/gtk3/app.py 2011-11-09 10:35:09 +0000
104+++ softwarecenter/ui/gtk3/app.py 2011-11-24 16:27:53 +0000
105@@ -552,6 +552,9 @@
106
107 def _on_sso_login(self, sso, oauth_result):
108 self._sso_login_successful = True
109+ # appmanager needs to know about the oauth token for the reinstall
110+ # previous purchases add_license_key call
111+ self.app_manager.oauth_token = oauth_result
112 # consumer key is the openid identifier
113 self.scagent.query_available_for_me(oauth_result["token"],
114 oauth_result["consumer_key"])
115
116=== modified file 'softwarecenter/ui/gtk3/session/appmanager.py'
117--- softwarecenter/ui/gtk3/session/appmanager.py 2011-11-09 10:35:09 +0000
118+++ softwarecenter/ui/gtk3/session/appmanager.py 2011-11-24 16:27:53 +0000
119@@ -16,6 +16,8 @@
120 # this program; if not, write to the Free Software Foundation, Inc.,
121 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
122
123+import json
124+
125 try:
126 from urllib.parse import urlencode
127 urlencode # pyflakes
128@@ -55,6 +57,7 @@
129 self.distro = get_distro()
130 self.datadir = softwarecenter.paths.datadir
131 self.icons = icons
132+ self.oauth_token = ""
133
134 def _globalise_instance(self):
135 global _appmanager
136@@ -162,12 +165,14 @@
137 license_key = appdetails.license_key
138 license_key_path = appdetails.license_key_path
139 signing_key_id = appdetails.signing_key_id
140+ oauth_token = json.dumps(self.oauth_token)
141 self.backend.add_repo_add_key_and_install_app(deb_line,
142 signing_key_id,
143 app,
144 iconname,
145 license_key,
146- license_key_path)
147+ license_key_path,
148+ oauth_token)
149
150 def enable_software_source(self, app):
151 """ enable the software source for the given app """
152
153=== modified file 'softwarecenter/ui/gtk3/views/purchaseview.py'
154--- softwarecenter/ui/gtk3/views/purchaseview.py 2011-11-22 08:28:29 +0000
155+++ softwarecenter/ui/gtk3/views/purchaseview.py 2011-11-24 16:27:53 +0000
156@@ -125,6 +125,7 @@
157 GObject.GObject.__init__(self)
158 self.wk = None
159 self._wk_handlers_blocked = False
160+ self._oauth_token = None
161
162 def init_view(self):
163 if self.wk is None:
164@@ -188,6 +189,13 @@
165 return wk.webkit
166
167 def _on_console_message(self, view, message, line, source_id):
168+ try:
169+ # load the token from the console message
170+ self._oauth_token = json.loads(message)
171+ # compat with the regular oauth naming
172+ self._oauth_token["token"] = self._oauth_token["token_key"]
173+ except ValueError:
174+ pass
175 for k in ["token_key", "token_secret", "consumer_secret"]:
176 if k in message:
177 LOG.debug("skipping console message that contains sensitive data")
178@@ -256,7 +264,7 @@
179 backend = get_install_backend()
180 backend.add_repo_add_key_and_install_app(
181 deb_line, signing_key_id, self.app, self.iconname,
182- license_key, license_key_path)
183+ license_key, license_key_path, json.dumps(self._oauth_token))
184
185 def _block_wk_handlers(self):
186 # we need to block webkit signal handlers when we hide the
187
188=== modified file 'softwarecenter/version.py'
189--- softwarecenter/version.py 2011-11-07 09:41:23 +0000
190+++ softwarecenter/version.py 2011-11-24 16:27:53 +0000
191@@ -1,5 +1,5 @@
192
193-VERSION='5.1.1'
194+VERSION='5.1.2'
195 CODENAME='UNRELEASED'
196 DISTRO='Ubuntu'
197-RELEASE='11.10'
198+RELEASE='12.04'
199
200=== modified file 'test/test_aptd.py'
201--- test/test_aptd.py 2011-09-29 18:16:38 +0000
202+++ test/test_aptd.py 2011-11-24 16:27:53 +0000
203@@ -2,12 +2,16 @@
204
205 import os
206 import sys
207+import time
208 import unittest
209
210
211 sys.path.insert(0,"../")
212 from softwarecenter.backend.installbackend_impl.aptd import AptdaemonBackend
213 from defer import inline_callbacks
214+from mock import Mock
215+
216+import aptdaemon.loop
217
218 class TestAptdaemon(unittest.TestCase):
219 """ tests the AptdaemonBackend """
220@@ -27,23 +31,39 @@
221 # test HOME
222 target = "~/.fasfasdfsdafdfsdafdsfa"
223 pkgname = "2vcard"
224- yield self.aptd.add_license_key(data, target, pkgname)
225+ json_auth = ""
226+ yield self.aptd.add_license_key(data, target, json_auth, pkgname)
227 self.assertEqual(open(os.path.expanduser(target)).read(), data)
228 # ensure its not written twice
229 data2 = "other-data"
230- yield self.aptd.add_license_key(data2, target, pkgname)
231+ yield self.aptd.add_license_key(data2, target, json_auth, pkgname)
232 self.assertEqual(open(os.path.expanduser(target)).read(), data)
233 # cleanup
234 os.remove(os.path.expanduser(target))
235
236- # disabled until aptdaemon support is merged
237- def disabled_test_add_license_key_opt(self):
238+ def test_add_license_key_opt(self):
239+ if os.getuid() != 0:
240+ logging.info("skipping add_license_key_opt test")
241+ return
242 # test /opt
243 data = "some-data"
244- pkgname = "2vcard"
245- path = "/opt"
246- defer = self.aptd.add_license_key(data, path, pkgname)
247- self.assertTrue(defer.called)
248+ pkgname = "hellox"
249+ path = "/opt/hellox/conf/license-key.txt"
250+ json_auth = os.environ.get("SC_TEST_JSON") or "no-json-auth"
251+ def _error(*args):
252+ print "errror", args
253+ self.aptd.ui = Mock()
254+ self.aptd.ui.error = _error
255+ @inline_callbacks
256+ def run():
257+ res = yield self.aptd.add_license_key(data, path, json_auth, pkgname)
258+ aptdaemon.loop.mainloop.quit()
259+ # run the callback
260+ run()
261+ aptdaemon.loop.mainloop.run()
262+ # give the daemon time to write the file
263+ time.sleep(0.5)
264+ self.assertTrue(os.path.exists(path))
265 #self.assertEqual(open(os.path.expanduser(target)).read(), data)
266 #os.remove(os.path.expanduser(target))
267
268@@ -60,8 +80,10 @@
269 self.assertEqual(self._pkgs_to_install, ["7zip", "2vcard"])
270 self._pkgs_to_install = []
271
272- def _monkey_patched_add_vendor_key_from_keyserver(self, keyid, *args):
273+ def _monkey_patched_add_vendor_key_from_keyserver(self, keyid,
274+ *args, **kwargs):
275 self.assertTrue(keyid.startswith("0x"))
276+ return Mock()
277
278 def test_download_key_from_keyserver(self):
279 keyid = "0EB12F05"

Subscribers

People subscribed via source and target branches