Package pyanaconda
[hide private]
[frames] | no frames]

Source Code for Package pyanaconda

  1  #!/usr/bin/python 
  2  # 
  3  # anaconda: The Red Hat Linux Installation program 
  4  # 
  5  # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 
  6  # Red Hat, Inc.  All rights reserved. 
  7  # 
  8  # This program is free software; you can redistribute it and/or modify 
  9  # it under the terms of the GNU General Public License as published by 
 10  # the Free Software Foundation; either version 2 of the License, or 
 11  # (at your option) any later version. 
 12  # 
 13  # This program is distributed in the hope that it will be useful, 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16  # GNU General Public License for more details. 
 17  # 
 18  # You should have received a copy of the GNU General Public License 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 20  # 
 21  # Author(s): Brent Fox <bfox@redhat.com> 
 22  #            Mike Fulbright <msf@redhat.com> 
 23  #            Jakub Jelinek <jakub@redhat.com> 
 24  #            Jeremy Katz <katzj@redhat.com> 
 25  #            Chris Lumens <clumens@redhat.com> 
 26  #            Paul Nasrat <pnasrat@redhat.com> 
 27  #            Erik Troan <ewt@rpath.com> 
 28  #            Matt Wilson <msw@rpath.com> 
 29  # 
 30   
 31  import os, time, string 
 32  import iutil 
 33  import isys 
 34  from constants import ROOT_PATH 
 35  from tempfile import mkstemp 
 36   
 37  import logging 
 38  log = logging.getLogger("anaconda") 
 39  stdoutLog = logging.getLogger("anaconda.stdout") 
 40   
 41  import gettext 
 42  _ = lambda x: gettext.ldgettext("anaconda", x) 
