Merge lp:~mvo/software-center/opengl-driver-blacklist into lp:software-center

Proposed by Michael Vogt
Status: Merged
Merged at revision: 2866
Proposed branch: lp:~mvo/software-center/opengl-driver-blacklist
Merge into: lp:software-center
Diff against target: 201 lines (+106/-16)
4 files modified
softwarecenter/db/application.py (+8/-6)
softwarecenter/hw.py (+47/-1)
softwarecenter/ui/gtk3/widgets/labels.py (+7/-9)
test/test_hw.py (+44/-0)
To merge this branch: bzr merge lp:~mvo/software-center/opengl-driver-blacklist
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Review via email: mp+97633@code.launchpad.net

Description of the change

This will add support for video driver blacklisting. It needs a string freeze exception though.

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

Looks just great, thanks Michael!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/db/application.py'
2--- softwarecenter/db/application.py 2012-03-08 14:36:25 +0000
3+++ softwarecenter/db/application.py 2012-03-15 12:47:22 +0000
4@@ -821,21 +821,23 @@
5 def hardware_requirements(self):
6 result = {}
7 try:
8- from debtagshw.debtagshw import DebtagsAvailableHW
9- hw = DebtagsAvailableHW()
10- result = hw.get_hardware_support_for_tags(
11- self.tags)
12+ from softwarecenter.hw import get_hardware_support_for_tags
13+ result = get_hardware_support_for_tags(self.tags)
14 except ImportError:
15 LOG.warn("failed to import debtagshw")
16 return result
17 return result
18
19 def _unavailable_channel(self):
20- """ Check if the given doc refers to a channel that is currently not enabled """
21+ """ Check if the given doc refers to a channel that is currently
22+ not enabled
23+ """
24 return not is_channel_available(self.channelname)
25
26 def _unavailable_component(self, component_to_check=None):
27- """ Check if the given doc refers to a component that is currently not enabled """
28+ """ Check if the given doc refers to a component that is currently
29+ not enabled
30+ """
31 if component_to_check:
32 component = component_to_check
33 elif self.component:
34
35=== modified file 'softwarecenter/hw.py'
36--- softwarecenter/hw.py 2012-03-02 10:11:09 +0000
37+++ softwarecenter/hw.py 2012-03-15 12:47:22 +0000
38@@ -18,6 +18,10 @@
39
40 from gettext import gettext as _
41
42+# private extension over the debtagshw stuff
43+OPENGL_DRIVER_BLACKLIST_TAG = "x-hardware::opengl-driver-blacklist:"
44+
45+
46 TAG_DESCRIPTION = {
47 'hardware::webcam' : _('webcam'),
48 'hardware::digicam' : _('digicam'),
49@@ -67,15 +71,57 @@
50 'drive, but none are currently connected.'),
51 'hardware::video:opengl' : _('This computer does not have graphics fast '
52 'enough for this software.'),
53+ # private extension
54+ OPENGL_DRIVER_BLACKLIST_TAG: _('This computer uses a "%s" video driver, '
55+ 'but the application is not compatible '
56+ 'with that.'),
57 }
58
59+def get_hw_short_description(tag):
60+ s = TAG_DESCRIPTION.get(tag)
61+ return s
62+
63 def get_hw_missing_long_description(tags):
64 s = ""
65 # build string
66 for tag, supported in tags.iteritems():
67 if supported == "no":
68- s += "%s\n" % TAG_MISSING_DESCRIPTION.get(tag)
69+ descr = TAG_MISSING_DESCRIPTION.get(tag)
70+ if descr:
71+ s += "%s\n" % descr
72+ else:
73+ # deal with generic tags
74+ prefix, sep, postfix = tag.rpartition(":")
75+ descr = TAG_MISSING_DESCRIPTION.get(prefix+sep)
76+ descr = descr % postfix
77+ if descr:
78+ s += "%s\n" % descr
79 # ensure that the last \n is gone
80 if s:
81 s = s[:-1]
82 return s
83+
84+
85+def get_private_extenstions_hardware_support_for_tags(tags):
86+ import debtagshw
87+ res = {}
88+ for tag in tags:
89+ if tag.startswith(OPENGL_DRIVER_BLACKLIST_TAG):
90+ prefix, sep, driver = tag.rpartition(":")
91+ if driver == debtagshw.opengl.get_driver():
92+ res[tag] = debtagshw.enums.HardwareSupported.NO
93+ else:
94+ res[tag] = debtagshw.enums.HardwareSupported.YES
95+ return res
96+
97+def get_hardware_support_for_tags(tags):
98+ """ wrapper around the DebtagsAvailalbeHW to support adding our own
99+ private tag extension (like opengl-driver)
100+ """
101+ from debtagshw.debtagshw import DebtagsAvailableHW
102+ hw = DebtagsAvailableHW()
103+ support = hw.get_hardware_support_for_tags(tags)
104+ private_extensions = get_private_extenstions_hardware_support_for_tags(
105+ tags)
106+ support.update(private_extensions)
107+ return support
108
109=== modified file 'softwarecenter/ui/gtk3/widgets/labels.py'
110--- softwarecenter/ui/gtk3/widgets/labels.py 2012-03-09 12:50:38 +0000
111+++ softwarecenter/ui/gtk3/widgets/labels.py 2012-03-15 12:47:22 +0000
112@@ -19,7 +19,7 @@
113 from gi.repository import Gtk
114 from gettext import gettext as _
115
116-from softwarecenter.hw import TAG_DESCRIPTION
117+from softwarecenter.hw import get_hw_short_description
118
119
120 class HardwareRequirementsLabel(Gtk.HBox):
121@@ -70,7 +70,7 @@
122 s = self.LABEL
123 return _(s) % {
124 "sym": sym,
125- "hardware": _(TAG_DESCRIPTION[self.tag]),
126+ "hardware": _(get_hw_short_description(self.tag))
127 }
128
129 def set_hardware_requirement(self, tag, result):
130@@ -91,17 +91,15 @@
131
132 def set_hardware_requirements(self, hw_requirements_result):
133 self.clear()
134- for tag, supported in hw_requirements_result.iteritems():
135+ for i, (tag, sup) in enumerate(hw_requirements_result.iteritems()):
136 # ignore unknown for now
137- if not supported in ("yes", "no"):
138+ if not sup in ("yes", "no"):
139 continue
140- label = HardwareRequirementsLabel(last_item=False)
141- label.set_hardware_requirement(tag, supported)
142+ is_last_item = (i == len(hw_requirements_result)-1)
143+ label = HardwareRequirementsLabel(last_item=is_last_item)
144+ label.set_hardware_requirement(tag, sup)
145 label.show()
146 self.pack_start(label, True, True, 6)
147- # tell the last item that its last
148- if self.get_children():
149- self.get_children()[-1].last_item = True
150
151 @property
152 def hw_labels(self):
153
154=== added file 'test/test_hw.py'
155--- test/test_hw.py 1970-01-01 00:00:00 +0000
156+++ test/test_hw.py 2012-03-15 12:47:22 +0000
157@@ -0,0 +1,44 @@
158+#!/usr/bin/python
159+
160+import unittest
161+
162+from mock import patch
163+
164+from testutils import setup_test_env
165+setup_test_env()
166+from softwarecenter.hw import (
167+ get_hardware_support_for_tags,
168+ get_hw_missing_long_description,
169+ OPENGL_DRIVER_BLACKLIST_TAG)
170+
171+class TestHW(unittest.TestCase):
172+ """ tests the hardware support detection """
173+
174+ def test_get_hardware_support_for_tags(self):
175+ tags = [OPENGL_DRIVER_BLACKLIST_TAG + "intel",
176+ "hardware::input:mouse",
177+ ]
178+ with patch("debtagshw.opengl.get_driver") as mock_get_driver:
179+ # test with the intel driver
180+ mock_get_driver.return_value = "intel"
181+ supported = get_hardware_support_for_tags(tags)
182+ self.assertEqual(supported[tags[0]], "no")
183+ self.assertEqual(len(supported), 2)
184+ # now with fake amd driver
185+ mock_get_driver.return_value = "amd"
186+ supported = get_hardware_support_for_tags(tags)
187+ self.assertEqual(supported[tags[0]], "yes")
188+
189+ def test_get_hw_missing_long_description(self):
190+ s = get_hw_missing_long_description(
191+ { "hardware::input:keyboard": "yes",
192+ OPENGL_DRIVER_BLACKLIST_TAG + "intel": "no",
193+ })
194+ self.assertEqual(s, 'This computer uses a "intel" video driver, '
195+ 'but the application is not compatible with that.')
196+
197+
198+if __name__ == "__main__":
199+ #import logging
200+ #logging.basicConfig(level=logging.DEBUG)
201+ unittest.main()

Subscribers

People subscribed via source and target branches