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)
37 retval
= KickstartCommand
.__str
__(self
)
42 if self
.type == CLEARPART_TYPE_NONE
:
44 elif self
.type == CLEARPART_TYPE_LINUX
:
46 elif self
.type == CLEARPART_TYPE_ALL
:
52 initstr
= " --initlabel"
56 if len(self
.drives
) > 0:
57 drivestr
= " --drives=" + ",".join(self
.drives
)
61 retval
+= "# Partition clearing information\nclearpart%s%s%s\n" % (clearstr
, initstr
, drivestr
)
65 def drive_cb (option
, opt_str
, value
, parser
):
66 for d
in value
.split(','):
67 parser
.values
.ensure_value(option
.dest
, []).append(d
)
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",
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
)
82 def parse(self
, args
):
83 (opts
, _extra
) = self
.op
.parse_args(args
=args
, lineno
=self
.lineno
)
84 self
._setToSelf
(self
.op
, opts
)
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", [])
93 s
= super(F17_ClearPart
, self
).__str
__()
94 if s
and len(self
.devices
) > 0:
96 s
+= " --list=" + ",".join(self
.devices
)
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")