~mvo/software-center/tos-dialog

« back to all changes in this revision

Viewing changes to softwarecenter/hw.py

  • Committer: Michael Vogt
  • Date: 2012-03-16 09:02:42 UTC
  • mfrom: (2847.1.20 trunk)
  • Revision ID: michael.vogt@ubuntu.com-20120316090242-qjbr54zfxt9refgj
merged from trunk, fix pep8 issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from gettext import gettext as _
20
20
 
 
21
# private extension over the debtagshw stuff
 
22
OPENGL_DRIVER_BLACKLIST_TAG = "x-hardware::opengl-driver-blacklist:"
 
23
 
 
24
 
21
25
TAG_DESCRIPTION = {
22
 
    'hardware::webcam' : _('webcam'),
23
 
    'hardware::digicam' : _('digicam'),
24
 
    'hardware::input:mouse' : _('mouse'),
25
 
    'hardware::input:joystick' : _('joystick'),
26
 
    'hardware::input:touchscreen' : _('touchscreen'),
27
 
    'hardware::gps' : _('GPS'),
28
 
    'hardware::laptop' : _('notebook computer'),
 
26
    'hardware::webcam': _('webcam'),
 
27
    'hardware::digicam': _('digicam'),
 
28
    'hardware::input:mouse': _('mouse'),
 
29
    'hardware::input:joystick': _('joystick'),
 
30
    'hardware::input:touchscreen': _('touchscreen'),
 
31
    'hardware::gps': _('GPS'),
 
32
    'hardware::laptop': _('notebook computer'),
29
33
    'hardware::printer': _('printer'),
30
 
    'hardware::scanner' : _('scanner'),
31
 
    'hardware::storage:cd' : _('CD drive'),
32
 
    'hardware::storage:cd-writer' : _('CD burner'),
33
 
    'hardware::storage:dvd' : _('DVD drive'),
34
 
    'hardware::storage:dvd-writer' : _('DVD burner'),
35
 
    'hardware::storage:floppy' : _('floppy disk drive'),
36
 
    'hardware::video:opengl' : _('OpenGL hardware acceleration'),
 
34
    'hardware::scanner': _('scanner'),
 
35
    'hardware::storage:cd': _('CD drive'),
 
36
    'hardware::storage:cd-writer': _('CD burner'),
 
37
    'hardware::storage:dvd': _('DVD drive'),
 
38
    'hardware::storage:dvd-writer': _('DVD burner'),
 
39
    'hardware::storage:floppy': _('floppy disk drive'),
 
40
    'hardware::video:opengl': _('OpenGL hardware acceleration'),
37
41
 
38
42
}
39
43
 
40
44
TAG_MISSING_DESCRIPTION = {
41
 
    'hardware::digicam' : _('This software requires a digital camera, but none '
42
 
                           'are currently connected'),
43
 
    'hardware::webcam' : _('This software requires a video camera, but none '
44
 
                           'are currently connected'),
45
 
    'hardware::input:mouse' : _('This software requires a mouse, '
 
45
    'hardware::digicam': _('This software requires a digital camera, but none '
 
46
                           'are currently connected'),
 
47
    'hardware::webcam': _('This software requires a video camera, but none '
 
48
                           'are currently connected'),
 
49
    'hardware::input:mouse': _('This software requires a mouse, '
46
50
                                'but none is currently setup.'),
47
 
    'hardware::input:joystick' : _('This software requires a joystick, '
 
51
    'hardware::input:joystick': _('This software requires a joystick, '
48
52
                                   'but none are currently connected.'),
49
 
    'hardware::input:touchscreen' : _('This software requires a touchscreen, '
 
53
    'hardware::input:touchscreen': _('This software requires a touchscreen, '
50
54
                                      'but the computer does not have one.'),
51
 
    'hardware::gps' : _('This software requires a GPS, '
 
55
    'hardware::gps': _('This software requires a GPS, '
52
56
                        'but the computer does not have one.'),
53
 
    'hardware::laptop' : _('This software is for notebook computers.'),
 
57
    'hardware::laptop': _('This software is for notebook computers.'),
54
58
    'hardware::printer': _('This software requires a printer, but none '
55
59
                           'are currently set up.'),
56
 
    'hardware::scanner' : _('This software requires a scanner, but none are '
 
60
    'hardware::scanner': _('This software requires a scanner, but none are '
57
61
                            'currently set up.'),
58
 
    'hardware::stoarge:cd' : _('This software requires a CD drive, but none '
 
62
    'hardware::stoarge:cd': _('This software requires a CD drive, but none '
59
63
                               'are currently connected.'),
60
 
    'hardware::storage:cd-writer' : _('This software requires a CD burner, '
 
64
    'hardware::storage:cd-writer': _('This software requires a CD burner, '
61
65
                                      'but none are currently connected.'),
62
 
    'hardware::storage:dvd' : _('This software requires a DVD drive, but none '
 
66
    'hardware::storage:dvd': _('This software requires a DVD drive, but none '
63
67
                                'are currently connected.'),
64
 
    'hardware::storage:dvd-writer' : _('This software requires a DVD burner, '
 
68
    'hardware::storage:dvd-writer': _('This software requires a DVD burner, '
65
69
                                       'but none are currently connected.'),
66
 
    'hardware::storage:floppy' : _('This software requires a floppy disk '
 
70
    'hardware::storage:floppy': _('This software requires a floppy disk '
67
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
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
}
71
79
 
 
80
def get_hw_short_description(tag):
 
81
    s = TAG_DESCRIPTION.get(tag)
 
82
    return s
 
83
 
72
84
def get_hw_missing_long_description(tags):
73
85
    s = ""
74
86
    # build string
75
87
    for tag, supported in tags.iteritems():
76
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
99
    # ensure that the last \n is gone
79
100
    if s:
80
101
        s = s[:-1]
81
102
    return s
 
103
 
 
104
 
 
105
def get_private_extensions_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
 
 
117
def 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_extensions_hardware_support_for_tags(
 
125
        tags)
 
126
    support.update(private_extensions)
 
127
    return support