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
=== modified file 'softwarecenter/enums.py'
--- softwarecenter/enums.py 2012-08-01 04:26:27 +0000
+++ softwarecenter/enums.py 2012-08-21 09:13:20 +0000
@@ -300,7 +300,7 @@
300PURCHASE_TRANSACTION_ID = "FakePurchaseTransactionID"300PURCHASE_TRANSACTION_ID = "FakePurchaseTransactionID"
301301
302from .version import VERSION, DISTRO, RELEASE, CODENAME302from .version import VERSION, DISTRO, RELEASE, CODENAME
303USER_AGENT = "Software Center/%s (N;) %s/%s (%s)" % (303WEBKIT_USER_AGENT_SUFFIX = "SoftwareCenter/%s %s/%s (%s)" % (
304 VERSION, DISTRO, RELEASE, CODENAME)304 VERSION, DISTRO, RELEASE, CODENAME)
305305
306# global backend switch, prefer aptdaemon, if that can not be found, use PK306# global backend switch, prefer aptdaemon, if that can not be found, use PK
307307
=== modified file 'softwarecenter/paths.py'
--- softwarecenter/paths.py 2012-04-12 10:15:36 +0000
+++ softwarecenter/paths.py 2012-08-21 09:13:20 +0000
@@ -70,6 +70,8 @@
70APT_XAPIAN_INDEX_UPDATE_STAMP_PATH = (APT_XAPIAN_INDEX_BASE_PATH +70APT_XAPIAN_INDEX_UPDATE_STAMP_PATH = (APT_XAPIAN_INDEX_BASE_PATH +
71 "/update-timestamp")71 "/update-timestamp")
7272
73# OEM
74OEM_CHANNEL_DESCRIPTOR = "/var/lib/ubuntu-dist-channel"
7375
74# ratings&review76# ratings&review
75# relative to datadir77# relative to datadir
7678
=== modified file 'softwarecenter/ui/gtk3/widgets/webkit.py'
--- softwarecenter/ui/gtk3/widgets/webkit.py 2012-08-14 05:46:18 +0000
+++ softwarecenter/ui/gtk3/widgets/webkit.py 2012-08-21 09:13:20 +0000
@@ -27,6 +27,8 @@
2727
28from softwarecenter.i18n import get_language28from softwarecenter.i18n import get_language
29from softwarecenter.paths import SOFTWARE_CENTER_CACHE_DIR29from softwarecenter.paths import SOFTWARE_CENTER_CACHE_DIR
30from softwarecenter.enums import WEBKIT_USER_AGENT_SUFFIX
31from softwarecenter.utils import get_oem_channel_descriptor
3032
31from gi.repository import Soup33from gi.repository import Soup
32from gi.repository import WebKit34from gi.repository import WebKit
@@ -70,13 +72,30 @@
70global_webkit_init()72global_webkit_init()
7173
7274
73class LocaleAwareWebView(webkit.WebView):75class SoftwareCenterWebView(webkit.WebView):
76 """ A customized version of the regular webview
77
78 It will:
79 - send Accept-Language headers from the users language
80 - disable plugings
81 - send a custom user-agent string
82 """
7483
75 def __init__(self):84 def __init__(self):
76 # actual webkit init85 # actual webkit init
77 webkit.WebView.__init__(self)86 webkit.WebView.__init__(self)
78 self.connect("resource-request-starting",87 self.connect("resource-request-starting",
79 self._on_resource_request_starting)88 self._on_resource_request_starting)
89 settings = self.get_settings()
90 settings.set_property("enable-plugins", False)
91 settings.set_property("user-agent", self._get_user_agent_string())
92
93 def _get_user_agent_string(self):
94 settings = self.get_settings()
95 user_agent_string = settings.get_property("user-agent")
96 user_agent_string += " %s " % WEBKIT_USER_AGENT_SUFFIX
97 user_agent_string += get_oem_channel_descriptor()
98 return user_agent_string
8099
81 def _on_resource_request_starting(self, view, frame, res, req, resp):100 def _on_resource_request_starting(self, view, frame, res, req, resp):
82 lang = get_language()101 lang = get_language()
@@ -95,9 +114,7 @@
95 def __init__(self, include_progress_ui=False):114 def __init__(self, include_progress_ui=False):
96 super(ScrolledWebkitWindow, self).__init__()115 super(ScrolledWebkitWindow, self).__init__()
97 # get webkit116 # get webkit
98 self.webkit = LocaleAwareWebView()117 self.webkit = SoftwareCenterWebView()
99 settings = self.webkit.get_settings()
100 settings.set_property("enable-plugins", False)
101 # add progress UI if needed118 # add progress UI if needed
102 if include_progress_ui:119 if include_progress_ui:
103 self._add_progress_ui()120 self._add_progress_ui()
104121
=== modified file 'softwarecenter/utils.py'
--- softwarecenter/utils.py 2012-08-16 14:44:29 +0000
+++ softwarecenter/utils.py 2012-08-21 09:13:20 +0000
@@ -38,7 +38,10 @@
38 from urlparse import urlsplit38 from urlparse import urlsplit
3939
40from enums import Icons, APP_INSTALL_PATH_DELIMITER40from enums import Icons, APP_INSTALL_PATH_DELIMITER
41from paths import SOFTWARE_CENTER_CACHE_DIR41from paths import (
42 SOFTWARE_CENTER_CACHE_DIR,
43 OEM_CHANNEL_DESCRIPTOR,
44 )
4245
43from config import get_config46from config import get_config
4447
@@ -754,6 +757,15 @@
754 raise757 raise
755758
756759
760def get_oem_channel_descriptor(path=OEM_CHANNEL_DESCRIPTOR):
761 """Return the ubuntu distribution channel descriptor or a empty string """
762 if not os.path.exists(path):
763 return ""
764 with open(path) as f:
765 for line in filter(lambda l: not l.startswith("#"), f):
766 return line.strip()
767
768
757class SimpleFileDownloader(GObject.GObject):769class SimpleFileDownloader(GObject.GObject):
758770
759 LOG = logging.getLogger("softwarecenter.simplefiledownloader")771 LOG = logging.getLogger("softwarecenter.simplefiledownloader")
760772
=== added file 'tests/data/ubuntu_dist_channel'
--- tests/data/ubuntu_dist_channel 1970-01-01 00:00:00 +0000
+++ tests/data/ubuntu_dist_channel 2012-08-21 09:13:20 +0000
@@ -0,0 +1,3 @@
1# This is a distribution channel descriptor
2# For more information see http://wiki.ubuntu.com/DistributionChannelDescriptor
3canonical-oem-watauga-precise-amd64-20120517-2
04
=== modified file 'tests/gtk3/test_purchase.py'
--- tests/gtk3/test_purchase.py 2012-08-15 12:00:33 +0000
+++ tests/gtk3/test_purchase.py 2012-08-21 09:13:20 +0000
@@ -2,8 +2,6 @@
22
3from mock import Mock, patch3from mock import Mock, patch
44
5from gi.repository import Soup, WebKit
6
7from tests.utils import (5from tests.utils import (
8 do_events_with_sleep,6 do_events_with_sleep,
9 get_mock_options,7 get_mock_options,
@@ -21,14 +19,6 @@
2119
22class TestPurchase(unittest.TestCase):20class TestPurchase(unittest.TestCase):
2321
24 def test_have_cookie_jar(self):
25 # ensure we have a cookie jar available
26 session = WebKit.get_default_session()
27 cookie_jars = [feature
28 for feature in session.get_features(Soup.SessionFeature)
29 if isinstance(feature, Soup.CookieJar)]
30 self.assertEqual(len(cookie_jars), 1)
31
32 def test_purchase_view_log_cleaner(self):22 def test_purchase_view_log_cleaner(self):
33 win = get_test_window_purchaseview()23 win = get_test_window_purchaseview()
34 self.addCleanup(win.destroy)24 self.addCleanup(win.destroy)
3525
=== added file 'tests/gtk3/test_webkit.py'
--- tests/gtk3/test_webkit.py 1970-01-01 00:00:00 +0000
+++ tests/gtk3/test_webkit.py 2012-08-21 09:13:20 +0000
@@ -0,0 +1,44 @@
1import unittest
2
3from gi.repository import Soup, WebKit
4
5from mock import patch
6
7from tests.utils import (
8 setup_test_env,
9)
10setup_test_env()
11
12from softwarecenter.enums import WEBKIT_USER_AGENT_SUFFIX
13from softwarecenter.ui.gtk3.widgets.webkit import SoftwareCenterWebView
14
15
16class TestWebkit(unittest.TestCase):
17
18 def test_have_cookie_jar(self):
19 # ensure we have a cookie jar available
20 session = WebKit.get_default_session()
21 cookie_jars = [feature
22 for feature in session.get_features(Soup.SessionFeature)
23 if isinstance(feature, Soup.CookieJar)]
24 self.assertEqual(len(cookie_jars), 1)
25
26 def test_user_agent_string(self):
27 webview = SoftwareCenterWebView()
28 settings = webview.get_settings()
29 self.assertTrue(
30 WEBKIT_USER_AGENT_SUFFIX in settings.get_property("user-agent"))
31
32 @patch("softwarecenter.ui.gtk3.widgets.webkit.get_oem_channel_descriptor")
33 def test_user_agent_oem_channel_descriptor(self, mock_oem_channel):
34 canary = "she-loves-you-yeah-yeah-yeah"
35 mock_oem_channel.return_value = canary
36 webview = SoftwareCenterWebView()
37 settings = webview.get_settings()
38 self.assertTrue(
39 canary in settings.get_property("user-agent"))
40
41
42
43if __name__ == "__main__":
44 unittest.main()
045
=== modified file 'tests/test_utils.py'
--- tests/test_utils.py 2012-07-19 09:29:16 +0000
+++ tests/test_utils.py 2012-08-21 09:13:20 +0000
@@ -31,6 +31,7 @@
31 get_http_proxy_string_from_libproxy,31 get_http_proxy_string_from_libproxy,
32 get_http_proxy_string_from_gsettings,32 get_http_proxy_string_from_gsettings,
33 get_nice_date_string,33 get_nice_date_string,
34 get_oem_channel_descriptor,
34 get_title_from_html,35 get_title_from_html,
35 get_uuid,36 get_uuid,
36 is_no_display_desktop_file,37 is_no_display_desktop_file,
@@ -288,6 +289,10 @@
288 # ensure that the second one was not called289 # ensure that the second one was not called
289 self.assertEqual(len(glob.glob(os.path.join(tmpdir, "marker.*"))), 1)290 self.assertEqual(len(glob.glob(os.path.join(tmpdir, "marker.*"))), 1)
290291
292 def test_oem_channel_extractor(self):
293 s = get_oem_channel_descriptor("./tests/data/ubuntu_dist_channel")
294 self.assertEqual(s, "canonical-oem-watauga-precise-amd64-20120517-2")
295
291296
292if __name__ == "__main__":297if __name__ == "__main__":
293 unittest.main()298 unittest.main()

Subscribers

People subscribed via source and target branches