免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2599 | 回复: 0
打印 上一主题 下一主题

anaconda对python字典的运用(一)定义安装步骤的数据结构类 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-11-29 15:40 |只看该作者 |倒序浏览
在图形安装方式下,定义步骤时,在gui.py中有如下一个字典。
stepToClass = {
    "language" : ("language_gui", "LanguageWindow"),
    "agreement" : ("agreement_gui", "AgreementWindow"),
    "keyboard" : ("keyboard_gui", "KeyboardWindow"),
    "mouse" : ("mouse_gui", "MouseWindow"),
    "welcome" : ("welcome_gui", "WelcomeWindow"),
    "installtype" : ("installpath_gui", "InstallPathWindow"),
    "zfcpconfig" : ("zfcp_gui", "ZFCPWindow"),
    "partitionmethod" : ("partmethod_gui", "PartitionMethodWindow"),
    "partition" : ("partition_gui", "PartitionWindow"),
    "autopartition" : ("partition_gui", "AutoPartitionWindow"),
    "findinstall" : ("examine_gui", "UpgradeExamineWindow"),
    "addswap" : ("upgrade_swap_gui", "UpgradeSwapWindow"),
    "upgrademigratefs" : ("upgrade_migratefs_gui", "UpgradeMigrateFSWindow"),
    "fdisk" : ("fdisk_gui", "FDiskWindow"),
    "bootloader": ("bootloader_main_gui", "MainBootloaderWindow"),
    "bootloaderadvanced": ("bootloader_advanced_gui", "AdvancedBootloaderWindow"),
    "upgbootloader": ("upgrade_bootloader_gui", "UpgradeBootloaderWindow"),
    "network" : ("network_gui", "NetworkWindow"),
    "firewall" : ("firewall_gui", "FirewallWindow"),
    "timezone" : ("timezone_gui", "TimezoneWindow"),
    "accounts" : ("account_gui", "AccountWindow"),
    "authentication" : ("auth_gui", "AuthWindow"),
    "desktopchoice": ("desktop_choice_gui", "DesktopChoiceWindow"),
    "package-selection" : ("package_gui", "PackageSelectionWindow"),
    "indivpackage" : ("package_gui", "IndividualPackageSelectionWindow"),
    "dependencies" : ("dependencies_gui", "UnresolvedDependenciesWindow"),
    "videocard" : ("xconfig_gui", "XConfigWindow"),
    "monitor" : ("xconfig_gui", "MonitorWindow"),
    "xcustom" : ("xconfig_gui", "XCustomWindow"),
    "confirminstall" : ("confirm_gui", "InstallConfirmWindow"),
    "confirmupgrade" : ("confirm_gui", "UpgradeConfirmWindow"),
    "finishxconfig" : None,
    "install" : ("progress_gui", "InstallProgressWindow_NEW"),
    "bootdisk" : ("bootdisk_gui", "BootdiskWindow"),
    "complete" : ("congrats_gui", "CongratulationWindow"),
}
而要谈到以后的调用,我们还得从另外一个文件的列表说起:那就是disptch.py中的
installSteps = [
    ("welcome", ()),
    ("betanag", betaNagScreen, ("intf", "dir")),
    ("language", ("intf", "id")),
    ("agreement", ("intf", "id", "dispatch")),
    ("keyboard", ("id.instLanguage.getDefaultKeyboard()", "id.keyboard")),
    ("checkmonitorok", checkMonitorOK, ("id.monitor", "dispatch")),
    ("monitor", ("id.xsetup", "id.monitor", "intf")),
    ("setsanex", setSaneXSettings, ("id.xsetup",)),
    ("findrootparts", findRootParts, ("intf", "id", "dispatch", "dir", "instPath")),
    ("findinstall", ("dispatch", "intf", "id", "instPath")),
    ("installtype", ("dispatch", "id", "method", "intf")),
    ("zfcpconfig", ("id.zfcp", "id.diskset", "intf")),
    ("indexmark1", doNothing, ()),
    ("partitionmethod", ("id.partitions", "id.instClass")),
    ("partitionobjinit", partitionObjectsInitialize, ("id.diskset",
                                                      "id.partitions",
                                                      "dir", "intf")),
    ("partitionmethodsetup", partitionMethodSetup, ("id.partitions",
                                                    "dispatch")),
    ("autopartition", ("id.diskset", "id.partitions", "intf", "dispatch")),
    ("autopartitionexecute", doAutoPartition, ("dir", "id.diskset",
                                               "id.partitions", "intf",
                                               "id.instClass", "dispatch")),
    ("fdisk", ("id.diskset", "id.partitions", "intf")),
    ("fdasd", ("id.diskset", "id.partitions", "intf")),
    ("partition", ("id.fsset", "id.diskset", "id.partitions", "intf")),
    ("upgrademount", upgradeMountFilesystems, ("intf", "id.upgradeRoot",
                                               "id.fsset", "instPath")),
    ("upgradecontinue", queryUpgradeContinue, ("intf", "dir")),
    ("upgradeswapsuggestion", upgradeSwapSuggestion, ("dispatch", "id",
                                                      "instPath")),
    ("addswap", ("intf", "id.fsset", "instPath",
                 "id.upgradeSwapInfo", "dispatch")),
    ("partitiondone", partitioningComplete, ("id.bootloader", "id.fsset",
                                             "id.diskset", "id.partitions",
                                             "intf", "instPath", "dir")),
    ("upgrademigfind", upgradeMigrateFind, ("dispatch", "id.fsset")),
    ("upgrademigratefs",  ("id.fsset",)),
    ("upgbootloader", ("dispatch", "id.bootloader")),
    ("bootloadersetup", bootloaderSetupChoices, ("dispatch", "id.bootloader",
                                                 "id.fsset", "id.diskset",
                                                 "dir")),
    ("bootloader", ("dispatch", "id.bootloader", "id.fsset", "id.diskset")),
    ("bootloaderadvanced", ("dispatch", "id.bootloader", "id.fsset",
                            "id.diskset")),
    ("networkdevicecheck", networkDeviceCheck, ("id.network", "dispatch")),
    ("network", ("id.network", "dir", "intf", "id")),
    ("firewall", ("intf", "id.network", "id.firewall", "id.security")),
    ("timezone", ("id.instLanguage", "id.timezone")),
    ("accounts", ("intf", "id.rootPassword")),
    ("authentication", ("id.auth",)),
    ("readcomps", readPackages, ("intf", "method", "id")),
    ("desktopchoice", ("intf", "id.instClass", "dispatch", "id.grpset")),
    ("findpackages", upgradeFindPackages, ("intf", "method", "id",
                                           "instPath", "dir")),
    ("selectlangpackages", selectLanguageSupportGroups, ("id.grpset","id.instLanguage")),   
    ("package-selection", ("id.grpset", "id.instLanguage", "id.instClass", "dispatch")),
    ("indivpackage", ("id.grpset",)),
    ("handleX11pkgs", handleX11Packages, ("dir", "intf", "dispatch",
                                          "id", "instPath")),
    ("handlemiscpkgs", handleMiscPackages, ("intf", "id", "dir")),
    ("fixupconditionals", fixupConditionals, ("id.grpset",)),
    ("checkdeps", checkDependencies, ("dir", "intf", "dispatch",
                                      "id", "instPath")),
    ("dependencies", ("id.grpset", "id.dependencies")),
    ("confirminstall", ("intf", "id",)),
    ("confirmupgrade", ("intf", "id",)),
    ("indexmark2", doNothing, ()),
    ("install", ("dir", "intf", "id")),
    ("enablefilesystems", turnOnFilesystems, ("dir", "id.fsset",
                                              "id.diskset", "id.partitions",
                                              "id.upgrade", "instPath")),
    ("migratefilesystems", doMigrateFilesystems, ("dir", "id.fsset",
                                              "id.diskset", "id.upgrade",
                                              "instPath")),
    ("setuptime", setupTimezone, ("id.timezone", "id.upgrade", "instPath",
                                  "dir")),
    ("preinstallconfig", doPreInstall, ("method", "id", "intf", "instPath",
                                        "dir")),
    ("installpackages", doInstall, ("method", "id", "intf", "instPath")),
    ("postinstallconfig", doPostInstall, ("method", "id", "intf", "instPath")),
    ("writeconfig", writeConfiguration, ("id", "instPath")),
    ("firstboot", firstbootConfiguration, ("id", "instPath")),
    ("instbootloader", writeBootloader, ("intf", "instPath", "id.fsset",
                                         "id.bootloader", "id.instLanguage",
                                         "id.grpset")),
    ("bootdisk", ("dir", "dispatch", "id.fsset")),
    ("makebootdisk", makeBootdisk, ("intf", "dir", "id.floppyDevice",
                                    "id.grpset", "instPath", "id.bootloader")),
#
# we dont use videocard and xcustom currently, they are still listed as
# steps but are not listed in the list of install steps in installclass.py
#   
    ("videocard", ("dispatch", "id.xsetup", "id.videocard", "intf")),
#   
# this got moved up to just after mouse config, only runs if monitor probe
# failed. Needs to be here if we enable videocard and xcustom again.
#    ("monitor", ("id.xsetup", "id.monitor", "intf")),
    ("xcustom", ("id.xsetup", "id.monitor", "id.videocard",
                 "id.desktop", "id.grpset", "id.instClass", "instPath")),
    ("writexconfig", writeXConfiguration, ("id", "instPath")),
    ("writeksconfig", writeKSConfiguration, ("id", "instPath")),
    ("setfilecon", setFileCons, ("instPath","id.partitions")),
    ("copylogs", copyAnacondaLogs, ("instPath",)),
    ("dopostaction", doPostAction, ("id", "instPath", "intf")),
    ("methodcomplete", doMethodComplete, ("method", "id.fsset")),
    ("dopostpost",doPostpost, ("method","id")),
    ("complete", ("intf", "id", "dispatch"))
    ]
