~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-28 12:45:42 UTC
  • mfrom: (406.1.2 nexus7)
  • Revision ID: dmitrijs.ledkovs@canonical.com-20130128124542-2y05i9bb622d3uob
Support flashing devices using fastboot (e.g. Nexus7).

Show diffs side-by-side

added added

removed removed

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