Merge lp:~dholbach/software-center/software-center-aptdaemon-plugins into lp:software-center

Proposed by Daniel Holbach
Status: Rejected
Rejected by: Kiwinote
Proposed branch: lp:~dholbach/software-center/software-center-aptdaemon-plugins
Merge into: lp:software-center
Diff against target: 349 lines (+299/-0) (has conflicts)
9 files modified
debian/changelog (+60/-0)
debian/compat (+1/-0)
debian/control (+26/-0)
debian/copyright (+16/-0)
debian/dirs (+1/-0)
debian/rules (+32/-0)
helper/ubuntu-license-key-helper (+88/-0)
setup.py (+14/-0)
softwarecenter_aptd_plugins/add_license_key_plugin.py (+61/-0)
Conflict adding file setup.py.  Moved existing file to setup.py.moved.
To merge this branch: bzr merge lp:~dholbach/software-center/software-center-aptdaemon-plugins
Reviewer Review Type Date Requested Status
software-store-developers Pending
Review via email: mp+162729@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Kiwinote (kiwinote) wrote :

merged into lp:~software-store-developers/software-center/software-center-aptdaemon-plugins - thanks!

(this merge proposal has the wrong target branch, so I'll set it as 'rejected' to close it, but the changes themselves are fine)

Unmerged revisions

19. By Daniel Holbach

debian/control: fix typo in description (LP: #1175101)

18. By Michael Vogt

releasing version 0.1.5

17. By Michael Vogt

build a utils/ubuntu-license-key-helper as a python2 binary
as there is no python3-piston-mini-client yet

16. By Michael Vogt

depend on python3-piston-mini-client

15. By Michael Vogt

add dependency for piston-mini-client

14. By Michael Vogt

fix helper location

13. By Michael Vogt

releasing version 0.1.3

12. By Michael Vogt

build for python3

11. By Michael Vogt

Open subprocesses with universal_newlines=True when expecting to read
text from them. On Python 2, this only enables \r\n conversion and the
like, but on Python 3 this also causes subprocess-related file objects
to read str rather than bytes.

10. By Michael Vogt

releasing version 0.1.2

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'debian'
2=== added file 'debian/changelog'
3--- debian/changelog 1970-01-01 00:00:00 +0000
4+++ debian/changelog 2013-05-07 08:35:35 +0000
5@@ -0,0 +1,60 @@
6+software-center-aptdaemon-plugins (0.1.6) saucy; urgency=low
7+
8+ * debian/control: fix typo in description (LP: #1175101)
9+
10+ -- Paolo Rotolo <paolo@curiosity> Sun, 05 May 2013 11:24:31 +0200
11+
12+software-center-aptdaemon-plugins (0.1.5) quantal; urgency=low
13+
14+ * build a utils/ubuntu-license-key-helper as a python2 binary
15+ as there is no python3-piston-mini-client yet (LP: #1052703)
16+
17+ -- Michael Vogt <michael.vogt@ubuntu.com> Tue, 25 Sep 2012 10:18:54 +0200
18+
19+software-center-aptdaemon-plugins (0.1.4) quantal; urgency=low
20+
21+ * fix helper location
22+ * add dependency for piston-mini-client
23+
24+ -- Michael Vogt <michael.vogt@ubuntu.com> Mon, 24 Sep 2012 15:02:11 +0200
25+
26+software-center-aptdaemon-plugins (0.1.3) quantal; urgency=low
27+
28+ * Open subprocesses with universal_newlines=True when expecting to read
29+ text from them. On Python 2, this only enables \r\n conversion and the
30+ like, but on Python 3 this also causes subprocess-related file objects
31+ to read str rather than bytes.
32+ * build for python3
33+
34+ -- Michael Vogt <michael.vogt@ubuntu.com> Fri, 24 Aug 2012 10:43:32 +0200
35+
36+software-center-aptdaemon-plugins (0.1.2) precise; urgency=low
37+
38+ [ Michael Vogt ]
39+ * helper/ubuntu-license-key-helper:
40+ - extra paranoia when iterating the license-key data
41+
42+ [ Martin Pitt ]
43+ * debian/control: Fix Vcs-Bzr: location.
44+ * softwarecenter_aptd_plugins/add_license_key_plugin.py: Port to
45+ gobject-introspection, to work with aptdaemon versions that use GI.
46+ * debian/control: Add python-gi/gir dependency and Breaks: aptdaemon
47+ (<< 0.43+bzr760), the upstream GI port commit.
48+
49+ -- Michael Vogt <michael.vogt@ubuntu.com> Fri, 03 Feb 2012 10:12:54 +0100
50+
51+software-center-aptdaemon-plugins (0.1.1) precise; urgency=low
52+
53+ * helper/ubuntu-license-key-helper:
54+ - honor SOFTWARE_CENTER_BUY_HOST
55+ * bug fixes
56+
57+ -- Michael Vogt <michael.vogt@ubuntu.com> Thu, 24 Nov 2011 15:13:38 +0100
58+
59+software-center-aptdaemon-plugins (0.1) precise; urgency=low
60+
61+ * Initial release, this is a helper for software-center to allow
62+ system-wide license-key installs
63+
64+ -- Michael Vogt <michael.vogt@ubuntu.com> Mon, 21 Nov 2011 12:13:55 +0100
65+
66
67=== added file 'debian/compat'
68--- debian/compat 1970-01-01 00:00:00 +0000
69+++ debian/compat 2013-05-07 08:35:35 +0000
70@@ -0,0 +1,1 @@
71+8
72
73=== added file 'debian/control'
74--- debian/control 1970-01-01 00:00:00 +0000
75+++ debian/control 2013-05-07 08:35:35 +0000
76@@ -0,0 +1,26 @@
77+Source: software-center-aptdaemon-plugins
78+Section: gnome
79+Priority: optional
80+Maintainer: Michael Vogt <mvo@ubuntu.com>
81+Build-Depends: debhelper (>= 8.0),
82+ python3-setuptools,
83+ python3-all,
84+ python-all,
85+ python-setuptools,
86+Standards-Version: 3.8.4
87+X-Python3-Version: >= 3.2
88+X-Python-Version: >= 2.7
89+Vcs-Bzr: https://code.launchpad.net/~software-store-developers/software-center/software-center-aptdaemon-plugins
90+
91+Package: software-center-aptdaemon-plugins
92+Architecture: all
93+Depends: ${python:Depends},
94+ ${misc:Depends},
95+ python3-gi,
96+ gir1.2-glib-2.0,
97+ python-piston-mini-client
98+Breaks: aptdaemon (<< 0.43+bzr760)
99+Description: The aptdaemon plugins for software-center
100+ This package contains the plugins of software-center that enhance the
101+ functionality of aptdaemon. This includes the ability to install
102+ systemwide license keys.
103
104=== added file 'debian/copyright'
105--- debian/copyright 1970-01-01 00:00:00 +0000
106+++ debian/copyright 2013-05-07 08:35:35 +0000
107@@ -0,0 +1,16 @@
108+Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?rev=59
109+Source: https://edge.launchpad.net/software-center-aptdaemon-plugins
110+
111+Files: *
112+Copyright: © 2011 Canonical
113+ © 2011 Sebastian Heinlein <glatzor@ubuntu.com>
114+License: GPL-3
115+
116+License: GPL-3
117+ This package is free software; you can redistribute it and/or modify
118+ it under the terms of the GNU General Public License as published by
119+ the Free Software Foundation; version 3.
120+ .
121+ On Debian systems, the complete text of the GNU General
122+ Public License can be found in `/usr/share/common-licenses/GPL-3'.
123+
124
125=== added file 'debian/dirs'
126--- debian/dirs 1970-01-01 00:00:00 +0000
127+++ debian/dirs 2013-05-07 08:35:35 +0000
128@@ -0,0 +1,1 @@
129+usr/share/software-center
130\ No newline at end of file
131
132=== added file 'debian/rules'
133--- debian/rules 1970-01-01 00:00:00 +0000
134+++ debian/rules 2013-05-07 08:35:35 +0000
135@@ -0,0 +1,32 @@
136+#!/usr/bin/make -f
137+share:=usr/share/software-center
138+
139+#export DH_VERBOSE=1
140+
141+PY3REQUESTED := $(shell py3versions -r)
142+PY3DEFAULT := $(shell py3versions -d)
143+# Run setup.py with the default python3 last so that the scripts use
144+# #!/usr/bin/python3 and not #!/usr/bin/python3.X.
145+PY3 := $(filter-out $(PY3DEFAULT),$(PY3REQUESTED)) python3
146+
147+%:
148+ dh $@ --with=python2,python3
149+
150+override_dh_auto_build:
151+ # this will build py2
152+ dh_auto_build
153+ # ... and this py3
154+ set -ex; for python in $(PY3); do \
155+ $$python setup.py build; \
156+ done
157+
158+override_dh_auto_install:
159+ # do the py3 dance
160+ set -ex; for python in $(PY3); do \
161+ $$python setup.py install --root=$(CURDIR)/debian/software-center-aptdaemon-plugins --install-layout=deb; \
162+ done
163+ # run the normal dh_auto_install which will copy the binary
164+ # ubuntu-license-key-helper into /usr/bin and not mangle it to py3
165+ dh_auto_install
166+ # Move the scripts to $(SHARE)
167+ mv $(CURDIR)/debian/software-center-aptdaemon-plugins/usr/*bin/* debian/software-center-aptdaemon-plugins/$(share)
168
169=== added directory 'helper'
170=== added file 'helper/ubuntu-license-key-helper'
171--- helper/ubuntu-license-key-helper 1970-01-01 00:00:00 +0000
172+++ helper/ubuntu-license-key-helper 2013-05-07 08:35:35 +0000
173@@ -0,0 +1,88 @@
174+#!/usr/bin/python
175+
176+import logging
177+import json
178+from optparse import OptionParser
179+import os
180+import sys
181+
182+sys.path.insert(0, "/usr/share/software-center")
183+from softwarecenter.backend.piston.scaclient import SoftwareCenterAgentAPI
184+import piston_mini_client.auth
185+
186+import gettext
187+gettext.install("aptdaemon")
188+
189+if __name__ == "__main__":
190+
191+ parser = OptionParser()
192+ parser.add_option("-s", "--server", default="ubuntu-production")
193+ parser.add_option("-p", "--pkgname")
194+ (options, args) = parser.parse_args()
195+
196+ # server to use
197+ if options.server == "ubuntu-production":
198+ server = "https://software-center.ubuntu.com"
199+ elif options.server == "ubuntu-staging":
200+ server = "https://sc.staging.ubuntu.com"
201+ else:
202+ raise Exception("Unknown license key server")
203+
204+ # allow override via environment, note that in order for this to
205+ # work aptdaemon needs to be started with that environment
206+ if os.environ.get("SOFTWARE_CENTER_BUY_HOST"):
207+ server = os.environ.get("SOFTWARE_CENTER_BUY_HOST")
208+ logging.warn("overriding server from environment: '%s'" % server)
209+
210+ # setup server root
211+ server += "/api/2.0"
212+ SoftwareCenterAgentAPI.default_service_root = server
213+
214+ # pkgname
215+ pkgname = options.pkgname
216+
217+ # wait for oauth token on stdin
218+ json_token = sys.stdin.readline()
219+ token = json.loads(json_token)
220+
221+ # get the data
222+ auth = piston_mini_client.auth.OAuthAuthorizer(token["token"],
223+ token["token_secret"],
224+ token["consumer_key"],
225+ token["consumer_secret"])
226+
227+ api = SoftwareCenterAgentAPI(auth=auth)
228+
229+
230+ try:
231+ subscriptions = api.subscriptions_for_me(complete_only=True)
232+ except piston_mini_client.APIError as e:
233+ sys.stderr.write(_("Failed to get the license key from "
234+ "the server."))
235+ sys.exit(1)
236+
237+ # find the right pkg
238+ license_key = None
239+ license_key_path = None
240+ for subscription in subscriptions:
241+ # paranoia, check if we actually have a license key attr too
242+ if (subscription.application["package_name"] == pkgname and
243+ hasattr(subscription, "license_key")):
244+ license_key = subscription.license_key
245+ license_key_path = subscription.license_key_path
246+ break
247+
248+ if license_key and license_key_path:
249+ # aptdaemon expects a absolute path, fix that up
250+ if not license_key_path.startswith("/"):
251+ license_key_path = os.path.join("/opt", pkgname, license_key_path)
252+
253+ sys.stdout.write(license_key_path + "\n")
254+ sys.stdout.write(license_key)
255+ sys.exit(0)
256+
257+ # generic error
258+ sys.stderr.write(_("Failed to get the license key from "
259+ "the server."))
260+ sys.exit(1)
261+
262
263=== added file 'setup.py'
264--- setup.py 1970-01-01 00:00:00 +0000
265+++ setup.py 2013-05-07 08:35:35 +0000
266@@ -0,0 +1,14 @@
267+#!/usr/bin/env python
268+
269+from setuptools import setup
270+
271+
272+setup(name="software-center-aptd-plugins",
273+ packages=['softwarecenter_aptd_plugins',
274+ ],
275+ scripts=["helper/ubuntu-license-key-helper",
276+ ],
277+ entry_points="""[aptdaemon.plugins]
278+get_license_key=softwarecenter_aptd_plugins.add_license_key_plugin:get_license_key
279+ """,
280+ )
281
282=== renamed file 'setup.py' => 'setup.py.moved'
283=== added directory 'softwarecenter_aptd_plugins'
284=== added file 'softwarecenter_aptd_plugins/__init__.py'
285=== added file 'softwarecenter_aptd_plugins/add_license_key_plugin.py'
286--- softwarecenter_aptd_plugins/add_license_key_plugin.py 1970-01-01 00:00:00 +0000
287+++ softwarecenter_aptd_plugins/add_license_key_plugin.py 2013-05-07 08:35:35 +0000
288@@ -0,0 +1,61 @@
289+#!/usr/bin/env python
290+# -*- coding: utf-8 -*-
291+"""Provides plugins for AptDaemon"""
292+# Copyright (C) 2011 Canonical Ltd.
293+#
294+# This program is free software; you can redistribute it and/or modify
295+# it under the terms of the GNU General Public License as published by
296+# the Free Software Foundation; either version 2 of the License, or
297+# any later version.
298+#
299+# This program is distributed in the hope that it will be useful,
300+# but WITHOUT ANY WARRANTY; without even the implied warranty of
301+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
302+# GNU General Public License for more details.
303+#
304+# You should have received a copy of the GNU General Public License along
305+# with this program; if not, write to the Free Software Foundation, Inc.,
306+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
307+
308+__author__ = "Sebastian Heinlein <devel@glatzor.de>"
309+
310+import apt_pkg
311+import os
312+import subprocess
313+import time
314+
315+from gi.repository import GLib
316+
317+from aptdaemon.errors import TransactionFailed
318+from aptdaemon.enums import ERROR_LICENSE_KEY_DOWNLOAD_FAILED
319+
320+
321+def get_license_key(uid, pkg_name, json_token, server_name):
322+ """Return the license key and the path for the given package."""
323+ rootdir = apt_pkg.config["Dir"]
324+ license_key_helper = os.path.join(rootdir, "usr/share/software-center/ubuntu-license-key-helper")
325+ cmd = [license_key_helper, "--server", server_name, "--pkgname", pkg_name]
326+ proc = subprocess.Popen(cmd, stdin=subprocess.PIPE,
327+ stderr=subprocess.PIPE,
328+ stdout=subprocess.PIPE,
329+ preexec_fn=lambda: os.setuid(uid),
330+ close_fds=True,
331+ # this will give us str in py3 instead of bytes
332+ universal_newlines=True)
333+ # send json token to the process
334+ proc.stdin.write(json_token + "\n")
335+ # wait until it finishes
336+ while proc.poll() is None:
337+ while GLib.main_context_default().pending():
338+ GLib.main_context_default().iteration()
339+ time.sleep(0.05)
340+
341+ if proc.returncode != 0:
342+ stderr = proc.stderr.read()
343+ raise TransactionFailed(ERROR_LICENSE_KEY_DOWNLOAD_FAILED, stderr)
344+
345+ # get data from stdout
346+ license_key_path = proc.stdout.readline().strip()
347+ license_key = proc.stdout.read()
348+
349+ return license_key, license_key_path