Exemple #1
0
 def modify_bootini(self, drive, associated_task):
     log.debug("modify_bootini %s" % drive.path)
     bootini = join_path(drive.path, 'boot.ini')
     if not os.path.isfile(bootini):
         log.debug("Could not find boot.ini %s" % bootini)
         return
     src = join_path(self.info.root_dir, 'winboot', 'wisildr')
     dest = join_path(drive.path, 'wisildr')
     shutil.copyfile(src, dest)
     src = join_path(self.info.root_dir, 'winboot', 'wisildr.mbr')
     dest = join_path(drive.path, 'wisildr.mbr')
     shutil.copyfile(src, dest)
     run_command(['attrib', '-R', '-S', '-H', bootini])
     boot_line = 'C:\wisildr.mbr = "%s"' % self.info.distro.name
     old_line = boot_line[:boot_line.index("=")].strip().lower()
     # ConfigParser gets confused by the ':' and changes the options order
     content = read_file(bootini)
     if content[-1] != '\n':
         content += '\n'
     lines = content.split('\n')
     is_section = False
     for i, line in enumerate(lines):
         if line.strip().lower() == "[operating systems]":
             is_section = True
         elif line.strip().startswith("["):
             is_section = False
         if is_section and line.strip().lower().startswith(old_line):
             lines[i] = boot_line
             break
         if is_section and not line.strip():
             lines.insert(i, boot_line)
             break
     content = '\n'.join(lines)
     write_file(bootini, content)
     run_command(['attrib', '+R', '+S', '+H', bootini])
Exemple #2
0
    def modify_configsys(self, drive, associated_task):
        log.debug("modify_configsys %s" % drive.path)
        configsys = join_path(drive.path, 'config.sys')
        if not os.path.isfile(configsys):
            return
        src = join_path(self.info.root_dir, 'winboot', 'wisildr.exe')
        dest = join_path(drive.path, 'wisildr.exe')
        shutil.copyfile(src,  dest)
        run_command(['attrib', '-R', '-S', '-H', configsys])
        config = read_file(configsys)
        if 'REM WUBI MENU START\n' in config:
            log.debug("Configsys has already been modified")
            return

        config += '''
        REM WUBI MENU START
        [menu]
        menucolor=15,0
        menuitem=windows,Windows
        menuitem=wisildr,$distro
        menudefault=windows,10
        [wisildr]
        device=wisildr.exe
        [windows]

        REM WUBI MENU END
        '''
        write_file(configsys, config)
        run_command(['attrib', '+R', '+S', '+H', configsys])
Exemple #3
0
 def undo_bcd(self, associated_task):
     bcdedit = join_path(os.getenv('SystemDrive'), 'bcdedit.exe')
     if not isfile(bcdedit):
         bcdedit = join_path(os.getenv('SystemRoot'), 'sysnative', 'bcdedit.exe')
     if not os.path.isfile(bcdedit):
         bcdedit = join_path(os.environ['systemroot'], 'System32', 'bcdedit.exe')
     if not os.path.isfile(bcdedit):
         log.error("Cannot find bcdedit")
         return
     id = registry.get_value(
         'HKEY_LOCAL_MACHINE',
         self.info.registry_key,
         'VistaBootDrive')
     if not id:
         log.debug("Could not find bcd id")
         return
     log.debug("Removing bcd entry %s" % id)
     command = [bcdedit, '/delete', id , '/f']
     try:
         run_command(command)
         registry.set_value(
             'HKEY_LOCAL_MACHINE',
             self.info.registry_key,
             'VistaBootDrive',
             "")
     except Exception, err: #this shouldn't be fatal
         log.error(err)