同样在dispatch.py中实现了如下的方法:
def currentStep(self):
    if self.step == None:
        self.gotoNext()
    elif self.step >= len(installSteps):
        return (None, None)
    stepInfo = installSteps[self.step]
    step = stepInfo[0]
    args = self.bindArgs(stepInfo[1])
    return (step, args)
也就是说,当调用此方法时,它的返回返回值就是序列中的第一项,和一个元组。
来看gui.py中的一个调用此方法的方法:
def setScreen (self):
    (step, args) = self.dispatch.currentStep()  //这就是调用的所要求的返回值
    if step is None:      
        gtk.main_quit()          //如果序列中不存在此项,则直接崩溃。
        return
   
        if self.dir == 1:
        return self.nextClicked()
        else:
        return self.prevClicked()
        
    (file, className) = stepToClass[step]        //这是对字典的操作,即去查询序列的第一项里是否是字典的key值。
        newScreenClass = None
    s = "from %s import %s; newScreenClass = %s" % (file, className,
                                                        className)
        #print s
        while 1:
            try:
                exec s
                break
            except ImportError, e:
                print e
                win = MessageWindow(_("Error!"),
                                   _("An error occurred when attempting "
                                     "to load an installer interface "
                                     "component.\n\nclassName = %s") % (className,),
                                    type="custom", custom_icon="warning",
                                    custom_buttons=[_("_Exit"),
                                                    _("_Retry")])  //如果不存在,则会报这么一个错误。
                if not win.getrc():
                    if flags.rootpath:
                        msg =  _("The installer will now exit...")
                        buttons = [_("_Exit")]
                    else:
                        msg =  _("Your system will now be rebooted...")
                        buttons = [_("_Reboot")]
                    MessageWindow(_("Rebooting System"),
                                  msg,
                                  type="custom",
                                  custom_icon="warning",
                                  custom_buttons=buttons)
                    sys.exit(0)
这个字典一直运行在anaconda的生命周期中。应当去注意它的无处不在。
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/6303/showart_1671909.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP