Don't set any default values on these commands.
[pykickstart.git] / pykickstart / commands / bootloader.py
blobd27eaed1db8dcc8511db84cb6be1084ee727af12
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2007 Red Hat, Inc.
6 # This software may be freely redistributed under the terms of the GNU
7 # general public license.
9 # You should have received a copy of the GNU General Public License
10 # along with this program; if not, write to the Free Software
11 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
13 import string
15 from pykickstart.base import *
16 from pykickstart.options import *
18 class FC3_Bootloader(KickstartCommand):
19 def __init__(self, writePriority=0, appendLine="", driveorder=None,
20 forceLBA=False, linear=True, location="", md5pass="",
21 password="", upgrade=False, useLilo=False):
22 KickstartCommand.__init__(self, writePriority)
23 self.appendLine = appendLine
25 if driveorder == None:
26 driveorder = []
28 self.driveorder = driveorder
30 self.forceLBA = forceLBA
31 self.linear = linear
32 self.location = location
33 self.md5pass = md5pass
34 self.password = password
35 self.upgrade = upgrade
36 self.useLilo = useLilo
38 def __str__(self):
39 if self.location != "":
40 retval = "# System bootloader configuration\nbootloader"
42 if self.appendLine != "":
43 retval += " --append=\"%s\"" % self.appendLine
44 if self.linear:
45 retval += " --linear"
46 if self.location:
47 retval += " --location=%s" % self.location
48 if self.forceLBA:
49 retval += " --lba32"
50 if self.password != "":
51 retval += " --password=%s" % self.password
52 if self.md5pass != "":
53 retval += " --md5pass=%s" % self.md5pass
54 if self.upgrade:
55 retval += " --upgrade"
56 if self.useLilo:
57 retval += " --useLilo"
58 if len(self.driveorder) > 0:
59 retval += " --driveorder=%s" % string.join(self.driveorder, ",")
61 return retval + "\n"
62 else:
63 return ""
65 def parse(self, args):
66 def driveorder_cb (option, opt_str, value, parser):
67 for d in value.split(','):
68 parser.values.ensure_value(option.dest, []).append(d)
70 op = KSOptionParser(lineno=self.lineno)
71 op.add_option("--append", dest="appendLine")
72 op.add_option("--linear", dest="linear", action="store_true",
73 default=True)
74 op.add_option("--nolinear", dest="linear", action="store_false")
75 op.add_option("--location", dest="location", type="choice",
76 default="mbr",
77 choices=["mbr", "partition", "none", "boot"])
78 op.add_option("--lba32", dest="forceLBA", action="store_true",
79 default=False)
80 op.add_option("--password", dest="password", default="")
81 op.add_option("--md5pass", dest="md5pass", default="")
82 op.add_option("--upgrade", dest="upgrade", action="store_true",
83 default=False)
84 op.add_option("--useLilo", dest="useLilo", action="store_true",
85 default=False)
86 op.add_option("--driveorder", dest="driveorder", action="callback",
87 callback=driveorder_cb, nargs=1, type="string")
89 (opts, extra) = op.parse_args(args=args)
90 self._setToSelf(op, opts)
92 if self.currentCmd == "lilo":
93 self.useLilo = True
95 class FC4_Bootloader(FC3_Bootloader):
96 def __init__(self, writePriority=0, appendLine="", driveorder=None,
97 forceLBA=False, location="", md5pass="", password="",
98 upgrade=False):
99 KickstartCommand.__init__(self, writePriority)
100 self.appendLine = appendLine
102 if driveorder == None:
103 driveorder = []
105 self.driveorder = driveorder
107 self.forceLBA = forceLBA
108 self.location = location
109 self.md5pass = md5pass
110 self.password = password
111 self.upgrade = upgrade
113 def __str__(self):
114 if self.location != "":
115 retval = "# System bootloader configuration\nbootloader"
117 if self.appendLine != "":
118 retval += " --append=\"%s\"" % self.appendLine
119 if self.location:
120 retval += " --location=%s" % self.location
121 if self.forceLBA:
122 retval += " --lba32"
123 if self.password != "":
124 retval += " --password=%s" % self.password
125 if self.md5pass != "":
126 retval += " --md5pass=%s" % self.md5pass
127 if self.upgrade:
128 retval += " --upgrade"
129 if len(self.driveorder) > 0:
130 retval += " --driveorder=%s" % string.join(self.driveorder, ",")
132 return retval + "\n"
133 else:
134 return ""
136 def parse(self, args):
137 def driveorder_cb (option, opt_str, value, parser):
138 for d in value.split(','):
139 parser.values.ensure_value(option.dest, []).append(d)
141 op = KSOptionParser(lineno=self.lineno)
142 op.add_option("--append", dest="appendLine")
143 op.add_option("--location", dest="location", type="choice",
144 default="mbr",
145 choices=["mbr", "partition", "none", "boot"])
146 op.add_option("--lba32", dest="forceLBA", action="store_true",
147 default=False)
148 op.add_option("--password", dest="password", default="")
149 op.add_option("--md5pass", dest="md5pass", default="")
150 op.add_option("--upgrade", dest="upgrade", action="store_true",
151 default=False)
152 op.add_option("--driveorder", dest="driveorder", action="callback",
153 callback=driveorder_cb, nargs=1, type="string")
155 (opts, extra) = op.parse_args(args=args)
156 self._setToSelf(op, opts)