Beispiel #1
0
 def diskimage_install(self):
     # TODO evand 2009-09-02: Disabled until we can find a cross-platform
     # way of determining dd progress.
     #self.initialize_progress_thread()
     self.progress_message(_('Writing disk image...'))
     failure_msg = _('Could not write the disk image (%s) to the device'
                     ' (%s).') % (self.source, self.device)
     
     cmd = ['dd', 'if=%s' % str(self.source), 'of=%s' % str(self.device),
            'bs=1M']
     if sys.platform == 'win32':
         cmd.append('--size')
         try:
             popen(cmd)
         except USBCreatorProcessException:
             self._failure(failure_msg)
     else:
         import dbus
         try:
             bus = dbus.SystemBus()
             obj = bus.get_object('com.ubuntu.USBCreator',
                                  '/com/ubuntu/USBCreator')
             obj.Image(self.source, self.device, self.allow_system_internal,
                       dbus_interface='com.ubuntu.USBCreator',
                       timeout=MAX_DBUS_TIMEOUT)
         except dbus.DBusException:
             self._failure(failure_msg)
Beispiel #2
0
 def install_bootloader(self, grub_location=''):
     logging.debug('install_bootloader')
     self.progress_pulse()
     self.progress_message(_('Installing the bootloader...'))
     message = _('Failed to install the bootloader.')
     if sys.platform == 'win32':
         # TODO evand 2009-07-23: Zero out the MBR.  Check to see if the
         # first 446 bytes are all NULs, and if not, ask the user if they
         # want to wipe it.  Confirm with a USB disk that never has had an
         # OS installed to it.
         opts = '-fma'
         dev = str(os.path.splitdrive(self.target)[0])
         try:
             popen(['syslinux', opts, dev])
         except (USBCreatorProcessException, IOError):
             self._failure(message)
     else:
         import dbus
         try:
             bus = dbus.SystemBus()
             obj = bus.get_object('com.ubuntu.USBCreator',
                                  '/com/ubuntu/USBCreator')
             obj.InstallBootloader(self.device, self.allow_system_internal,
                                   grub_location,
                                   dbus_interface='com.ubuntu.USBCreator',
                                   timeout=MAX_DBUS_TIMEOUT)
         except dbus.DBusException:
             self._failure(message)
     self.progress_pulse_stop()
     self.check()
Beispiel #3
0
    def create_persistence(self):
        logging.debug('create_persistence')
        if self.persist != 0:
            dd_cmd = [
                'dd', 'if=/dev/zero', 'bs=1M',
                'of=%s' % os.path.join(str(self.target), 'casper-rw'),
                'count=%d' % self.persist
            ]
            if sys.platform == 'win32':
                # XXX evand 2009-07-30: Do not read past the end of the device.
                # See http://www.chrysocome.net/dd for details.
                dd_cmd.append('--size')
            if sys.platform != 'win32':
                mkfs_cmd = [
                    'mkfs.ext3', '-F',
                    '%s/casper-rw' % str(self.target)
                ]
            else:
                # FIXME evand 2009-07-23: Need a copy of mke2fs.exe.
                mkfs_cmd = []

            self.progress_message(_('Creating a persistence file...'))
            popen(dd_cmd)
            self.check()
            self.progress_message(
                _('Creating an ext2 filesystem in the '
                  'persistence file...'))
            if sys.platform != 'win32':
                popen(mkfs_cmd)
            self.check()
Beispiel #4
0
    def diskimage_install(self):
        # TODO evand 2009-09-02: Disabled until we can find a cross-platform
        # way of determining dd progress.
        #self.initialize_progress_thread()
        self.progress_message(_('Writing disk image...'))
        failure_msg = _('Could not write the disk image (%s) to the device'
                        ' (%s).') % (self.source, self.device)

        cmd = [
            'dd',
            'if=%s' % str(self.source),
            'of=%s' % str(self.device), 'bs=1M'
        ]
        if sys.platform == 'win32':
            cmd.append('--size')
            try:
                popen(cmd)
            except USBCreatorProcessException:
                self._failure(failure_msg)
        else:
            import dbus
            try:
                bus = dbus.SystemBus()
                obj = bus.get_object('com.ubuntu.USBCreator',
                                     '/com/ubuntu/USBCreator')
                obj.Image(self.source,
                          self.device,
                          self.allow_system_internal,
                          dbus_interface='com.ubuntu.USBCreator',
                          timeout=MAX_DBUS_TIMEOUT)
            except dbus.DBusException:
                self._failure(failure_msg)
Beispiel #5
0
 def install_bootloader(self, grub_location=''):
     logging.debug('install_bootloader')
     self.progress_pulse()
     self.progress_message(_('Installing the bootloader...'))
     message = _('Failed to install the bootloader.')
     if sys.platform == 'win32':
         # TODO evand 2009-07-23: Zero out the MBR.  Check to see if the
         # first 446 bytes are all NULs, and if not, ask the user if they
         # want to wipe it.  Confirm with a USB disk that never has had an
         # OS installed to it.
         opts = '-fma'
         dev = str(os.path.splitdrive(self.target)[0])
         try:
             popen(['syslinux', opts, dev])
         except (USBCreatorProcessException, IOError):
             self._failure(message)
     else:
         import dbus
         try:
             bus = dbus.SystemBus()
             obj = bus.get_object('com.ubuntu.USBCreator',
                                  '/com/ubuntu/USBCreator')
             obj.InstallBootloader(self.device,
                                   self.allow_system_internal,
                                   grub_location,
                                   self.need_syslinux_legacy(),
                                   dbus_interface='com.ubuntu.USBCreator',
                                   timeout=MAX_DBUS_TIMEOUT)
         except dbus.DBusException:
             self._failure(message)
     self.progress_pulse_stop()
     self.check()
 def open(self, udi):
     mp = self.targets[udi]['mountpoint']
     if not mp:
         try:
             dk = self.bus.get_object(DISKS_IFACE, udi)
             mp = dk.FilesystemMount('', [], dbus_interface=DEVICE_IFACE)
         except dbus.DBusException:
             logging.exception('Could not mount the device:')
             return ''
     try:
         misc.popen(['mount', '-o', 'remount,rw', mp])
     except misc.USBCreatorProcessException:
         logging.exception('Could not mount the device:')
         return ''
     return mp
Beispiel #7
0
 def open(self, udi):
     mp = self.targets[udi]['mountpoint']
     if not mp:
         try:
             obj = self.udisks.get_object(udi)
             fs = obj.get_filesystem()
             if not fs:
                 return ''
             mp = fs.call_mount_sync(no_options, None)
         except GLib.GError:
             logging.exception('Could not mount the device:')
             return ''
     try:
         misc.popen(['mount', '-o', 'remount,rw', mp])
     except misc.USBCreatorProcessException:
         logging.exception('Could not mount the device:')
         return ''
     return mp
 def _is_casper_cd(self, filename):
     cmd = ['isoinfo', '-J', '-i', filename, '-x', '/.disk/info']
     try:
         output = misc.popen(cmd, stderr=None)
         if output:
             return output
     except misc.USBCreatorProcessException:
         # TODO evand 2009-07-26: Error dialog.
         logging.error('Could not extract .disk/info.')
     return None
 def _is_casper_cd(self, filename):
     '''If this is a casper-based CD, return the CD label.'''
     # XXX evand 2009-07-25: Using 7zip until cdkit gets mingw support.
     cmd = ['7z', 'x', filename, '.disk/info', '-so']
     try:
         output = misc.popen(cmd, stderr=None)
         if output:
             return output
     except misc.USBCreatorProcessException:
         # TODO evand 2009-07-26: Error dialog.
         logging.error('Could not extract .disk/info.')
     return None
Beispiel #10
0
 def create_persistence(self):
     logging.debug('create_persistence')
     if self.persist != 0:
         dd_cmd = ['dd', 'if=/dev/zero', 'bs=1M', 'of=%s' %
                   os.path.join(str(self.target), 'casper-rw'),
                   'count=%d' % self.persist]
         if sys.platform == 'win32':
             # XXX evand 2009-07-30: Do not read past the end of the device.
             # See http://www.chrysocome.net/dd for details.
             dd_cmd.append('--size')
         if sys.platform != 'win32':
             mkfs_cmd = ['mkfs.ext3', '-F', '%s/casper-rw' % str(self.target)]
         else:
             # FIXME evand 2009-07-23: Need a copy of mke2fs.exe.
             mkfs_cmd = []
         
         self.progress_message(_('Creating a persistence file...'))
         popen(dd_cmd)
         self.check()
         self.progress_message(_('Creating an ext2 filesystem in the '
                                 'persistence file...'))
         if sys.platform != 'win32':
             popen(mkfs_cmd)
         self.check()
Beispiel #11
0
    def cdimage_install(self):
        # Build.

        cmd = ['7z', 'l', self.source]
        output = popen(cmd, stderr=None)
        processing = False
        listing = []
        for line in output.splitlines():
            if line.startswith('----------'):
                processing = not processing
                continue
            if not processing:
                continue
            listing.append(line.split())
        self.check()
        
        # Clear.

        self.progress_message(_('Removing files...'))
        for line in listing:
            length = len(line)
            assert length == 3 or length == 5
            t = os.path.join(self.target, line[-1])
            if os.path.exists(t):
                self.check()
                if os.path.isfile(t):
                    logging.debug('Removing %s' % t)
                    os.unlink(t)
                elif os.path.isdir(t):
                    logging.debug('Removing %s' % t)
                    shutil.rmtree(t)
        self.check()
        self.remove_extras()
        
        self.initialize_progress_thread()

        # Copy.
        
        cmd = ['7z', 'x', self.source, 'md5sum.txt', '-so']
        md5sums = {}
        try:
            output = popen(cmd, stderr=None)
            for line in output.splitlines():
                md5sum, filename = line.split()
                filename = os.path.normpath(filename[2:])
                md5sums[filename] = md5sum
        except StandardError:
            logging.error('Could not generate the md5sum list from md5sum.txt.')

        self.progress_message(_('Copying files...'))
        for line in listing:
            # TODO evand 2009-07-27: Because threads cannot kill other threads
            # in Python, and because it takes a significant amount of time to
            # copy the filesystem.sqaushfs file, we'll end up with a long wait
            # after the user presses the cancel button.  This is far from ideal
            # and should be resolved.
            # One possibility is to deal with subprocesses asynchronously.
            self.check()
            length = len(line)
            if length == 5:
                path = line[4]
                logging.debug('Writing %s' % os.path.join(self.target, path))
                cmd = ['7z', 'x', '-o%s' % self.target, self.source, path]
                popen(cmd)

                # Check md5sum.

                if path in md5sums:
                    targethash = md5()
                    targetfh = None
                    try:
                        targetfh = open(os.path.join(self.target, path), 'rb')
                        while 1:
                            buf = targetfh.read(16 * 1024)
                            if not buf:
                                break
                            targethash.update(buf)
                        if targethash.hexdigest() != md5sums[path]:
                            self._failure(_('md5 checksums do not match.'))
                            # TODO evand 2009-07-27: Recalculate md5 hash.
                    finally:
                        if targetfh:
                            targetfh.close()
                else:
                    logging.warn('md5 hash not available for %s' % path)
                    # TODO evand 2009-07-27: Recalculate md5 hash.
            elif length == 3:
                # TODO evand 2009-07-27: Update mtime with line[0] (YYYY-MM-DD)
                # and line[1] (HH:MM:SS).
                logging.debug('mkdir %s' % os.path.join(self.target, line[2]))
                os.mkdir(os.path.join(self.target, line[2]))

        self.install_efi()

        grub = os.path.join(self.target, 'boot', 'grub', 'i386-pc')
        if os.path.isdir(grub):
            self.install_bootloader(grub)
        else:
            self.install_bootloader()
            self.mangle_syslinux()

        self.create_persistence()
        self.sync()