43 44 -class Anaconda(object):
45 - def __init__(self):
46 import desktop, dispatch, firewall, security 47 import system_config_keyboard.keyboard as keyboard 48 from flags import flags 49 50 self._backend = None 51 self._bootloader = None 52 self.canReIPL = False 53 self.desktop = desktop.Desktop() 54 self.dir = None 55 self.dispatch = dispatch.Dispatcher(self) 56 self.displayMode = None 57 self.extraModules = [] 58 self.firewall = firewall.Firewall() 59 self.id = None 60 self._instClass = None 61 self._instLanguage = None 62 self._intf = None 63 self.isHeadless = False 64 self.keyboard = keyboard.Keyboard() 65 self.ksdata = None 66 self.mediaDevice = None 67 self.methodstr = None 68 self._network = None 69 self.opts = None 70 self._platform = None 71 self.proxy = None 72 self.proxyUsername = None 73 self.proxyPassword = None 74 self.reIPLMessage = None 75 self.rescue = False 76 self.rescue_mount = True 77 self.rootParts = None 78 self.security = security.Security() 79 self.simpleFilter = not iutil.isS390() 80 self.stage2 = None 81 self._storage = None 82 self._timezone = None 83 self.updateSrc = None 84 self.upgrade = flags.cmdline.has_key("preupgrade") 85 self.upgradeRoot = None 86 self._users = None 87 self.mehConfig = None 88 self.clearPartTypeSelection = None # User's GUI selection 89 self.clearPartTypeSystem = None # System's selection 90 91 # *sigh* we still need to be able to write this out 92 self.xdriver = None
93 94 @property
95 - def backend(self):
96 if not self._backend: 97 b = self.instClass.getBackend() 98 self._backend = apply(b, (self, )) 99 100 return self._backend
101 102 @property
103 - def bootloader(self):
104 if not self._bootloader: 105 self._bootloader = self.platform._bootloaderClass(self.storage) 106 107 return self._bootloader
108 109 @property
110 - def firstboot(self):
111 from pykickstart.constants import FIRSTBOOT_DEFAULT 112 113 if self.ksdata: 114 return self.ksdata.firstboot.firstboot 115 else: 116 return FIRSTBOOT_DEFAULT
117 118 @property
119 - def instClass(self):
120 if not self._instClass: 121 from installclass import DefaultInstall 122 self._instClass = DefaultInstall() 123 124 return self._instClass
125 126 @property
127 - def instLanguage(self):
128 if not self._instLanguage: 129 import language 130 self._instLanguage = language.Language(self.displayMode) 131 132 return self._instLanguage
133
134 - def _getInterface(self):
135 return self._intf
136
137 - def _setInterface(self, v):
138 # "lambda cannot contain assignment" 139 self._intf = v
140
141 - def _delInterface(self):
142 del self._intf
143 144 intf = property(_getInterface, _setInterface, _delInterface) 145 146 @property
147 - def network(self):
148 if not self._network: 149 import network 150 self._network = network.Network() 151 152 return self._network
153 154 @property
155 - def platform(self):
156 if not self._platform: 157 from pyanaconda import platform 158 self._platform = platform.getPlatform(self) 159 160 return self._platform
161 162 @property
163 - def protected(self):
164 import stat 165 166 if os.path.exists("/dev/live") and \ 167 stat.S_ISBLK(os.stat("/dev/live")[stat.ST_MODE]): 168 return [os.readlink("/dev/live")] 169 elif self.methodstr and self.methodstr.startswith("hd:"): 170 method = self.methodstr[3:] 171 return [method.split(":", 3)[0]] 172 else: 173 return []
174 175 @property
176 - def users(self):
177 if not self._users: 178 import users 179 self._users = users.Users(self) 180 181 return self._users
182 183 @property
184 - def storage(self):
185 if not self._storage: 186 import storage 187 self._storage = storage.Storage(anaconda=self) 188 189 return self._storage
190 191 @property
192 - def timezone(self):
193 if not self._timezone: 194 import timezone 195 self._timezone = timezone.Timezone() 196 self._timezone.setTimezoneInfo(self.instLanguage.getDefaultTimeZone()) 197 198 return self._timezone
199
200 - def dumpState(self):
201 from meh.dump import ReverseExceptionDump 202 from inspect import stack as _stack 203 204 # Skip the frames for dumpState and the signal handler. 205 stack = _stack()[2:] 206 stack.reverse() 207 exn = ReverseExceptionDump((None, None, stack), self.mehConfig) 208 209 # dump to a unique file 210 (fd, filename) = mkstemp("", "anaconda-tb-", "/tmp") 211 fo = os.fdopen(fd, "w") 212 exn.write(self, fo) 213 fo.close() 214 215 #append to a given file 216 with open(filename, "r") as f: 217 content = f.readlines() 218 with open("/tmp/anaconda-tb-all.log", "a+") as f: 219 f.write("--- traceback: %s ---\n" % filename) 220 f.writelines(content)
221
222 - def initInterface(self):
223 if self._intf: 224 raise RuntimeError, "Second attempt to initialize the InstallInterface" 225 226 # setup links required by graphical mode if installing and verify display mode 227 if self.displayMode == 'g': 228 stdoutLog.info (_("Starting graphical installation.")) 229 230 try: 231 from gui import InstallInterface 232 except Exception as e: 233 from flags import flags 234 stdoutLog.error("Exception starting GUI installer: %s" %(e,)) 235 # if we're not going to really go into GUI mode, we need to get 236 # back to vc1 where the text install is going to pop up. 237 if not flags.livecdInstall: 238 isys.vtActivate (1) 239 stdoutLog.warning("GUI installer startup failed, falling back to text mode.") 240 self.displayMode = 't' 241 if 'DISPLAY' in os.environ.keys(): 242 del os.environ['DISPLAY'] 243 time.sleep(2) 244 245 if self.displayMode == 't': 246 from text import InstallInterface 247 if not os.environ.has_key("LANG"): 248 os.environ["LANG"] = "en_US.UTF-8" 249 250 if self.displayMode == 'r': 251 import rescue 252 InstallInterface = rescue.RescueInterface 253 254 if self.displayMode == 'c': 255 from cmdline import InstallInterface 256 257 if self.displayMode == 's': 258 from script import InstallInterface 259 260 self._intf = InstallInterface() 261 return self._intf
262
263 - def writeXdriver(self, root = None):
264 # this should go away at some point, but until it does, we 265 # need to keep it around. 266 if self.xdriver is None: 267 return 268 if root is None: 269 root = ROOT_PATH 270 if not os.path.isdir("%s/etc/X11" %(root,)): 271 os.makedirs("%s/etc/X11" %(root,), mode=0755) 272 f = open("%s/etc/X11/xorg.conf" %(root,), 'w') 273 f.write('Section "Device"\n\tIdentifier "Videocard0"\n\tDriver "%s"\nEndSection\n' % self.xdriver) 274 f.close()
275
276 - def setMethodstr(self, methodstr):
277 if methodstr.startswith("cdrom://"): 278 (device, tree) = string.split(methodstr[8:], ":", 1) 279 280 if not tree.startswith("/"): 281 tree = "/%s" %(tree,) 282 283 if device.startswith("/dev/"): 284 device = device[5:] 285 286 self.mediaDevice = device 287 self.methodstr = "cdrom://%s" % tree 288 else: 289 self.methodstr = methodstr
290
291 - def write(self):
292 self.writeXdriver() 293 self.instLanguage.write() 294 295 self.timezone.write() 296 if not self.ksdata: 297 self.instClass.setNetworkOnbootDefault(self.network) 298 self.network.write() 299 self.network.copyConfigToPath() 300 self.network.disableNMForStorageDevices(self) 301 self.network.autostartFCoEDevices(self) 302 self.desktop.write() 303 self.users.write() 304 self.security.write() 305 self.firewall.write() 306 307 services = list(self.storage.services) 308 309 if self.ksdata: 310 for svc in self.ksdata.services.disabled: 311 iutil.execWithRedirect("/sbin/chkconfig", 312 [svc, "off"], 313 stdout="/dev/tty5", stderr="/dev/tty5", 314 root=ROOT_PATH) 315 316 services.extend(self.ksdata.services.enabled) 317 318 for svc in services: 319 iutil.execWithRedirect("/sbin/chkconfig", 320 [svc, "on"], 321 stdout="/dev/tty5", stderr="/dev/tty5", 322 root=ROOT_PATH)
323
324 - def writeKS(self, filename):
325 import urllib 326 from pykickstart.version import versionToString, DEVEL 327 from flags import flags 328 329 f = open(filename, "w") 330 331 f.write("# Kickstart file automatically generated by anaconda.\n\n") 332 f.write("#version=%s\n" % versionToString(DEVEL)) 333 334 if self.upgrade: 335 f.write("upgrade\n") 336 else: 337 f.write("install\n") 338 339 m = None 340 341 if self.methodstr: 342 m = self.methodstr 343 elif self.stage2: 344 m = self.stage2 345 346 if m: 347 if m.startswith("cdrom:"): 348 f.write("cdrom\n") 349 elif m.startswith("hd:"): 350 if m.count(":") == 3: 351 (part, fs, dir) = string.split(m[3:], ":") 352 else: 353 (part, dir) = string.split(m[3:], ":") 354 355 f.write("harddrive --partition=%s --dir=%s\n" % (part, dir)) 356 elif m.startswith("nfs:"): 357 if m.count(":") == 3: 358 (opts, server, dir) = string.split(m[4:], ":") 359 f.write("nfs --server=%s --opts=%s --dir=%s\n" % (server, opts, dir)) 360 else: 361 (server, dir) = string.split(m[4:], ":") 362 f.write("nfs --server=%s --dir=%s\n" % (server, dir)) 363 elif m.startswith("ftp://") or m.startswith("http"): 364 ssl = "" 365 if flags.noverifyssl: 366 ssl = " --noverifyssl" 367 f.write("url --url=%s%s\n" % (urllib.unquote(m), ssl)) 368 369 # Some kickstart commands do not correspond to any anaconda UI 370 # component. If this is a kickstart install, we need to make sure 371 # the information from the input file ends up in the output file. 372 if self.ksdata: 373 f.write(self.ksdata.user.__str__()) 374 f.write(self.ksdata.services.__str__()) 375 f.write(self.ksdata.reboot.__str__()) 376 377 self.instLanguage.writeKS(f) 378 379 if not self.isHeadless: 380 self.keyboard.writeKS(f) 381 self.network.writeKS(f) 382 383 self.timezone.writeKS(f) 384 self.users.writeKS(f) 385 self.security.writeKS(f) 386 self.firewall.writeKS(f) 387 388 self.storage.writeKS(f) 389 self.bootloader.writeKS(f) 390 391 if self.backend: 392 self.backend.writeKS(f) 393 self.backend.writePackagesKS(f, self) 394 395 # Also write out any scripts from the input ksfile. 396 if self.ksdata: 397 for s in self.ksdata.scripts: 398 f.write(s.__str__()) 399 400 # make it so only root can read, could have password 401 os.chmod(filename, 0600)
402