• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.run_command函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wubi.backends.common.utils.run_command函数的典型用法代码示例。如果您正苦于以下问题:Python run_command函数的具体用法?Python run_command怎么用?Python run_command使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了run_command函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: expand_diskimage

 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)
开发者ID:Karho,项目名称:mint4win,代码行数:7,代码来源:backend.py


示例2: modify_bootini

 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])
开发者ID:Karho,项目名称:mint4win,代码行数:35,代码来源:backend.py


示例3: modify_configsys

    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])
开发者ID:Karho,项目名称:mint4win,代码行数:29,代码来源:backend.py


示例4: undo_bcd

 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)
开发者ID:Karho,项目名称:mint4win,代码行数:27,代码来源:backend.py


示例5: undo_bootini

 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:\wubildr.mbr', ignore_case=True)
     run_command(['attrib', '+R', '+S', '+H', bootini])
开发者ID:Karho,项目名称:mint4win,代码行数:8,代码来源:backend.py


示例6: uncompress_target_dir

 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)
开发者ID:Karho,项目名称:mint4win,代码行数:10,代码来源:backend.py


示例7: uncompress_files

 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)
开发者ID:Karho,项目名称:mint4win,代码行数:11,代码来源:backend.py


示例8: undo_bootloader

 def undo_bootloader(self, associated_task):
     winboot_files = ['yldr', 'yldr.mbr', 'yldrd', 'yldrd.mbr']
     self.undo_bcd(associated_task)
     for drive in self.info.drives:
         if drive.type not in ('removable', 'hd'):
             continue
         self.undo_bootini(drive, associated_task)
         #self.undo_configsys(drive, associated_task)
         for f in winboot_files:
             f = join_path(drive.path, f)
             if os.path.isfile(f):
                 run_command(['attrib', '-R', '-S', '-H', f])
                 os.unlink(f)
开发者ID:hechaoyuyu,项目名称:swinst,代码行数:13,代码来源:backend.py


示例9: undo_configsys

 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])
开发者ID:Karho,项目名称:mint4win,代码行数:14,代码来源:backend.py


