Add --resolvedeps and --includedeps as deprecated options to %packages.
[pykickstart.git] / pykickstart / writer.py
blobb072038d67272358d8dfe994437e4166d9d3e737
2 # writer.py: Kickstart file writer.
4 # Chris Lumens <clumens@redhat.com>
6 # Copyright 2005 Red Hat, Inc.
8 # This software may be freely redistributed under the terms of the GNU
9 # general public license.
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software
13 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 import string
16 from constants import *
18 class KickstartWriter:
19 def __init__(self, ksdata):
20 # All the printing handlers in the order they should be called.
21 self.handlers = [self.doPlatform,
23 self.doAuthconfig, self.doAutoPart, self.doAutoStep,
24 self.doBootloader, self.doClearPart, self.doDevice,
25 self.doDeviceProbe, self.doDisplayMode,
26 self.doDriverDisk, self.doFirewall, self.doFirstboot,
27 self.doIgnoreDisk, self.doInteractive, self.doKeyboard,
28 self.doLang, self.doMediaCheck, self.doMethod,
29 self.doMonitor, self.doNetwork, self.doReboot,
30 self.doRootPw, self.doSELinux, self.doSkipX,
31 self.doTimezone, self.doUpgrade, self.doVnc,
32 self.doXConfig, self.doZeroMbr, self.doZFCP,
34 self.doPartition, self.doLogicalVolume,
35 self.doVolumeGroup, self.doRaid,
37 self.doScripts, self.doPackages]
39 self.ksdata = ksdata
41 # Return a string representation of the ksdata suitable for writing to
42 # a file.
43 def write(self):
44 return string.join(filter (lambda str: str != None and str != "",
45 map (lambda fn: fn(), self.handlers)), "\n")
47 def doPlatform(self):
48 if self.ksdata.platform != "":
49 return "#platform=%s" % self.ksdata.platform
51 def doAuthconfig(self):
52 if self.ksdata.authconfig != "" and self.ksdata.upgrade == False:
53 return "# System authorization information\nauth %s" % self.ksdata.authconfig
55 def doAutoPart(self):
56 if self.ksdata.autopart:
57 return "autopart"
59 def doAutoStep(self):
60 if self.ksdata.autostep["autoscreenshot"]:
61 return "autostep --autoscreenshot"
63 def doBootloader(self):
64 str = "# System bootloader configuration\nbootloader"
66 if self.ksdata.bootloader["appendLine"] != "":
67 str = str + " --append=\"%s\"" % self.ksdata.bootloader["appendLine"]
68 if self.ksdata.bootloader["location"]:
69 str = str + " --location=%s" % self.ksdata.bootloader["location"]
70 if self.ksdata.bootloader["forceLBA"] == True:
71 str = str + " --lba32"
72 if self.ksdata.bootloader["password"] != "":
73 str = str + " --password=%s" % self.ksdata.bootloader["password"]
74 if self.ksdata.bootloader["md5pass"] != "":
75 str = str + " --md5pass=%s" % self.ksdata.bootloader["md5pass"]
76 if self.ksdata.bootloader["upgrade"] == True:
77 str = str + " --upgrade"
78 if len(self.ksdata.bootloader["driveorder"]) > 0:
79 str = str + " --driveorder=%s" % \
80 string.join(self.ksdata.bootloader["driveorder"], ",")
82 if str != "bootloader":
83 return str
85 def doClearPart(self):
86 if self.ksdata.clearpart["type"] == CLEARPART_TYPE_NONE:
87 clearstr = "--none"
88 elif self.ksdata.clearpart["type"] == CLEARPART_TYPE_LINUX:
89 clearstr = "--linux"
90 elif self.ksdata.clearpart["type"] == CLEARPART_TYPE_LINUX:
91 clearstr = "--all"
93 if self.ksdata.clearpart["initAll"] == True:
94 initstr = "--initlabel"
95 else:
96 initstr = ""
98 if len(self.ksdata.clearpart["drives"]) > 0:
99 drivestr = "--drives=" + \
100 string.join (self.ksdata.clearpart["drives"], ",")
101 else:
102 drivestr = ""
104 return "# Partition clearing information\nclearpart %s %s %s" % (clearstr, initstr, drivestr)
106 def doDevice(self):
107 if self.ksdata.device != "":
108 return "device %s" % self.ksdata.device
110 def doDeviceProbe(self):
111 if self.ksdata.deviceprobe != "":
112 return "deviceprobe %s" % self.ksdata.deviceprobe
114 def doDisplayMode(self):
115 if self.ksdata.displayMode == DISPLAY_MODE_CMDLINE:
116 return "cmdline"
117 elif self.ksdata.displayMode == DISPLAY_MODE_GRAPHICAL:
118 return "# Use graphical install\ngraphical"
119 elif self.ksdata.displayMode == DISPLAY_MODE_TEXT:
120 return "# Use text mode install\ntext"
122 def doDriverDisk(self):
123 if self.ksdata.driverdisk != "":
124 return "driverdisk %s" % self.ksdata.driverdisk
126 def doFirewall(self):
127 if self.ksdata.upgrade == True:
128 return
130 if self.ksdata.firewall["enabled"]:
131 portstr = string.join (self.ksdata.firewall["ports"], ",")
132 if len(portstr) > 0:
133 portstr = "--ports= " + portstr
134 else:
135 portstr = ""
137 truststr = string.join (self.ksdata.firewall["trusts"], ",")
138 if len(truststr) > 0:
139 truststr = "--trust= " + truststr
141 return "# Firewall configuration\nfirewall --enabled %s %s" % (portstr, truststr)
142 else:
143 return "# Firewall configuration\nfirewall --disabled"
145 def doFirstboot(self):
146 str = "# Run the Setup Agent on first boot\n"
148 if self.ksdata.firstboot == FIRSTBOOT_SKIP:
149 return str + "firstboot --disable"
150 elif self.ksdata.firstboot == FIRSTBOOT_DEFAULT:
151 return str + "firstboot --enable"
152 elif self.ksdata.firstboot == FIRSTBOOT_RECONFIG:
153 return str + "firstboot --reconfig"
155 def doIgnoreDisk(self):
156 if len(self.ksdata.ignoredisk) > 0:
157 str = string.join (self.ksdata.ignoredisk, ",")
158 return "ignoredisk --drives= %s" % str
160 def doInteractive(self):
161 if self.ksdata.interactive == True:
162 return "# Use interactive kickstart installation method\ninteractive"
164 def doKeyboard(self):
165 if self.ksdata.keyboard != "":
166 return "# System keyboard\nkeyboard %s" % self.ksdata.keyboard
168 def doLang(self):
169 if self.ksdata.lang != "":
170 return "# System language\nlang %s" % self.ksdata.lang
172 def doLogicalVolume(self):
173 if self.ksdata.upgrade == True:
174 return
176 str = ""
178 for part in self.ksdata.lvList:
179 str = str + "logvol %s" % part.mountpoint
181 if part.bytesPerInode > 0:
182 str = str + " --bytes-per-inode= %d" % part.bytesPerInode
183 if part.fsopts != "":
184 str = str + " --fsoptions=\"%s\"" % part.fsopts
185 if part.fstype != "":
186 str = str + " --fstype=\"%s\"" % part.fstype
187 if part.grow == True:
188 str = str + " --grow"
189 if part.maxSizeMB > 0:
190 str = str + " --maxsize=%d" % part.maxSizeMB
191 if part.format == False:
192 str = str + " --noformat"
193 if part.percent > 0:
194 str = str + " --percent=%d" % part.percent
195 if part.recommended == True:
196 str = str + " --recommended"
197 if part.size > 0:
198 str = str + " --size=%d" % part.size
199 if part.preexist == True:
200 str = str + " --useexisting"
202 str = str + " --name=%s --vgname=%s\n" % (part.name, part.vgname)
204 return str.rstrip()
206 def doMediaCheck(self):
207 if self.ksdata.mediacheck == True:
208 return "mediacheck"
210 def doMethod(self):
211 if self.ksdata.method["method"] == "cdrom":
212 return "# Use CDROM installation media\ncdrom"
213 elif self.ksdata.method["method"] == "harddrive":
214 return "# Use hard drive installation media\nharddrive --partition=%s --dir=%s" % (self.ksdata.method["partition"], self.ksdata.method["dir"])
215 elif self.ksdata.method["method"] == "nfs":
216 return "# Use NFS installation media\nnfs --server=%s --dir=%s" % (self.ksdata.method["server"], self.ksdata.method["dir"])
217 elif self.ksdata.method["method"] == "url":
218 return "# Use network installation\nurl --url=%s" % self.ksdata.method["url"]
220 def doMonitor(self):
221 str = "monitor"
223 if self.ksdata.monitor["hsync"] != "":
224 str = str + " --hsync=%s" % self.ksdata.monitor["hsync"]
225 if self.ksdata.monitor["monitor"] != "":
226 str = str + " --monitor=%s" % self.ksdata.monitor["monitor"]
227 if self.ksdata.monitor["vsync"] != "":
228 str = str + " --vsync=%s" % self.ksdata.monitor["vsync"]
230 if str != "monitor":
231 return str
233 def doNetwork(self):
234 if self.ksdata.network == []:
235 return
237 str = "# Network information\n"
239 for nic in self.ksdata.network:
240 str = str + "network"
242 if nic.bootProto != "":
243 str = str + " --bootproto=%s" % nic.bootProto
244 if nic.dhcpclass != "":
245 str = str + " --dhcpclass=%s" % nic.dhcpclass
246 if nic.device != "":
247 str = str + " --device=%s" % nic.device
248 if nic.essid != "":
249 str = str + " --essid=\"%s\"" % nic.essid
250 if nic.ethtool != "":
251 str = str + " --ethtool=%s" % nic.ethtool
252 if nic.gateway != "":
253 str = str + " --gateway=%s" % nic.gateway
254 if nic.hostname != "":
255 str = str + " --hostname=%s" % nic.hostname
256 if nic.ip != "":
257 str = str + " --ip=%s" % nic.ip
258 if nic.nameserver != "":
259 str = str + " --nameserver=%s" % nic.nameserver
260 if nic.netmask != "":
261 str = str + " --netmask=%s" % nic.netmask
262 if nic.nodns == True:
263 str = str + " --nodns"
264 if nic.notksdevice == True:
265 str = str + " --notksdevice"
266 if nic.onboot == True:
267 str = str + " --onboot"
268 if nic.wepkey != "":
269 str = str + " --wepkey=%s" % nic.wepkey
271 str = str + "\n"
273 return str.rstrip()
275 def doPartition(self):
276 if self.ksdata.upgrade == True or self.ksdata.partitions == []:
277 return
279 str = "# Disk partitioning information\n"
281 for part in self.ksdata.partitions:
282 str = str + "part %s" % part.mountpoint
284 if part.active == True:
285 str = str + " --active"
286 if part.primOnly == True:
287 str = str + " --asprimary"
288 if part.bytesPerInode != 0:
289 str = str + " --bytes-per-inode=%d" % part.bytesPerInode
290 if part.end != 0:
291 str = str + " --end=%d" % part.end
292 if part.fsopts != "":
293 str = str + " --fsoptions=\"%s\"" % part.fsopts
294 if part.fstype != "":
295 str = str + " --fstype=\"%s\"" % part.fstype
296 if part.grow == True:
297 str = str + " --grow"
298 if part.label != "":
299 str = str + " --label=%s" % part.label
300 if part.maxSizeMB > 0:
301 str = str + " --maxsize=%d" % part.maxSizeMB
302 if part.format == False:
303 str = str + " --noformat"
304 if part.onbiosdisk != "":
305 str = str + " --onbiosdisk=%s" % part.onbiosdisk
306 if part.disk != "":
307 str = str + " --ondisk=%s" % part.disk
308 if part.onPart != "":
309 str = str + " --onpart=%s" % part.onPart
310 if part.recommended == True:
311 str = str + " --recommended"
312 if part.size != 0:
313 str = str + " --size=%d" % part.size
314 if part.start != 0:
315 str = str + " --start=%d" % part.start
317 str = str + "\n"
319 return str.rstrip()
321 def doReboot(self):
322 if self.ksdata.reboot == True:
323 return "# Reboot after installation\nreboot"
325 def doRaid(self):
326 if self.ksdata.upgrade == True:
327 return
329 str = ""
331 for raid in self.ksdata.raidList:
332 str = str + "raid %s" % raid.mountpoint
334 if raid.device != "":
335 str = str + " --device=%s" % raid.device
336 if raid.fsopts != "":
337 str = str + " --fsoptions=\"%s\"" % raid.fsopts
338 if raid.fstype != "":
339 str = str + " --fstype=\"%s\"" % raid.fstype
340 if raid.level != "":
341 str = str + " --level=%s" % raid.level
342 if raid.format == False:
343 str = str + " --noformat"
344 if raid.spares != 0:
345 str = str + " --spares=%d" % raid.spares
346 if raid.preexist == True:
347 str = str + " --useexisting"
349 str = str + " %s\n" % string.join(raid.members)
351 return str.rstrip()
353 def doRootPw(self):
354 if self.ksdata.rootpw["password"] != "":
355 if self.ksdata.rootpw["isCrypted"] == True:
356 crypted = "--iscrypted"
357 else:
358 crypted = ""
360 return "#Root password\nrootpw %s %s" % (crypted, self.ksdata.rootpw["password"])
362 def doSELinux(self):
363 str = "# SELinux configuration\n"
365 if self.ksdata.selinux == SELINUX_DISABLED:
366 return str + "selinux --disabled"
367 elif self.ksdata.selinux == SELINUX_ENFORCING:
368 return str + "selinux --enforcing"
369 elif self.ksdata.selinux == SELINUX_PERMISSIVE:
370 return str + "selinux --permissive"
372 def doSkipX(self):
373 if self.ksdata.skipx == True and self.ksdata.upgrade == False:
374 return "# Do not configure the X Window System\nskipx"
376 def doTimezone(self):
377 if self.ksdata.timezone["timezone"] != "":
378 if self.ksdata.timezone["isUtc"] == True:
379 utc = "--isUtc"
380 else:
381 utc = ""
383 return "# System timezone\ntimezone %s %s" %(utc, self.ksdata.timezone["timezone"])
385 def doUpgrade(self):
386 if self.ksdata.upgrade == True:
387 return "# Upgrade existing installation\nupgrade"
388 else:
389 return "# Install OS instead of upgrade\ninstall"
391 def doVnc(self):
392 if self.ksdata.vnc["enabled"] == True:
393 if self.ksdata.vnc["password"] != "":
394 password = "--password=%s" % self.ksdata.vnc["password"]
395 else:
396 password = ""
398 if self.ksdata.vnc["port"] != "":
399 port = ":%s" % self.ksdata.vnc["port"]
400 else:
401 port = ""
403 return "vnc --enabled %s %s%s" % (password, self.ksdata.vnc["host"],
404 port)
406 def doVolumeGroup(self):
407 if self.ksdata.upgrade == True:
408 return
410 str = ""
412 for vg in self.ksdata.vgList:
413 str = str + "volgroup %s" % vg.vgname
415 if vg.format == False:
416 str = str + " --noformat"
417 if vg.pesize != 0:
418 str = str + " --pesize=%d" % vg.pesize
419 if vg.preexist == True:
420 str = str + " --useexisting"
422 str = str + " %s\n" % string.join(vg.physvols, ",")
424 return str.rstrip()
426 def doXConfig(self):
427 if self.ksdata.upgrade == True or self.ksdata.skipx == True:
428 return
430 str = "# X Window System configuration information\nxconfig"
432 if self.ksdata.xconfig["driver"] != "":
433 str = str + " --driver=%s" % self.ksdata.xconfig["driver"]
434 if self.ksdata.xconfig["defaultdesktop"] != "":
435 str = str + " --defaultdesktop=%s" % self.ksdata.xconfig["defaultdesktop"]
436 if self.ksdata.xconfig["depth"] != 0:
437 str = str + " --depth=%d" % self.ksdata.xconfig["depth"]
438 if self.ksdata.xconfig["hsync"] != "":
439 str = str + " --hsync=%s" % self.ksdata.xconfig["hsync"]
440 if self.ksdata.xconfig["monitor"] != "":
441 str = str + " --monitor=\"%s\"" % self.ksdata.xconfig["monitor"]
442 if self.ksdata.xconfig["probe"] == False:
443 str = str + " --noprobe"
444 if self.ksdata.xconfig["resolution"] != "":
445 str = str + " --resolution=%s" % self.ksdata.xconfig["resolution"]
446 if self.ksdata.xconfig["startX"] == True:
447 str = str + " --startxonboot"
448 if self.ksdata.xconfig["videoRam"] != "":
449 str = str + " --videoram=%s" % self.ksdata.xconfig["videoRam"]
450 if self.ksdata.xconfig["vsync"] != "":
451 str = str + " --vsync=%s" % self.ksdata.xconfig["vsync"]
453 if str != "xconfig":
454 return str
456 def doZeroMbr(self):
457 if self.ksdata.zerombr == True:
458 return "# Clear the Master Boot Record\nzerombr"
460 def doZFCP(self):
461 if self.ksdata.zfcp["devnum"] != "":
462 return "zfcp --devnum=%(devnum)s --fcplun=%(fcplun)s --scsiid=%(scsiid)s --scsilun=%(scsilun)s --wwpn=%(wwpn)s" % self.ksdata.zfcp
464 def doScripts(self):
465 preStr = ""
466 postStr = ""
467 tracebackStr = ""
469 for script in self.ksdata.scripts:
470 if script.type == KS_SCRIPT_PRE:
471 preStr = preStr + "%%pre %s" % script.write()
472 elif script.type == KS_SCRIPT_POST:
473 postStr = postStr + "%%post %s" % script.write()
474 elif script.type == KS_SCRIPT_TRACEBACK:
475 tracebackStr = tracebackStr + "%%traceback %s" % script.write()
477 return preStr + postStr + tracebackStr.rstrip()
479 def doPackages(self):
480 if self.ksdata.upgrade == True:
481 return
483 str = "\n%packages\n"
485 for pkg in self.ksdata.packageList:
486 str = str + "%s\n" % pkg
488 for pkg in self.ksdata.excludedList:
489 str = str + "-%s\n" % pkg
491 for grp in self.ksdata.groupList:
492 str = str + "@%s\n" % grp
494 return str.rstrip()