New version.
[pykickstart.git] / pykickstart / commands / clearpart.py
blobf6af6fbe7a1087b9d8487d14b28f00ef838ce6ab
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2005, 2006, 2007, 2012 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 KickstartCommand
21 from pykickstart.constants import CLEARPART_TYPE_ALL, CLEARPART_TYPE_LINUX, CLEARPART_TYPE_LIST, CLEARPART_TYPE_NONE
22 from pykickstart.options import KSOptionParser
24 class FC3_ClearPart(KickstartCommand):
25 removedKeywords = KickstartCommand.removedKeywords
26 removedAttrs = KickstartCommand.removedAttrs
28 def __init__(self, writePriority=120, *args, **kwargs):
29 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
30 self.op = self._getParser()
32 self.drives = kwargs.get("drives", [])
33 self.initAll = kwargs.get("initAll", False)
34 self.type = kwargs.get("type", None)
36 def __str__(self):
37 retval = KickstartCommand.__str__(self)
39 if self.type is None:
40 return retval
42 if self.type == CLEARPART_TYPE_NONE:
43 clearstr = " --none"
44 elif self.type == CLEARPART_TYPE_LINUX:
45 clearstr = " --linux"
46 elif self.type == CLEARPART_TYPE_ALL:
47 clearstr = " --all"
48 else:
49 clearstr = ""
51 if self.initAll:
52 initstr = " --initlabel"
53 else:
54 initstr = ""
56 if len(self.drives) > 0:
57 drivestr = " --drives=" + ",".join(self.drives)
58 else:
59 drivestr = ""
61 retval += "# Partition clearing information\nclearpart%s%s%s\n" % (clearstr, initstr, drivestr)
62 return retval
64 def _getParser(self):
65 def drive_cb (option, opt_str, value, parser):
66 for d in value.split(','):
67 parser.values.ensure_value(option.dest, []).append(d)
69 op = KSOptionParser()
70 op.add_option("--all", dest="type", action="store_const",
71 const=CLEARPART_TYPE_ALL)
72 op.add_option("--drives", dest="drives", action="callback",
73 callback=drive_cb, nargs=1, type="string")
74 op.add_option("--initlabel", dest="initAll", action="store_true",
75 default=False)
76 op.add_option("--linux", dest="type", action="store_const",
77 const=CLEARPART_TYPE_LINUX)
78 op.add_option("--none", dest="type", action="store_const",
79 const=CLEARPART_TYPE_NONE)
80 return op
82 def parse(self, args):
83 (opts, _extra) = self.op.parse_args(args=args, lineno=self.lineno)
84 self._setToSelf(self.op, opts)
85 return self
87 class F17_ClearPart(FC3_ClearPart):
88 def __init__(self, *args, **kwargs):
89 super(F17_ClearPart, self).__init__(*args, **kwargs)
90 self.devices = kwargs.get("devices", [])
92 def __str__(self):
93 s = super(F17_ClearPart, self).__str__()
94 if s and len(self.devices) > 0:
95 s = s.rstrip()
96 s += " --list=" + ",".join(self.devices)
97 s += "\n"
98 return s
100 def _getParser(self):
101 op = FC3_ClearPart._getParser(self)
103 def list_cb (option, opt_str, value, parser):
104 self.type = CLEARPART_TYPE_LIST
105 for d in value.split(','):
106 parser.values.ensure_value(option.dest, []).append(d)
108 op.add_option("--list", dest="devices", action="callback",
109 callback=list_cb, nargs=1, type="string")
110 return op