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
=== modified file 'softwarecenter/db/application.py'
--- softwarecenter/db/application.py 2012-03-08 14:36:25 +0000
+++ softwarecenter/db/application.py 2012-03-15 12:47:22 +0000
@@ -821,21 +821,23 @@
821 def hardware_requirements(self):821 def hardware_requirements(self):
822 result = {}822 result = {}
823 try:823 try:
824 from debtagshw.debtagshw import DebtagsAvailableHW824 from softwarecenter.hw import get_hardware_support_for_tags
825 hw = DebtagsAvailableHW()825 result = get_hardware_support_for_tags(self.tags)
826 result = hw.get_hardware_support_for_tags(
827 self.tags)
828 except ImportError:826 except ImportError:
829 LOG.warn("failed to import debtagshw")827 LOG.warn("failed to import debtagshw")
830 return result828 return result
831 return result829 return result
832830
833 def _unavailable_channel(self):831 def _unavailable_channel(self):
834 """ Check if the given doc refers to a channel that is currently not enabled """832 """ Check if the given doc refers to a channel that is currently
833 not enabled
834 """
835 return not is_channel_available(self.channelname)835 return not is_channel_available(self.channelname)
836836
837 def _unavailable_component(self, component_to_check=None):837 def _unavailable_component(self, component_to_check=None):
838 """ Check if the given doc refers to a component that is currently not enabled """838 """ Check if the given doc refers to a component that is currently
839 not enabled
840 """
839 if component_to_check:841 if component_to_check:
840 component = component_to_check842 component = component_to_check
841 elif self.component:843 elif self.component:
842844
=== modified file 'softwarecenter/hw.py'
--- softwarecenter/hw.py 2012-03-02 10:11:09 +0000
+++ softwarecenter/hw.py 2012-03-15 12:47:22 +0000
@@ -18,6 +18,10 @@
1818
19from gettext import gettext as _19from gettext import gettext as _
2020
21# private extension over the debtagshw stuff
22OPENGL_DRIVER_BLACKLIST_TAG = "x-hardware::opengl-driver-blacklist:"
23
24
21TAG_DESCRIPTION = {25TAG_DESCRIPTION = {
22 'hardware::webcam' : _('webcam'),26 'hardware::webcam' : _('webcam'),
23 'hardware::digicam' : _('digicam'),27 'hardware::digicam' : _('digicam'),
@@ -67,15 +71,57 @@
67 'drive, but none are currently connected.'),71 'drive, but none are currently connected.'),
68 'hardware::video:opengl' : _('This computer does not have graphics fast '72 'hardware::video:opengl' : _('This computer does not have graphics fast '
69 'enough for this software.'),73 'enough for this software.'),
74 # private extension
75 OPENGL_DRIVER_BLACKLIST_TAG: _('This computer uses a "%s" video driver, '
76 'but the application is not compatible '
77 'with that.'),
70}78}
7179
80def get_hw_short_description(tag):
81 s = TAG_DESCRIPTION.get(tag)
82 return s
83
72def get_hw_missing_long_description(tags):84def get_hw_missing_long_description(tags):
73 s = ""85 s = ""
74 # build string86 # build string
75 for tag, supported in tags.iteritems():87 for tag, supported in tags.iteritems():
76 if supported == "no":88 if supported == "no":
77 s += "%s\n" % TAG_MISSING_DESCRIPTION.get(tag)89 descr = TAG_MISSING_DESCRIPTION.get(tag)
90 if descr:
91 s += "%s\n" % descr
92 else:
93 # deal with generic tags
94 prefix, sep, postfix = tag.rpartition(":")
95 descr = TAG_MISSING_DESCRIPTION.get(prefix+sep)
96 descr = descr % postfix
97 if descr:
98 s += "%s\n" % descr
78 # ensure that the last \n is gone99 # ensure that the last \n is gone
79 if s:100 if s:
80 s = s[:-1]101 s = s[:-1]
81 return s102 return s
103
104
105def get_private_extenstions_hardware_support_for_tags(tags):
106 import debtagshw
107 res = {}
108 for tag in tags:
109 if tag.startswith(OPENGL_DRIVER_BLACKLIST_TAG):
110 prefix, sep, driver = tag.rpartition(":")
111 if driver == debtagshw.opengl.get_driver():
112 res[tag] = debtagshw.enums.HardwareSupported.NO
113 else:
114 res[tag] = debtagshw.enums.HardwareSupported.YES
115 return res
116
117def get_hardware_support_for_tags(tags):
118 """ wrapper around the DebtagsAvailalbeHW to support adding our own
119 private tag extension (like opengl-driver)
120 """
121 from debtagshw.debtagshw import DebtagsAvailableHW
122 hw = DebtagsAvailableHW()
123 support = hw.get_hardware_support_for_tags(tags)
124 private_extensions = get_private_extenstions_hardware_support_for_tags(
125 tags)
126 support.update(private_extensions)
127 return support
82128
=== modified file 'softwarecenter/ui/gtk3/widgets/labels.py'
--- softwarecenter/ui/gtk3/widgets/labels.py 2012-03-09 12:50:38 +0000
+++ softwarecenter/ui/gtk3/widgets/labels.py 2012-03-15 12:47:22 +0000
@@ -19,7 +19,7 @@
19from gi.repository import Gtk19from gi.repository import Gtk
20from gettext import gettext as _20from gettext import gettext as _
2121
22from softwarecenter.hw import TAG_DESCRIPTION22from softwarecenter.hw import get_hw_short_description
2323
2424
25class HardwareRequirementsLabel(Gtk.HBox):25class HardwareRequirementsLabel(Gtk.HBox):
@@ -70,7 +70,7 @@
70 s = self.LABEL70 s = self.LABEL
71 return _(s) % {71 return _(s) % {
72 "sym": sym,72 "sym": sym,
73 "hardware": _(TAG_DESCRIPTION[self.tag]),73 "hardware": _(get_hw_short_description(self.tag))
74 }74 }
7575
76 def set_hardware_requirement(self, tag, result):76 def set_hardware_requirement(self, tag, result):
@@ -91,17 +91,15 @@
9191
92 def set_hardware_requirements(self, hw_requirements_result):92 def set_hardware_requirements(self, hw_requirements_result):
93 self.clear()93 self.clear()
94 for tag, supported in hw_requirements_result.iteritems():94 for i, (tag, sup) in enumerate(hw_requirements_result.iteritems()):
95 # ignore unknown for now95 # ignore unknown for now
96 if not supported in ("yes", "no"):96 if not sup in ("yes", "no"):
97 continue97 continue
98 label = HardwareRequirementsLabel(last_item=False)98 is_last_item = (i == len(hw_requirements_result)-1)
99 label.set_hardware_requirement(tag, supported)99 label = HardwareRequirementsLabel(last_item=is_last_item)
100 label.set_hardware_requirement(tag, sup)
100 label.show()101 label.show()
101 self.pack_start(label, True, True, 6)102 self.pack_start(label, True, True, 6)
102 # tell the last item that its last
103 if self.get_children():
104 self.get_children()[-1].last_item = True
105103
106 @property104 @property
107 def hw_labels(self):105 def hw_labels(self):
108106
=== added file 'test/test_hw.py'
--- test/test_hw.py 1970-01-01 00:00:00 +0000
+++ test/test_hw.py 2012-03-15 12:47:22 +0000
@@ -0,0 +1,44 @@
1#!/usr/bin/python
2
3import unittest
4
5from mock import patch
6
7from testutils import setup_test_env
8setup_test_env()
9from softwarecenter.hw import (
10 get_hardware_support_for_tags,
11 get_hw_missing_long_description,
12 OPENGL_DRIVER_BLACKLIST_TAG)
13
14class TestHW(unittest.TestCase):
15 """ tests the hardware support detection """
16
17 def test_get_hardware_support_for_tags(self):
18 tags = [OPENGL_DRIVER_BLACKLIST_TAG + "intel",
19 "hardware::input:mouse",
20 ]
21 with patch("debtagshw.opengl.get_driver") as mock_get_driver:
22 # test with the intel driver
23 mock_get_driver.return_value = "intel"
24 supported = get_hardware_support_for_tags(tags)
25 self.assertEqual(supported[tags[0]], "no")
26 self.assertEqual(len(supported), 2)
27 # now with fake amd driver
28 mock_get_driver.return_value = "amd"
29 supported = get_hardware_support_for_tags(tags)
30 self.assertEqual(supported[tags[0]], "yes")
31
32 def test_get_hw_missing_long_description(self):
33 s = get_hw_missing_long_description(
34 { "hardware::input:keyboard": "yes",
35 OPENGL_DRIVER_BLACKLIST_TAG + "intel": "no",
36 })
37 self.assertEqual(s, 'This computer uses a "intel" video driver, '
38 'but the application is not compatible with that.')
39
40
41if __name__ == "__main__":
42 #import logging
43 #logging.basicConfig(level=logging.DEBUG)
44 unittest.main()

Subscribers

People subscribed via source and target branches