Exemple #4
0
 def modify_bootini(self, drive, associated_task):
     log.debug("modify_bootini %s" % drive.path)
     bootini = join_path(drive.path, 'boot.ini')
     if not os.path.isfile(bootini):
         log.debug("Could not find boot.ini %s" % bootini)
         return
     src = join_path(self.info.root_dir, 'winboot', 'wisildr')
     dest = join_path(drive.path, 'wisildr')
     shutil.copyfile(src,  dest)
     src = join_path(self.info.root_dir, 'winboot', 'wisildr.mbr')
     dest = join_path(drive.path, 'wisildr.mbr')
     shutil.copyfile(src,  dest)
     run_command(['attrib', '-R', '-S', '-H', bootini])
     boot_line = 'C:\wisildr.mbr = "%s"' % self.info.distro.name
     old_line = boot_line[:boot_line.index("=")].strip().lower()
     # ConfigParser gets confused by the ':' and changes the options order
     content = read_file(bootini)
     if content[-1] != '\n':
         content += '\n'
     lines = content.split('\n')
     is_section = False
     for i,line in enumerate(lines):
         if line.strip().lower() == "[operating systems]":
             is_section = True
         elif line.strip().startswith("["):
             is_section = False
         if is_section and line.strip().lower().startswith(old_line):
             lines[i] = boot_line
             break
         if is_section and not line.strip():
             lines.insert(i, boot_line)
             break
     content = '\n'.join(lines)
     write_file(bootini, content)
     run_command(['attrib', '+R', '+S', '+H', bootini])
Exemple #5
0
    def modify_configsys(self, drive, associated_task):
        log.debug("modify_configsys %s" % drive.path)
        configsys = join_path(drive.path, 'config.sys')
        if not os.path.isfile(configsys):
            return
        src = join_path(self.info.root_dir, 'winboot', 'wisildr.exe')
        dest = join_path(drive.path, 'wisildr.exe')
        shutil.copyfile(src, dest)
        run_command(['attrib', '-R', '-S', '-H', configsys])
        config = read_file(configsys)
        if 'REM WUBI MENU START\n' in config:
            log.debug("Configsys has already been modified")
            return

        config += '''
        REM WUBI MENU START
        [menu]
        menucolor=15,0
        menuitem=windows,Windows
        menuitem=wisildr,$distro
        menudefault=windows,10
        [wisildr]
        device=wisildr.exe
        [windows]

        REM WUBI MENU END
        '''
        write_file(configsys, config)
        run_command(['attrib', '+R', '+S', '+H', configsys])
Exemple #6
0
 def expand_diskimage(self, associated_task=None):
     # TODO: might use -p to get percentage to feed into progress.
     root = join_path(self.info.disks_dir, 'root.disk')
     resize2fs = join_path(self.info.bin_dir, 'resize2fs.exe')
     resize_cmd = [resize2fs, '-f', root,
                   '%dM' % self.info.root_size_mb]
     run_command(resize_cmd)
Exemple #7
0
 def extract_file_from_iso(self,
                           iso_path,
                           file_path,
                           output_dir=None,
                           overwrite=False):
     '''
     platform specific
     '''
     log.debug("  extracting %s from %s" % (file_path, iso_path))
     if not iso_path or not os.path.exists(iso_path):
         raise Exception('Invalid path %s' % iso_path)
     iso_path = abspath(iso_path)
     file_path = os.path.normpath(file_path)
     if not output_dir:
         output_dir = tempfile.gettempdir()
     output_file = join_path(output_dir, os.path.basename(file_path))
     if os.path.exists(output_file):
         if overwrite:
             os.unlink(output_file)
         else:
             raise Exception('Cannot overwrite %s' % output_file)
     command = [
         self.info.iso_extractor, 'e', '-i!' + file_path, '-o' + output_dir,
         iso_path
     ]
     try:
         run_command(command)
     except Exception, err:
         log.exception(err)
         output_file = None
Exemple #8
0
 def undo_bootini(self, drive, associated_task):
     log.debug("undo_bootini %s" % drive.path)
     bootini = join_path(drive.path, 'boot.ini')
     if not os.path.isfile(bootini):
         return
     run_command(['attrib', '-R', '-S', '-H', bootini])
     remove_line_in_file(bootini, 'c:\wisildr.mbr', ignore_case=True)
     run_command(['attrib', '+R', '+S', '+H', bootini])
Exemple #9
0
 def undo_bootini(self, drive, associated_task):
     log.debug("undo_bootini %s" % drive.path)
     bootini = join_path(drive.path, 'boot.ini')
     if not os.path.isfile(bootini):
         return
     run_command(['attrib', '-R', '-S', '-H', bootini])
     remove_line_in_file(bootini, 'c:\wisildr.mbr', ignore_case=True)
     run_command(['attrib', '+R', '+S', '+H', bootini])
Exemple #10
0
 def uncompress_target_dir(self, associated_task):
     if self.info.target_drive.is_fat():
         return
     try:
         command = ['compact', self.info.target_dir, '/U', '/A', '/F']
         run_command(command)
         command = ['compact', join_path(self.info.target_dir,'*.*'), '/U', '/A', '/F']
         run_command(command)
     except Exception, err:
         log.error(err)
Exemple #11
0
 def uncompress_files(self, associated_task):
     if self.info.target_drive.is_fat():
         return
     command1 = ['compact', join_path(self.info.install_boot_dir), '/U', '/A', '/F']
     command2 = ['compact', join_path(self.info.install_boot_dir,'*.*'), '/U', '/A', '/F']
     for command in [command1,command2]:
         log.debug(" ".join(command))
         try:
             run_command(command)
         except Exception, err:
             log.error(err)
Exemple #12
0
 def uncompress_target_dir(self, associated_task):
     if self.info.target_drive.is_fat():
         return
     try:
         command = ['compact', self.info.target_dir, '/U', '/A', '/F']
         run_command(command)
         command = [
             'compact',
             join_path(self.info.target_dir, '*.*'), '/U', '/A', '/F'
         ]
         run_command(command)
     except Exception, err:
         log.error(err)
Exemple #13
0
 def undo_configsys(self, drive, associated_task):
     log.debug("undo_configsys %s" % drive)
     configsys = join_path(drive.path, 'config.sys')
     if not os.path.isfile(configsys):
         return
     run_command(['attrib', '-R', '-S', '-H', configsys])
     config = read_file(configsys)
     s = config.find('REM WUBI MENU START\n')
     e = config.find('REM WUBI MENU END\n')
     if s > 0 and e > 0:
         e += len('REM WUBI MENU END')
     config = config[:s] + config[e:]
     write_file(configsys, config)
     run_command(['attrib', '+R', '+S', '+H', configsys])
Exemple #14
0
 def undo_configsys(self, drive, associated_task):
     log.debug("undo_configsys %s" % drive)
     configsys = join_path(drive.path, 'config.sys')
     if not os.path.isfile(configsys):
         return
     run_command(['attrib', '-R', '-S', '-H', configsys])
     config = read_file(configsys)
     s = config.find('REM WUBI MENU START\n')
     e = config.find('REM WUBI MENU END\n')
     if s > 0 and e > 0:
         e += len('REM WUBI MENU END')
     config = config[:s] + config[e:]
     write_file(configsys, config)
     run_command(['attrib', '+R', '+S', '+H', configsys])
Exemple #15
0
 def uncompress_files(self, associated_task):
     if self.info.target_drive.is_fat():
         return
     command1 = [
         'compact',
         join_path(self.info.install_boot_dir), '/U', '/A', '/F'
     ]
     command2 = [
         'compact',
         join_path(self.info.install_boot_dir, '*.*'), '/U', '/A', '/F'
     ]
     for command in [command1, command2]:
         log.debug(" ".join(command))
         try:
             run_command(command)
         except Exception, err:
             log.error(err)
Exemple #16
0
 def get_iso_file_names(self, iso_path):
     iso_path = abspath(iso_path)
     if iso_path in self.cache:
         return self.cache[iso_path]
     else:
         self.cache[iso_path] = None
     command = [self.info.iso_extractor, 'l', iso_path]
     try:
         output = run_command(command)
     except Exception, err:
         log.exception(err)
         log.debug('command >>%s' % ' '.join(command))
         output = None