Beispiel #12
0
    def cdimage_install(self):
        # Build.

        cmd = ['7z', 'l', self.source]
        output = popen(cmd, stderr=None)
        processing = False
        listing = []
        for line in output.splitlines():
            if line.startswith('----------'):
                processing = not processing
                continue
            if not processing:
                continue
            listing.append(line.split())
        self.check()

        # Clear.

        self.progress_message(_('Removing files...'))
        for line in listing:
            length = len(line)
            assert length == 3 or length == 5
            t = os.path.join(self.target, line[-1])
            if os.path.exists(t):
                self.check()
                if os.path.isfile(t):
                    logging.debug('Removing %s' % t)
                    os.unlink(t)
                elif os.path.isdir(t):
                    logging.debug('Removing %s' % t)
                    shutil.rmtree(t)
        self.check()
        self.remove_extras()

        self.initialize_progress_thread()

        # Copy.

        cmd = ['7z', 'x', self.source, 'md5sum.txt', '-so']
        md5sums = {}
        try:
            output = popen(cmd, stderr=None)
            for line in output.splitlines():
                md5sum, filename = line.split()
                filename = os.path.normpath(filename[2:])
                md5sums[filename] = md5sum
        except Exception:
            logging.error(
                'Could not generate the md5sum list from md5sum.txt.')

        self.progress_message(_('Copying files...'))
        for line in listing:
            # TODO evand 2009-07-27: Because threads cannot kill other threads
            # in Python, and because it takes a significant amount of time to
            # copy the filesystem.sqaushfs file, we'll end up with a long wait
            # after the user presses the cancel button.  This is far from ideal
            # and should be resolved.
            # One possibility is to deal with subprocesses asynchronously.
            self.check()
            length = len(line)
            if length == 5:
                path = line[4]
                logging.debug('Writing %s' % os.path.join(self.target, path))
                cmd = ['7z', 'x', '-o%s' % self.target, self.source, path]
                popen(cmd)

                # Check md5sum.

                if path in md5sums:
                    targethash = md5()
                    targetfh = None
                    try:
                        targetfh = open(os.path.join(self.target, path), 'rb')
                        while 1:
                            buf = targetfh.read(16 * 1024)
                            if not buf:
                                break
                            targethash.update(buf)
                        if targethash.hexdigest() != md5sums[path]:
                            self._failure(_('md5 checksums do not match.'))
                            # TODO evand 2009-07-27: Recalculate md5 hash.
                    finally:
                        if targetfh:
                            targetfh.close()
                else:
                    logging.warn('md5 hash not available for %s' % path)
                    # TODO evand 2009-07-27: Recalculate md5 hash.
            elif length == 3:
                # TODO evand 2009-07-27: Update mtime with line[0] (YYYY-MM-DD)
                # and line[1] (HH:MM:SS).
                logging.debug('mkdir %s' % os.path.join(self.target, line[2]))
                os.mkdir(os.path.join(self.target, line[2]))

        self.install_efi()

        grub = os.path.join(self.target, 'boot', 'grub', 'i386-pc')
        if os.path.isdir(grub):
            self.install_bootloader(grub)
        else:
            self.install_bootloader()
            self.mangle_syslinux()

        self.create_persistence()
        self.sync()
Beispiel #13
0
 def _fastboot_command(self, cmd):
     fastboot_cmd = ['fastboot', '-s', self.target]
     fastboot_cmd.extend(cmd)
     popen(fastboot_cmd)