Merge lp:~mvo/software-center/oem-descriptor-in-user-agent into lp:software-center

Proposed by Michael Vogt
Status: Merged
Merged at revision: 3113
Proposed branch: lp:~mvo/software-center/oem-descriptor-in-user-agent
Merge into: lp:software-center
Diff against target: 221 lines (+89/-16)
8 files modified
softwarecenter/enums.py (+1/-1)
softwarecenter/paths.py (+2/-0)
softwarecenter/ui/gtk3/widgets/webkit.py (+21/-4)
softwarecenter/utils.py (+13/-1)
tests/data/ubuntu_dist_channel (+3/-0)
tests/gtk3/test_purchase.py (+0/-10)
tests/gtk3/test_webkit.py (+44/-0)
tests/test_utils.py (+5/-0)
To merge this branch: bzr merge lp:~mvo/software-center/oem-descriptor-in-user-agent
Reviewer Review Type Date Requested Status
James Westby (community) Approve
software-store-developers Pending
Review via email: mp+120518@code.launchpad.net

Description of the change

Include the oem channel descriptor in the user-agent string

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/enums.py'
2--- softwarecenter/enums.py 2012-08-01 04:26:27 +0000
3+++ softwarecenter/enums.py 2012-08-21 09:13:20 +0000
4@@ -300,7 +300,7 @@
5 PURCHASE_TRANSACTION_ID = "FakePurchaseTransactionID"
6
7 from .version import VERSION, DISTRO, RELEASE, CODENAME
8-USER_AGENT = "Software Center/%s (N;) %s/%s (%s)" % (
9+WEBKIT_USER_AGENT_SUFFIX = "SoftwareCenter/%s %s/%s (%s)" % (
10 VERSION, DISTRO, RELEASE, CODENAME)
11
12 # global backend switch, prefer aptdaemon, if that can not be found, use PK
13
14=== modified file 'softwarecenter/paths.py'
15--- softwarecenter/paths.py 2012-04-12 10:15:36 +0000
16+++ softwarecenter/paths.py 2012-08-21 09:13:20 +0000
17@@ -70,6 +70,8 @@
18 APT_XAPIAN_INDEX_UPDATE_STAMP_PATH = (APT_XAPIAN_INDEX_BASE_PATH +
19 "/update-timestamp")
20
21+# OEM
22+OEM_CHANNEL_DESCRIPTOR = "/var/lib/ubuntu-dist-channel"
23
24 # ratings&review
25 # relative to datadir
26
27=== modified file 'softwarecenter/ui/gtk3/widgets/webkit.py'
28--- softwarecenter/ui/gtk3/widgets/webkit.py 2012-08-14 05:46:18 +0000
29+++ softwarecenter/ui/gtk3/widgets/webkit.py 2012-08-21 09:13:20 +0000
30@@ -27,6 +27,8 @@
31
32 from softwarecenter.i18n import get_language
33 from softwarecenter.paths import SOFTWARE_CENTER_CACHE_DIR
34+from softwarecenter.enums import WEBKIT_USER_AGENT_SUFFIX
35+from softwarecenter.utils import get_oem_channel_descriptor
36
37 from gi.repository import Soup
38 from gi.repository import WebKit
39@@ -70,13 +72,30 @@
40 global_webkit_init()
41
42
43-class LocaleAwareWebView(webkit.WebView):
44+class SoftwareCenterWebView(webkit.WebView):
45+ """ A customized version of the regular webview
46+
47+ It will:
48+ - send Accept-Language headers from the users language
49+ - disable plugings
50+ - send a custom user-agent string
51+ """
52
53 def __init__(self):
54 # actual webkit init
55 webkit.WebView.__init__(self)
56 self.connect("resource-request-starting",
57 self._on_resource_request_starting)
58+ settings = self.get_settings()
59+ settings.set_property("enable-plugins", False)
60+ settings.set_property("user-agent", self._get_user_agent_string())
61+
62+ def _get_user_agent_string(self):
63+ settings = self.get_settings()
64+ user_agent_string = settings.get_property("user-agent")
65+ user_agent_string += " %s " % WEBKIT_USER_AGENT_SUFFIX
66+ user_agent_string += get_oem_channel_descriptor()
67+ return user_agent_string
68
69 def _on_resource_request_starting(self, view, frame, res, req, resp):
70 lang = get_language()
71@@ -95,9 +114,7 @@
72 def __init__(self, include_progress_ui=False):
73 super(ScrolledWebkitWindow, self).__init__()
74 # get webkit
75- self.webkit = LocaleAwareWebView()
76- settings = self.webkit.get_settings()
77- settings.set_property("enable-plugins", False)
78+ self.webkit = SoftwareCenterWebView()
79 # add progress UI if needed
80 if include_progress_ui:
81 self._add_progress_ui()
82
83=== modified file 'softwarecenter/utils.py'
84--- softwarecenter/utils.py 2012-08-16 14:44:29 +0000
85+++ softwarecenter/utils.py 2012-08-21 09:13:20 +0000
86@@ -38,7 +38,10 @@
87 from urlparse import urlsplit
88
89 from enums import Icons, APP_INSTALL_PATH_DELIMITER
90-from paths import SOFTWARE_CENTER_CACHE_DIR
91+from paths import (
92+ SOFTWARE_CENTER_CACHE_DIR,
93+ OEM_CHANNEL_DESCRIPTOR,
94+ )
95
96 from config import get_config
97
98@@ -754,6 +757,15 @@
99 raise
100
101
102+def get_oem_channel_descriptor(path=OEM_CHANNEL_DESCRIPTOR):
103+ """Return the ubuntu distribution channel descriptor or a empty string """
104+ if not os.path.exists(path):
105+ return ""
106+ with open(path) as f:
107+ for line in filter(lambda l: not l.startswith("#"), f):
108+ return line.strip()
109+
110+
111 class SimpleFileDownloader(GObject.GObject):
112
113 LOG = logging.getLogger("softwarecenter.simplefiledownloader")
114
115=== added file 'tests/data/ubuntu_dist_channel'
116--- tests/data/ubuntu_dist_channel 1970-01-01 00:00:00 +0000
117+++ tests/data/ubuntu_dist_channel 2012-08-21 09:13:20 +0000
118@@ -0,0 +1,3 @@
119+# This is a distribution channel descriptor
120+# For more information see http://wiki.ubuntu.com/DistributionChannelDescriptor
121+canonical-oem-watauga-precise-amd64-20120517-2
122
123=== modified file 'tests/gtk3/test_purchase.py'
124--- tests/gtk3/test_purchase.py 2012-08-15 12:00:33 +0000
125+++ tests/gtk3/test_purchase.py 2012-08-21 09:13:20 +0000
126@@ -2,8 +2,6 @@
127
128 from mock import Mock, patch
129
130-from gi.repository import Soup, WebKit
131-
132 from tests.utils import (
133 do_events_with_sleep,
134 get_mock_options,
135@@ -21,14 +19,6 @@
136
137 class TestPurchase(unittest.TestCase):
138
139- def test_have_cookie_jar(self):
140- # ensure we have a cookie jar available
141- session = WebKit.get_default_session()
142- cookie_jars = [feature
143- for feature in session.get_features(Soup.SessionFeature)
144- if isinstance(feature, Soup.CookieJar)]
145- self.assertEqual(len(cookie_jars), 1)
146-
147 def test_purchase_view_log_cleaner(self):
148 win = get_test_window_purchaseview()
149 self.addCleanup(win.destroy)
150
151=== added file 'tests/gtk3/test_webkit.py'
152--- tests/gtk3/test_webkit.py 1970-01-01 00:00:00 +0000
153+++ tests/gtk3/test_webkit.py 2012-08-21 09:13:20 +0000
154@@ -0,0 +1,44 @@
155+import unittest
156+
157+from gi.repository import Soup, WebKit
158+
159+from mock import patch
160+
161+from tests.utils import (
162+ setup_test_env,
163+)
164+setup_test_env()
165+
166+from softwarecenter.enums import WEBKIT_USER_AGENT_SUFFIX
167+from softwarecenter.ui.gtk3.widgets.webkit import SoftwareCenterWebView
168+
169+
170+class TestWebkit(unittest.TestCase):
171+
172+ def test_have_cookie_jar(self):
173+ # ensure we have a cookie jar available
174+ session = WebKit.get_default_session()
175+ cookie_jars = [feature
176+ for feature in session.get_features(Soup.SessionFeature)
177+ if isinstance(feature, Soup.CookieJar)]
178+ self.assertEqual(len(cookie_jars), 1)
179+
180+ def test_user_agent_string(self):
181+ webview = SoftwareCenterWebView()
182+ settings = webview.get_settings()
183+ self.assertTrue(
184+ WEBKIT_USER_AGENT_SUFFIX in settings.get_property("user-agent"))
185+
186+ @patch("softwarecenter.ui.gtk3.widgets.webkit.get_oem_channel_descriptor")
187+ def test_user_agent_oem_channel_descriptor(self, mock_oem_channel):
188+ canary = "she-loves-you-yeah-yeah-yeah"
189+ mock_oem_channel.return_value = canary
190+ webview = SoftwareCenterWebView()
191+ settings = webview.get_settings()
192+ self.assertTrue(
193+ canary in settings.get_property("user-agent"))
194+
195+
196+
197+if __name__ == "__main__":
198+ unittest.main()
199
200=== modified file 'tests/test_utils.py'
201--- tests/test_utils.py 2012-07-19 09:29:16 +0000
202+++ tests/test_utils.py 2012-08-21 09:13:20 +0000
203@@ -31,6 +31,7 @@
204 get_http_proxy_string_from_libproxy,
205 get_http_proxy_string_from_gsettings,
206 get_nice_date_string,
207+ get_oem_channel_descriptor,
208 get_title_from_html,
209 get_uuid,
210 is_no_display_desktop_file,
211@@ -288,6 +289,10 @@
212 # ensure that the second one was not called
213 self.assertEqual(len(glob.glob(os.path.join(tmpdir, "marker.*"))), 1)
214
215+ def test_oem_channel_extractor(self):
216+ s = get_oem_channel_descriptor("./tests/data/ubuntu_dist_channel")
217+ self.assertEqual(s, "canonical-oem-watauga-precise-amd64-20120517-2")
218+
219
220 if __name__ == "__main__":
221 unittest.main()

Subscribers

People subscribed via source and target branches