Exemple #17
0
 def get_iso_file_names(self, iso_path):
     iso_path = abspath(iso_path)
     if iso_path in self.cache:
         return self.cache[iso_path]
     else:
         self.cache[iso_path] = None
     command = [self.info.iso_extractor,'l',iso_path]
     try:
         output = run_command(command)
     except Exception, err:
         log.exception(err)
         log.debug('command >>%s' % ' '.join(command))
         output = None
Exemple #18
0
 def extract_file_from_iso(self, iso_path, file_path, output_dir=None, overwrite=False):
     '''
     platform specific
     '''
     log.debug("  extracting %s from %s" % (file_path, iso_path))
     if not iso_path or not os.path.exists(iso_path):
         raise Exception('Invalid path %s' % iso_path)
     iso_path = abspath(iso_path)
     file_path = os.path.normpath(file_path)
     if not output_dir:
         output_dir = tempfile.gettempdir()
     output_file = join_path(output_dir, os.path.basename(file_path))
     if os.path.exists(output_file):
         if overwrite:
             os.unlink(output_file)
         else:
             raise Exception('Cannot overwrite %s' % output_file)
     command = [self.info.iso_extractor, 'e', '-i!' + file_path, '-o' + output_dir, iso_path]
     try:
         run_command(command)
     except Exception, err:
         log.exception(err)
         output_file = None
Exemple #19
0
 def undo_bcd(self, associated_task):
     bcdedit = join_path(os.getenv('SystemDrive'), 'bcdedit.exe')
     if not isfile(bcdedit):
         bcdedit = join_path(os.getenv('SystemRoot'), 'sysnative',
                             'bcdedit.exe')
     if not os.path.isfile(bcdedit):
         bcdedit = join_path(os.environ['systemroot'], 'System32',
                             'bcdedit.exe')
     if not os.path.isfile(bcdedit):
         log.error("Cannot find bcdedit")
         return
     id = registry.get_value('HKEY_LOCAL_MACHINE', self.info.registry_key,
                             'VistaBootDrive')
     if not id:
         log.debug("Could not find bcd id")
         return
     log.debug("Removing bcd entry %s" % id)
     command = [bcdedit, '/delete', id, '/f']
     try:
         run_command(command)
         registry.set_value('HKEY_LOCAL_MACHINE', self.info.registry_key,
                            'VistaBootDrive', "")
     except Exception, err:  #this shouldn't be fatal
         log.error(err)
Exemple #20
0
 def reboot(self):
     command = ['shutdown', '-r', '-t', '00']
     run_command(command) #TBD make async
Exemple #21
0
    def modify_bcd(self, drive, associated_task):
        log.debug("modify_bcd %s" % drive)
        if drive is self.info.system_drive \
        or drive.path == "C:" \
        or drive.path == os.getenv('SystemDrive').upper():
            src = join_path(self.info.root_dir, 'winboot', 'wisildr')
            dest = join_path(drive.path, 'wisildr')
            shutil.copyfile(src, dest)
            src = join_path(self.info.root_dir, 'winboot', 'wisildr.mbr')
            dest = join_path(drive.path, 'wisildr.mbr')
            shutil.copyfile(src, dest)
        bcdedit = join_path(os.getenv('SystemDrive'), 'bcdedit.exe')
        if not os.path.isfile(bcdedit):
            bcdedit = join_path(os.environ['systemroot'], 'sysnative',
                                'bcdedit.exe')
        # FIXME: Just test for bcdedit in the PATH.  What's the Windows
        # equivalent of `type`?
        if not os.path.isfile(bcdedit):
            bcdedit = join_path(os.environ['systemroot'], 'System32',
                                'bcdedit.exe')
        if not os.path.isfile(bcdedit):
            log.error("Cannot find bcdedit")
            return
        if registry.get_value('HKEY_LOCAL_MACHINE', self.info.registry_key,
                              'VistaBootDrive'):
            log.debug("BCD has already been modified")
            return

        command = [
            bcdedit, '/create', '/d',
            '%s' % self.info.distro.name, '/application', 'bootsector'
        ]
        id = run_command(command)
        id = id[id.index('{'):id.index('}') + 1]
        mbr_path = join_path(self.info.target_dir, 'winboot',
                             'wisildr.mbr')[2:]
        run_command([
            bcdedit, '/set', id, 'device',
            'partition=%s' % self.info.target_drive.path
        ])
        run_command([bcdedit, '/set', id, 'path', mbr_path])
        run_command([bcdedit, '/displayorder', id, '/addlast'])
        run_command([bcdedit, '/timeout', '10'])
        run_command([bcdedit, '/bootsequence', id])
        registry.set_value('HKEY_LOCAL_MACHINE', self.info.registry_key,
                           'VistaBootDrive', id)
Exemple #22
0
 def create_swap_diskimage(self, associated_task=None):
     path = join_path(self.info.disks_dir, 'swap.disk')
     # fsutil works in bytes.
     swap_size = '%d' % (self.info.swap_size_mb * 1024 * 1024)
     create_cmd = ['fsutil', 'file', 'createnew', path, swap_size]
     run_command(create_cmd)
Exemple #23
0
    def modify_bcd(self, drive, associated_task):
        log.debug("modify_bcd %s" % drive)
        if drive is self.info.system_drive \
        or drive.path == "C:" \
        or drive.path == os.getenv('SystemDrive').upper():
            src = join_path(self.info.root_dir, 'winboot', 'wisildr')
            dest = join_path(drive.path, 'wisildr')
            shutil.copyfile(src,  dest)
            src = join_path(self.info.root_dir, 'winboot', 'wisildr.mbr')
            dest = join_path(drive.path, 'wisildr.mbr')
            shutil.copyfile(src,  dest)
        bcdedit = join_path(os.getenv('SystemDrive'), 'bcdedit.exe')
        if not os.path.isfile(bcdedit):
            bcdedit = join_path(os.environ['systemroot'], 'sysnative', 'bcdedit.exe')
        # FIXME: Just test for bcdedit in the PATH.  What's the Windows
        # equivalent of `type`?
        if not os.path.isfile(bcdedit):
            bcdedit = join_path(os.environ['systemroot'], 'System32', 'bcdedit.exe')
        if not os.path.isfile(bcdedit):
            log.error("Cannot find bcdedit")
            return
        if registry.get_value('HKEY_LOCAL_MACHINE', self.info.registry_key, 'VistaBootDrive'):
            log.debug("BCD has already been modified")
            return

        command = [bcdedit, '/create', '/d', '%s' % self.info.distro.name, '/application', 'bootsector']
        id = run_command(command)
        id = id[id.index('{'):id.index('}')+1]
        mbr_path = join_path(self.info.target_dir, 'winboot', 'wisildr.mbr')[2:]
        run_command([bcdedit, '/set', id, 'device', 'partition=%s' % self.info.target_drive.path])
        run_command([bcdedit, '/set', id, 'path', mbr_path])
        run_command([bcdedit, '/displayorder', id, '/addlast'])
        run_command([bcdedit, '/timeout', '10'])
        run_command([bcdedit, '/bootsequence', id])
        registry.set_value(
            'HKEY_LOCAL_MACHINE',
            self.info.registry_key,
            'VistaBootDrive',
            id)
Exemple #24
0
 def create_swap_diskimage(self, associated_task=None):
     path = join_path(self.info.disks_dir, 'swap.disk')
     # fsutil works in bytes.
     swap_size = '%d' % (self.info.swap_size_mb * 1024 * 1024)
     create_cmd = ['fsutil', 'file', 'createnew', path, swap_size]
     run_command(create_cmd)
Exemple #25
0
 def expand_diskimage(self, associated_task=None):
     # TODO: might use -p to get percentage to feed into progress.
     root = join_path(self.info.disks_dir, 'root.disk')
     resize2fs = join_path(self.info.bin_dir, 'resize2fs.exe')
     resize_cmd = [resize2fs, '-f', root, '%dM' % self.info.root_size_mb]
     run_command(resize_cmd)
Exemple #26
0
 def reboot(self):
     command = ['shutdown', '-r', '-t', '00']
     run_command(command)  #TBD make async