~usb-creator-hackers/usb-creator/trunk

« back to all changes in this revision

Viewing changes to usbcreator/install.py

  • Committer: Dmitrijs Ledkovs
  • Date: 2013-01-24 17:00:31 UTC
  • mto: This revision was merged to the branch mainline in revision 407.
  • Revision ID: dmitrijs.ledkovs@canonical.com-20130124170031-0w7zc2kkaj86uu7x
Support flashing devices using fastboot (e.g. Nexus7).

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from threading import Thread, Event
27
27
import logging
28
28
from hashlib import md5
 
29
import time
29
30
 
30
31
if sys.platform != 'win32':
31
32
    from usbcreator.misc import MAX_DBUS_TIMEOUT
65
66
 
66
67
class install(Thread):
67
68
    def __init__(self, source, target, persist, device=None,
68
 
                 allow_system_internal=False):
 
69
                 allow_system_internal=False,
 
70
                 fastboot_mode=False):
69
71
        Thread.__init__(self)
70
72
        self.source = source
71
73
        self.target = target
72
74
        self.persist = persist
73
75
        self.device = device
74
76
        self.allow_system_internal = allow_system_internal
 
77
        self.fastboot_mode = fastboot_mode
75
78
        self._stopevent = Event()
76
79
        self.progress_thread = None
77
80
        logging.debug('install thread source: %s' % source)
137
140
                if ext not in ['.iso', '.img']:
138
141
                    self._failure(_('The extension "%s" is not supported.') %
139
142
                                    ext)
140
 
                if ext == '.iso':
 
143
                if self.fastboot_mode:
 
144
                    self.bootimg = os.path.splitext(self.source)[0] + '.bootimg'
 
145
                    if not os.path.isfile(self.bootimg):
 
146
                        self._failure(_('Missing matching "%s" for source image %s.') %
 
147
                                    (self.bootimg, self.source))
 
148
                    self.fastboot_install()
 
149
                elif ext == '.iso':
141
150
                    if sys.platform == 'win32':
142
151
                        self.cdimage_install()
143
152
                    else:
394
403
            except dbus.DBusException:
395
404
                self._failure(failure_msg)
396
405
 
 
406
    def _fastboot_command(self, cmd):
 
407
        fastboot_cmd = ['fastboot', '-s', self.target]
 
408
        fastboot_cmd.extend(cmd)
 
409
        popen(fastboot_cmd)
 
410
 
 
411
    def fastboot_install(self):
 
412
        self.progress(0, 3*60+9, True)
 
413
        self.progress_message(_('Erasing boot partition...'))
 
414
        self._fastboot_command(['erase', 'boot'])
 
415
        self.progress(5, 3*60+7, True)
 
416
        self.progress_message(_('Erasing user partition...'))
 
417
        self._fastboot_command(['erase', 'userdata'])
 
418
        self.progress(10, 3*60+5, True)
 
419
        self.progress_message(_('Flashing boot partition...'))
 
420
        self._fastboot_command(['flash', 'boot', self.bootimg])
 
421
        self.progress(15, 3*60+3, True)
 
422
        self.progress_message(_('Flashing user partition...'))
 
423
        self.progress_pulse()
 
424
        self._fastboot_command(['flash', 'userdata', self.source])
 
425
        self.progress_pulse_stop()        
 
426
        self.progress(95, 1, True)
 
427
        self.progress_message(_('Rebooting device...'))
 
428
        self._fastboot_command(['reboot'])
 
429
        self.progress(100, 0, True)
 
430
 
397
431
    def cdimage_install(self):
398
432
        # Build.
399
433