Example #1
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', 'wubildr.exe')
        dest = join_path(drive.path, 'wubildr.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=wubildr,$distro
        menudefault=windows,10
        [wubildr]
        device=wubildr.exe
        [windows]

        REM WUBI MENU END
        '''
        write_file(configsys, config)
        run_command(['attrib', '+R', '+S', '+H', configsys])
Example #2
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', 'wubildr')
     dest = join_path(drive.path, 'wubildr')
     shutil.copyfile(src,  dest)
     src = join_path(self.info.root_dir, 'winboot', 'wubildr.mbr')
     dest = join_path(drive.path, 'wubildr.mbr')
     shutil.copyfile(src,  dest)
     run_command(['attrib', '-R', '-S', '-H', bootini])
     boot_line = 'C:\wubildr.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])
Example #3
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', 'wubildr.exe')
        dest = join_path(drive.path, 'wubildr.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=wubildr,$distro
        menudefault=windows,10
        [wubildr]
        device=wubildr.exe
        [windows]

        REM WUBI MENU END
        '''
        write_file(configsys, config)
        run_command(['attrib', '+R', '+S', '+H', configsys])
Example #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', 'wubildr')
     dest = join_path(drive.path, 'wubildr')
     shutil.copyfile(src, dest)
     src = join_path(self.info.root_dir, 'winboot', 'wubildr.mbr')
     dest = join_path(drive.path, 'wubildr.mbr')
     shutil.copyfile(src, dest)
     run_command(['attrib', '-R', '-S', '-H', bootini])
     boot_line = 'C:\wubildr.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])
Example #5
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])
Example #6
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])
Example #7
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

        if self.info.run_task == "cd_boot":
            src = join_path(self.info.root_dir, 'winboot', 'yldrd')
        elif self.info.flag:
            src = join_path(self.info.root_dir, 'winboot', 'yldr')
        else:
            src = join_path(self.info.root_dir, 'winboot', 'yldrd')

        if self.info.run_task == "cd_boot":
            dest = join_path(drive.path, 'yldrd')
        elif self.info.flag:
            dest = join_path(drive.path, 'yldr')
        else:
            dest = join_path(drive.path, 'yldrd')
        shutil.copyfile(src,  dest)
        run_command(['attrib', '+R', '+S', '+H', dest])

        if self.info.run_task == "cd_boot":
            src = join_path(self.info.root_dir, 'winboot', 'yldrd.mbr')
        elif self.info.flag:
            src = join_path(self.info.root_dir, 'winboot', 'yldr.mbr')
        else:
            src = join_path(self.info.root_dir, 'winboot', 'yldrd.mbr')

        if self.info.run_task == "cd_boot":
            dest = join_path(drive.path, 'yldrd.mbr')
        elif self.info.flag:
            dest = join_path(drive.path, 'yldr.mbr')
        else:
            dest = join_path(drive.path, 'yldrd.mbr')
        shutil.copyfile(src,  dest)
        run_command(['attrib', '+R', '+S', '+H', dest])

        run_command(['attrib', '-R', '-S', '-H', bootini])

        if self.info.run_task == "cd_boot":
            boot_line = 'C:\yldrd.mbr = "%s LiveCD"' % self.info.distro.name
        elif self.info.flag:
            boot_line = 'C:\yldr.mbr = "%s"' % self.info.distro.name
        else:
            boot_line = 'C:\yldrd.mbr = "%s LiveCD"' % 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')
	boot_loader_pos = 0
	has_timeout = False
	has_boot_head = False
        is_section = False
        for i,line in enumerate(lines):
            if line.strip().lower() == "[operating systems]":
                is_section = True
     		continue
	    elif line.strip().lower() == "[boot loader]":
		has_boot_head = True
		boot_loader_pos = i
		continue
            elif line.strip().startswith("["):
                is_section  = False
     		continue
	    if  line.strip().lower().startswith("timeout"):
		if not has_boot_head: 
		    lines.remove(line)
	        else:
		    lines[i] = "timeout = 10"
		    has_timeout = True
	        continue
            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

	if not has_boot_head:
	    lines.insert(0,"[boot loader]")
	    lines.insert(1,"timeout = 10")
	elif not has_timeout:
	    lines.insert(boot_loader_pos+1, "timeout = 10")
        
        content = '\n'.join(lines)
        write_file(bootini, content)
        run_command(['attrib', '+R', '+S', '+H', bootini])