~ubuntu-branches/ubuntu/trusty/jockey/trusty

« back to all changes in this revision

Viewing changes to jockey/xorg_driver.py

  • Committer: Package Import Robot
  • Author(s): Alberto Milone
  • Date: 2012-06-12 14:57:57 UTC
  • Revision ID: package-import@ubuntu.com-20120612145757-fmuzahun42e7ntte
Tags: 0.9.7-0ubuntu9
* debian/control:
  - Depend on python-xkit >= 0.5.0.
* data/handlers/fglrx.py data/handlers/nvidia.py jockey/xorg_driver.py:
  - Port custom handlers and xorg handler to the xkit 0.5 API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import os.path, logging, re
20
20
from glob import glob
21
21
 
22
 
import XKit.xutils
23
 
import XKit.xorgparser
 
22
import xkit.xutils
 
23
import xkit.xorgparser
24
24
 
25
25
from handlers import KernelModuleHandler
26
26
from jockey.oslib import OSLib
75
75
 
76
76
        if os.path.exists(OSLib.inst.xorg_conf_path):
77
77
            try:
78
 
                self.xorg_conf = XKit.xutils.XUtils(OSLib.inst.xorg_conf_path)
79
 
            except XKit.xorgparser.ParseException:
 
78
                self.xorg_conf = xkit.xutils.XUtils(OSLib.inst.xorg_conf_path)
 
79
            except xkit.xorgparser.ParseException:
80
80
                # for now, do not mess up an already broken xorg.conf any
81
81
                # further; TODO: UI dialog question to start from scratch
82
82
                self.xorg_conf = None
83
83
        else:
84
 
            self.xorg_conf = XKit.xutils.XUtils()
 
84
            self.xorg_conf = xkit.xutils.XUtils()
85
85
 
86
86
    def id(self):
87
87
        '''Return a unique identifier of the handler.'''
113
113
    def enabled(self):
114
114
        if self.xorg_conf:
115
115
            if self.xorg_driver:
116
 
                if self.xorg_conf.isDriverEnabled(self.xorg_driver) == False:
 
116
                if self.xorg_conf.is_driver_enabled(self.xorg_driver) == False:
117
117
                    logging.debug('XorgDriverHandler(%s, %s, %s).enabled(): considering xorg driver disabled',
118
118
                        self.module, self.package, self.xorg_driver)
119
119
                    return False
144
144
        '''
145
145
        for i in xrange(len(self.xorg_conf.globaldict['Module'])):
146
146
            try:
147
 
                modules = self.xorg_conf.getValue('Module', action, i)
148
 
            except XKit.xorgparser.OptionException:
 
147
                modules = self.xorg_conf.get_value('Module', action, i)
 
148
            except xkit.xorgparser.OptionException:
149
149
                # there is no matching action
150
150
                continue
151
151
            
187
187
            it = 0
188
188
            for section in self.xorg_conf.globaldict['Device']:
189
189
                try:
190
 
                    driver = self.xorg_conf.getDriver('Device', it)
 
190
                    driver = self.xorg_conf.get_driver('Device', it)
191
191
                    if driver == self.xorg_driver:
192
192
                        has_proprietary = True
193
193
                        break
194
 
                except XKit.xorgparser.OptionException:
 
194
                except xkit.xorgparser.OptionException:
195
195
                    # no driver is specified
196
196
                    pass
197
197
                it += 1
208
208
        if self.xorg_driver or self.extra_conf_options:
209
209
            if len(self.xorg_conf.globaldict['Device']) == 0:
210
210
                # Create a new Device section. "device" = position of the section
211
 
                device = self.xorg_conf.makeSection('Device', identifier='Default Device')
 
211
                device = self.xorg_conf.make_section('Device', identifier='Default Device')
212
212
                relevant_devices.append(device)
213
213
                # Set the driver
214
214
                if self.xorg_driver:
215
 
                    self.xorg_conf.setDriver('Device', self.xorg_driver, device)
 
215
                    self.xorg_conf.set_driver('Device', self.xorg_driver, device)
216
216
            else:
217
217
                # Get the relevant sections by checking the ServerLayout section
218
218
                # in case of multiple screens layouts or modify all the Device
219
219
                # sections
220
 
                devices = self.xorg_conf.getDevicesInUse()
 
220
                devices = self.xorg_conf.get_devices_in_use()
221
221
                if len(devices) > 0:
222
222
                    relevant_devices = devices
223
223
                else:
224
224
                    relevant_devices = self.xorg_conf.globaldict['Device'].keys()
225
225
                if self.xorg_driver:
226
226
                    for device in relevant_devices:
227
 
                        self.xorg_conf.setDriver('Device', self.xorg_driver, device)
 
227
                        self.xorg_conf.set_driver('Device', self.xorg_driver, device)
228
228
            logging.debug('XorgDriverHandler device sections (%s)' % (
229
229
                str(self.xorg_conf.globaldict['Device'])))
230
230
        
234
234
        if have_modules:
235
235
            for section in module_sections:
236
236
                for mod in self.remove_modules:
237
 
                    self.xorg_conf.removeOption('Module', 'Load', value=mod, position=section)
 
237
                    self.xorg_conf.remove_option('Module', 'Load', value=mod, position=section)
238
238
        
239
239
        if self.add_modules:
240
240
            if not have_modules:
241
 
                module_section = self.xorg_conf.makeSection('Module')
 
241
                module_section = self.xorg_conf.make_section('Module')
242
242
            else:
243
243
                module_section = 0 #the 1st module section
244
244
            
245
245
            for mod in self.add_modules:
246
246
                if not self._mod_enabled(mod):
247
 
                    self.xorg_conf.addOption('Module', 'Load', mod, optiontype=None, position=module_section, reference=True)
 
247
                    self.xorg_conf.add_option('Module', 'Load', mod, option_type=None, position=module_section, reference=True)
248
248
        
249
249
        if self.disable_modules:
250
250
            for mod in self.disable_modules:
251
251
                if not self._mod_disabled(mod):
252
 
                    self.xorg_conf.addOption('Module', 'Disable', mod, optiontype=None, position=module_section, reference=True)
 
252
                    self.xorg_conf.add_option('Module', 'Disable', mod, option_type=None, position=module_section, reference=True)
253
253
        
254
254
        for device_section in relevant_devices:
255
255
            for k, v in self.extra_conf_options.iteritems():
256
 
                self.xorg_conf.addOption('Device', k, v, optiontype='Option', position=device_section)
 
256
                self.xorg_conf.add_option('Device', k, v, option_type='Option', position=device_section)
257
257
        
258
258
        self.enable_config_hook()
259
259
        
260
 
        self.xorg_conf.writeFile(OSLib.inst.xorg_conf_path)
 
260
        self.xorg_conf.write(OSLib.inst.xorg_conf_path)
261
261
 
262
262
        return False
263
263
 
279
279
            os.unlink(self.no_conf)
280
280
            if os.path.exists(OSLib.inst.xorg_conf_path):
281
281
                os.unlink(OSLib.inst.xorg_conf_path)
282
 
            self.xorg_conf = XKit.xutils.XUtils()
 
282
            self.xorg_conf = xkit.xutils.XUtils()
283
283
        # if we have the previous xorg.conf, restore that
284
284
        elif os.path.exists(self.old_conf):
285
285
            logging.debug('XorgDriverHandler.disable(%s): restoring xorg.conf backup', 
286
286
                    self.xorg_driver or self.package)
287
287
            open(OSLib.inst.xorg_conf_path, 'w').write(open(self.old_conf).read())
288
288
            os.unlink(self.old_conf)
289
 
            self.xorg_conf = XKit.xutils.XUtils(OSLib.inst.xorg_conf_path)
 
289
            self.xorg_conf = xkit.xutils.XUtils(OSLib.inst.xorg_conf_path)
290
290
        else: # no backup, so mangle current config manually
291
291
            logging.debug('XorgDriverHandler.disable(%s): missing xorg.conf, reversing changes from enable()',
292
292
                    self.xorg_driver or self.package)
293
293
            relevant_devices = []
294
294
            
295
295
            if len(self.xorg_conf.globaldict['Device']) > 0:
296
 
                devices = self.xorg_conf.getDevicesInUse()
 
296
                devices = self.xorg_conf.get_devices_in_use()
297
297
                if len(devices) > 0:
298
298
                    relevant_devices = devices
299
299
                else:
306
306
                if have_modules:
307
307
                    for section in module_sections:
308
308
                        for mod in self.add_modules:
309
 
                            self.xorg_conf.removeOption('Module', 'Load', value=mod, position=section)
 
309
                            self.xorg_conf.remove_option('Module', 'Load', value=mod, position=section)
310
310
                        
311
311
                        for mod in self.disable_modules:
312
 
                            self.xorg_conf.removeOption('Module', 'Disable', value=mod, position=section)
 
312
                            self.xorg_conf.remove_option('Module', 'Disable', value=mod, position=section)
313
313
                
314
314
                if self.remove_modules:
315
315
                    if not have_modules:
316
 
                        module_section = self.xorg_conf.makeSection('Module')
 
316
                        module_section = self.xorg_conf.make_section('Module')
317
317
                    else:
318
318
                        module_section = 0 #the 1st module section
319
319
                    
320
320
                    for mod in self.remove_modules:
321
321
                        if not self._mod_enabled(mod):
322
 
                            self.xorg_conf.addOption('Module', 'Load', mod,
323
 
                                optiontype=None, position=module_section,
 
322
                            self.xorg_conf.add_option('Module', 'Load', mod,
 
323
                                option_type=None, position=module_section,
324
324
                                reference=True)
325
325
                    
326
326
                for device_section in relevant_devices:
327
327
                    if self.alt_free_driver:
328
 
                        self.xorg_conf.setDriver('Device', self.alt_free_driver, device_section)
 
328
                        self.xorg_conf.set_driver('Device', self.alt_free_driver, device_section)
329
329
                    
330
330
                    for k, v in self.extra_conf_options.iteritems():
331
 
                        self.xorg_conf.removeOption('Device', k, v, position=device_section)
 
331
                        self.xorg_conf.remove_option('Device', k, v, position=device_section)
332
332
                
333
333
            self.disable_config_hook()
334
334
 
335
335
            logging.debug('XorgDriverHandler.disable(%s): writing restored xorg.conf', 
336
336
                    self.xorg_driver or self.package)
337
 
            self.xorg_conf.writeFile(OSLib.inst.xorg_conf_path)
 
337
            self.xorg_conf.write(OSLib.inst.xorg_conf_path)
338
338
 
339
339
        return False
340
340