2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2005, 2006, 2007 Red Hat, Inc.
6 # This copyrighted material is made available to anyone wishing to use, modify,
7 # copy, or redistribute it subject to the terms and conditions of the GNU
8 # General Public License v.2. This program is distributed in the hope that it
9 # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
10 # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # this program; if not, write to the Free Software Foundation, Inc., 51
15 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
16 # trademarks that are incorporated in the source code or documentation are not
17 # subject to the GNU General Public License and may only be used or replicated
18 # with the express permission of Red Hat, Inc.
20 from pykickstart.base import *
21 from pykickstart.constants import *
22 from pykickstart.errors import *
23 from pykickstart.options import *
25 class FC3_ClearPart(KickstartCommand):
26 removedKeywords = KickstartCommand.removedKeywords
27 removedAttrs = KickstartCommand.removedAttrs
29 def __init__(self, writePriority=120, *args, **kwargs):
30 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
31 self.op = self._getParser()
33 self.drives = kwargs.get("drives", [])
34 self.initAll = kwargs.get("initAll", False)
35 self.type = kwargs.get("type", None)
38 retval = KickstartCommand.__str__(self)
43 if self.type == CLEARPART_TYPE_NONE:
45 elif self.type == CLEARPART_TYPE_LINUX:
47 elif self.type == CLEARPART_TYPE_ALL:
53 initstr = "--initlabel"
57 if len(self.drives) > 0:
58 drivestr = "--drives=" + ",".join(self.drives)
62 retval += "# Partition clearing information\nclearpart %s %s %s\n" % (clearstr, initstr, drivestr)
66 def drive_cb (option, opt_str, value, parser):
67 for d in value.split(','):
68 parser.values.ensure_value(option.dest, []).append(d)
71 op.add_option("--all", dest="type", action="store_const",
72 const=CLEARPART_TYPE_ALL)
73 op.add_option("--drives", dest="drives", action="callback",
74 callback=drive_cb, nargs=1, type="string")
75 op.add_option("--initlabel", dest="initAll", action="store_true",
77 op.add_option("--linux", dest="type", action="store_const",
78 const=CLEARPART_TYPE_LINUX)
79 op.add_option("--none", dest="type", action="store_const",
80 const=CLEARPART_TYPE_NONE)
83 def parse(self, args):
84 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
85 self._setToSelf(self.op, opts)