~ubuntu-branches/ubuntu/saucy/usb-creator/saucy

« back to all changes in this revision

Viewing changes to usbcreator/backends/fastboot/backend.py

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-01-28 13:35:56 UTC
  • mfrom: (70.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130128133556-6wz7bnolagyylr94
Tags: 0.2.45.1
KDE frontend python3 fixes from Riddell.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import logging
 
2
 
 
3
from gi.repository import GUdev
 
4
from gi.repository import GLib
 
5
 
 
6
from usbcreator.backends.base import Backend
 
7
from usbcreator import misc
 
8
 
 
9
KNOWN_IDS = {
 
10
    'ID_VENDOR_ID': ('18d1',),
 
11
    'ID_MODEL_ID': ('4e40', 'd001',),
 
12
}
 
13
 
 
14
class FastbootBackend(Backend):
 
15
    def __init__(self):
 
16
        Backend.__init__(self)
 
17
        logging.debug('FastbootBackend')
 
18
        self.client = GUdev.Client(subsystems=['usb'])
 
19
        
 
20
    def on_uevent(self, action, device):
 
21
        logging.debug('action: %s' % action)
 
22
        logging.debug('device: %s' % device.get_sysfs_path())
 
23
 
 
24
        for key,ids in KNOWN_IDS.items():
 
25
            result = device.get_property(key)
 
26
            if result not in ids:
 
27
                logging.debug('Unknown %s: %s' % (key, result))
 
28
                return
 
29
            
 
30
        [logging.debug('%s=%s' % (k, device.get_property(k))) for k in device.get_property_keys()]
 
31
        
 
32
        key = device.get_property('ID_SERIAL_SHORT')
 
33
        
 
34
        if action == 'add':
 
35
            self.targets[key] = {
 
36
                'vendor'     : device.get_property('ID_VENDOR_FROM_DATABASE'),
 
37
                'model'      : device.get_property('ID_MODEL'),
 
38
                'label'      : '',
 
39
                'device'     : device.get_property('ID_SERIAL_SHORT'),
 
40
                'status'     : misc.CAN_USE,
 
41
                }
 
42
            if misc.callable(self.target_added_cb):
 
43
                self.target_added_cb(key)
 
44
        elif action == 'remove':
 
45
            self._device_removed(key)
 
46
            
 
47
    def detect_devices(self):
 
48
        def _on_uevent(client, action, device):
 
49
            self.on_uevent(action, device)
 
50
            
 
51
        self.client.connect('uevent', _on_uevent)
 
52
        # Just in case, go over already attached devices
 
53
        for device in self.client.query_by_subsystem('usb'):
 
54
            self.on_uevent('add', device)
 
55
 
 
56
    def update_free(self):
 
57
        # No progress yet.
 
58
        return True
 
59
 
 
60
    def _is_casper_cd(self, filename):
 
61
        # no cds for us
 
62
        return None    
 
63
 
 
64
    def unmount(self):
 
65
        return
 
66
 
 
67
    def shutdown(self):
 
68
        return