|
在anaconda的主程序中,定义了如下的一个python类。 理解面对对象,如果是从C++或java过来的人,对于python定义类的方式,是有点不"感冒“的,就像是对于python的缩进一样。
class Anaconda: #类定义,关键字class.默认为object. def __init__(self): #定义构造器 self.intf = None #设置intf self.dir = None #设置 dir self.id = None #设置 ID self.method = None #设置method self.methodstr = None #设置methodstr self.backend = None #设置backend self.rootPath = None #设置rootpath self.dispatch = None #设置dispatch self.isKickstart = False #是否是kickstart安装 self.rescue_mount = True #是否是救援模式的mount已有的根目录 self.rescue = False #是否救援模式 self.updateSrc = None #设置升级源updateSrc
def setDispatch(self): #定义方法setDispatch self.dispatch = dispatch.Dispatcher(self) #dispatch的方法实现 def setInstallInterface(self, display_mode): #定义方法设置安装界面,传入参数display_mode # setup links required by graphical mode if installing and verify display mode if display_mode == 'g': #如果获得参数为图形方式 stdoutLog.info (_("Starting graphical installation...")) #安装时最常见的输出。 if not flags.test and flags.setupFilesystems: #调用flag模块函数。 setupGraphicalLinks() #调用函数
try: #定义异常 from gui import InstallInterface except Exception, e: #异常抛出,java的程序员应该不陌生。 stdoutLog.error("Exception starting GUI installer: %s" %(e,))#标准输出 if flags.test: #模块flag的调用,设置为条件 sys.exit(1) #退出 # if we're not going to really go into GUI mode, we need to get # back to vc1 where the text install is going to pop up. if not x_already_set: isys.vtActivate (1) stdoutLog.warning("GUI installer startup failed, falling back to text mode.") display_mode = 't' #传入参数t if 'DISPLAY' in os.environ.keys(): del os.environ['DISPLAY'] time.sleep(2) #暂停两秒 if display_mode == 't': from text import InstallInterface if not os.environ.has_key("LANG"): os.environ["LANG"] = "en_US.UTF-8"
if display_mode == 'c': #命令行模式安装 from cmdline import InstallInterface #从InstallInterface模块中调用cmdline方法或函数
self.intf = InstallInterface() #对象实例化intf为InstallInterface,便于以后引用
def setMethod(self): #定义安装介质的方法,以下*InstallMethod均在别处定义的类的实例 if self.methodstr.startswith('cdrom://'): #从anaconda实例中截取字符 from image import CdromInstallMethod self.method = CdromInstallMethod(self.methodstr, self.rootPath, self.intf) elif self.methodstr.startswith('nfs:/'): from image import NfsInstallMethod self.method = NfsInstallMethod(self.methodstr, self.rootPath, self.intf) elif self.methodstr.startswith('nfsiso:/'): from image import NfsIsoInstallMethod self.method = NfsIsoInstallMethod(self.methodstr, self.rootPath, self.intf) elif self.methodstr.startswith('ftp://') or self.methodstr.startswith('http://'): from urlinstall import UrlInstallMethod self.method = UrlInstallMethod(self.methodstr, self.rootPath, self.intf) elif self.methodstr.startswith('hd://'): #硬盘安装 from harddrive import HardDriveInstallMethod self.method = HardDriveInstallMethod(self.methodstr, self.rootPath, self.intf) else: self.method = None
这是一个没有实例化的类。但是整个anaconda程序有着无数次的实例在里面。以后会看到的。但是我们可以看到决定的安装分类,图形、文本、命令的按照界面以及cdrom\nfs\http\hd等按照安装介质的分类。 在此本人就不再说明,具体的实例化了,以免造成断章取义。
|