示例10: extract_file_from_iso

    def extract_file_from_iso(self, iso_path, file_path, output_dir=None, overwrite=True):
        '''
        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))
        log.debug("output_file === %s" %output_file)

        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]
        log.debug("command === %s" % command)
        try:
            output = run_command(command)
        except Exception, err:
            log.exception(err)
            output_file = None
开发者ID:hechaoyuyu,项目名称:swinst,代码行数:26,代码来源:backend.py


示例11: undo_bootloader

    def undo_bootloader(self, associated_task):
        winboot_files = ['wubildr', 'wubildr.mbr', 'wubildr.exe']
        self.undo_bcd(associated_task)
        for drive in self.info.drives:
            if drive.type not in ('removable', 'hd'):
                continue
            self.undo_bootini(drive, associated_task)
            self.undo_configsys(drive, associated_task)
            for f in winboot_files:
                f = join_path(drive.path, f)
                if os.path.isfile(f):
                    os.unlink(f)

        if self.info.efi:
            log.debug("Undo EFI boot")
            self.undo_EFI_folder(associated_task) 
            run_command(['powercfg', '/h', 'on'])
开发者ID:Ando02,项目名称:wubiuefi,代码行数:17,代码来源:backend.py


示例12: undo_EFI_folder

 def undo_EFI_folder(self, associated_task):
     for efi_drive in 'HIJKLMNOPQRSTUVWXYZ':
         drive = Drive(efi_drive)
         if not drive.type:
             break
     efi_drive = efi_drive + ':'
     log.debug("Temporary EFI drive %s" % efi_drive)
     try: 
         run_command(['mountvol', efi_drive, '/s'])
         dest = join_path(efi_drive, 'EFI',self.info.previous_target_dir[3:],'wubildr')
         dest.replace(' ', '_')
         dest.replace('__', '_')
         if os.path.exists(dest):
             log.debug('Removing EFI folder %s' % dest)
             shutil.rmtree(dest)
         run_command(['mountvol', efi_drive, '/d'])
     except Exception, err: #this shouldn't be fatal
         log.error(err)            
开发者ID:Ando02,项目名称:wubiuefi,代码行数:18,代码来源:backend.py


示例13: modify_EFI_folder

 def modify_EFI_folder(self, associated_task,bcdedit):
     command = [bcdedit, '/enum', '{bootmgr}']
     boot_drive = run_command(command)
     if 'partition=' in boot_drive:
         boot_drive = boot_drive[boot_drive.index('partition=')+10:]
     else:
         boot_drive = boot_drive[boot_drive.index('device')+24:]
     boot_drive = boot_drive[:boot_drive.index('\r')]
     log.debug("EFI boot partition %s" % boot_drive)
     # if EFI boot partition is mounted we use it
     if boot_drive[1]==':':
         efi_drive = boot_drive
     else:
         for efi_drive in 'HIJKLMNOPQRSTUVWXYZ':
             drive = Drive(efi_drive)
             if not drive.type:
                 break
         efi_drive = efi_drive + ':'
         log.debug("Temporary EFI drive %s" % efi_drive)
     if efi_drive != boot_drive:
         run_command(['mountvol', efi_drive, '/s'])
     src = join_path(self.info.root_dir, 'winboot','EFI')
     src.replace(' ', '_')
     src.replace('__', '_')
     dest = join_path(efi_drive, 'EFI',self.info.target_dir[3:])
     dest.replace(' ', '_')
     dest.replace('__', '_')
     if not os.path.exists(dest):
         shutil.os.mkdir(dest)
     dest = join_path(dest,'wubildr')
     if os.path.exists(dest):
         shutil.rmtree(dest)        
     log.debug('Copying EFI folder %s -> %s' % (src, dest))
     shutil.copytree(src,  dest)
     if self.get_efi_arch(associated_task,efi_drive)=="ia32":
         efi_path = join_path(dest, 'grubia32.efi')[2:]
     else:
         efi_path = join_path(dest, 'shimx64.efi')[2:]
     if efi_drive != boot_drive:
         run_command(['mountvol', efi_drive, '/d'])
     return efi_path
开发者ID:Ando02,项目名称:wubiuefi,代码行数:41,代码来源:backend.py


示例14: get_iso_file_names

 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
开发者ID:Karho,项目名称:mint4win,代码行数:13,代码来源:backend.py


示例15: modify_bcd

    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', '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)
        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', 'wubildr.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'])
        registry.set_value(
            'HKEY_LOCAL_MACHINE',
            self.info.registry_key,
            'VistaBootDrive',
            id)
开发者ID:isek,项目名称:mint4win,代码行数:38,代码来源:backend.py


示例16: check_EFI

 def check_EFI(self):
     efi = False
     if self.info.bootloader == 'vista':
         bcdedit = join_path(os.getenv('SystemDrive'), 'bcdedit.exe')
         if not os.path.isfile(bcdedit):
             bcdedit = join_path(os.environ['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 False
         command = [bcdedit, '/enum']
         result = run_command(command)
         result = result.lower()
         if "bootmgfw.efi" in result:
             efi = True
         if "winload.efi" in result:
             efi = True
     log.debug('EFI boot = %s' % efi)
     return efi
开发者ID:pombredanne,项目名称:wubi-1,代码行数:20,代码来源:backend.py


示例17: modify_bcd

    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():
            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])

        if self.info.run_task == "cd_boot":
            mbr_path = join_path(self.info.target_dir, 'winboot', 'yldrd.mbr')[2:]
        elif self.info.flag:
            mbr_path = join_path(self.info.target_dir, 'winboot', 'yldr.mbr')[2:]
        else:
            mbr_path = join_path(self.info.target_dir, 'winboot', 'yldrd.mbr')[2:]

        bcdedit = join_path(os.getenv('SystemDrive'), 'bcdedit.exe')
        if not os.path.isfile(bcdedit):
            bcdedit = join_path(os.environ['systemroot'], 'System32', 'bcdedit.exe')
        if not os.path.isfile(bcdedit):
            bcdedit = join_path(os.environ['systemroot'], 'sysnative', '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
        if self.info.run_task == "cd_boot":
            command = [bcdedit, '/create', '/d', '%s LiveCD' % self.info.distro.name, '/application', 'bootsector']
        elif self.info.flag:
            command = [bcdedit, '/create', '/d', '%s' % self.info.distro.name, '/application', 'bootsector']
        else:
            command = [bcdedit, '/create', '/d', '%s LiveCD' % self.info.distro.name, '/application', 'bootsector']
        log.debug("run command %s" %command)
        id = run_command(command)
        id = id[id.index('{'):id.index('}')+1]
        #mbr_path = self.info.flag and join_path(self.info.target_dir, 'winboot', 'yldr.mbr')[2:] or join_path(self.info.target_dir, 'winboot', 'yldrd.mbr')[2:]
        ##print mbr_path
        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'])
        registry.set_value(
            'HKEY_LOCAL_MACHINE',
            self.info.registry_key,
            'VistaBootDrive',
            id)
开发者ID:hechaoyuyu,项目名称:swinst,代码行数:73,代码来源:backend.py


示例18: modify_bcd

    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', '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)
        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

        if self.info.efi:
            log.debug("EFI boot")
            efi_path = self.modify_EFI_folder(associated_task,bcdedit)
            run_command(['powercfg', '/h', 'off'])
            command = [bcdedit, '/copy', '{bootmgr}', '/d', '%s' % self.info.distro.name]
            id = run_command(command)
            id = id[id.index('{'):id.index('}')+1]
            run_command([bcdedit, '/set', id, 'path', efi_path])
            try:
                run_command([bcdedit, '/set', '{fwbootmgr}', 'displayorder', id, '/addlast'])
                run_command([bcdedit, '/set', '{fwbootmgr}', 'timeout', '10'])
                run_command([bcdedit, '/set', '{fwbootmgr}', 'bootsequence', id])
            except Exception, err: #this shouldn't be fatal
                log.error(err)
            registry.set_value(
                'HKEY_LOCAL_MACHINE',
                self.info.registry_key,
                'VistaBootDrive',
                id)
            return
开发者ID:Ando02,项目名称:wubiuefi,代码行数:45,代码来源:backend.py


示例19: create_swap_diskimage

 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)
开发者ID:Karho,项目名称:mint4win,代码行数:6,代码来源:backend.py


示例20: modify_bootini

    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])
开发者ID:hechaoyuyu,项目名称:swinst,代码行数:93,代码来源:backend.py



注:本文中的wubi.backends.common.utils.run_command函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python base.render函数代码示例发布时间:2022-05-26
下一篇:
Python utils.join_path函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap