~ubuntu-branches/ubuntu/vivid/debtags/vivid

« back to all changes in this revision

Viewing changes to debtagshw/detectors.py

  • Committer: Package Import Robot
  • Author(s): Enrico Zini, Michael Vogt, Enrico Zini
  • Date: 2013-10-25 12:41:25 UTC
  • Revision ID: package-import@ubuntu.com-20131025124125-ytl4xarlmdyiuzjb
Tags: 1.12
[ Michael Vogt ]
* Install files in python3-debtagshw

[ Enrico Zini ]
* Build with new wibble

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# along with this program; if not, write to the Free Software
20
20
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
21
 
 
22
from __future__ import absolute_import
 
23
 
22
24
import logging
23
25
import os
24
26
import subprocess
31
33
except ImportError:
32
34
    HAVE_GUDEV = False
33
35
 
34
 
from enums import HardwareSupported
35
 
import opengl
 
36
from .enums import HardwareSupported
 
37
from . import opengl
36
38
 
37
39
class Detector(object):
38
40
    """ Base detector class """
110
112
    }
111
113
 
112
114
    # all tags this class knows about
113
 
    SUPPORTED_TAGS = DEBTAG_TO_UDEV_PROPERTY.keys() + \
114
 
                      DEBTAG_TO_ID_TYPE.keys()
 
115
    SUPPORTED_TAGS = list(DEBTAG_TO_UDEV_PROPERTY.keys()) + \
 
116
                      list(DEBTAG_TO_ID_TYPE.keys())
115
117
 
116
118
    def __init__(self):
117
119
        if HAVE_GUDEV:
145
147
                    return HardwareSupported.YES
146
148
        # if we know about the tag and did not find it, return NO
147
149
        # (LP: #1020057)
148
 
        if tag in self.SUPPORTED_TAGS: 
 
150
        if tag in self.SUPPORTED_TAGS:
149
151
            return HardwareSupported.NO
150
152
        # otherwise its UNKNOWN
151
153
        return HardwareSupported.UNKNOWN
156
158
 
157
159
class DetectorCmdline(Detector):
158
160
    """ detect hardware using cmdline helpers """
159
 
    
 
161
 
160
162
    LAPTOP_DETECT = "/usr/sbin/laptop-detect"
161
163
    SCANIMAGE = ["scanimage", "-L"]
162
164
 
189
191
        # Note: you can use multiprocessing.Pool.map to run all checks in
190
192
        # parallel
191
193
        try:
192
 
            output = subprocess.check_output(self.SCANIMAGE)
 
194
            output = subprocess.check_output(self.SCANIMAGE,
 
195
                                             universal_newlines=True)
193
196
            if output.startswith("device"):
194
197
                return HardwareSupported.YES
195
198
            else:
200
203
 
201
204
class DetectorCtypes(Detector):
202
205
    """ detect hardware using ctypes c calls """
203
 
    
 
206
 
204
207
    def __init__(self):
205
208
        self.TAG_TO_FUNC = {
206
209
            'hardware::video:opengl' : self._is_supported,
218
221
            elif res is False:
219
222
                return HardwareSupported.NO
220
223
        return HardwareSupported.UNKNOWN
221
 
    
 
224
 
222
225
    def get_supported_tags(self):
223
 
        return self.TAG_TO_FUNC.keys()
 
226
        return list(self.TAG_TO_FUNC.keys())
224
227
 
225
228
 
226
229
class DetectorPython(Detector):
247
250
    """ hepler that returns a list of all lowlevel detector classes """
248
251
    # introspect the detectors modules to load all availalbe detectors
249
252
    detectors = []
250
 
    for name, klass in globals().iteritems():
 
253
    for name, klass in globals().items():
251
254
        if name.startswith("Detector"):
252
255
            detectors.append(klass())
253
256
    return detectors