summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/3rdparty/pykickstart/commands/partition.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/wic/3rdparty/pykickstart/commands/partition.py')
-rw-r--r--scripts/lib/wic/3rdparty/pykickstart/commands/partition.py314
1 files changed, 314 insertions, 0 deletions
diff --git a/scripts/lib/wic/3rdparty/pykickstart/commands/partition.py b/scripts/lib/wic/3rdparty/pykickstart/commands/partition.py
new file mode 100644
index 0000000000..56b91aa9d9
--- /dev/null
+++ b/scripts/lib/wic/3rdparty/pykickstart/commands/partition.py
@@ -0,0 +1,314 @@
1#
2# Chris Lumens <clumens@redhat.com>
3#
4# Copyright 2005, 2006, 2007, 2008 Red Hat, Inc.
5#
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.
12#
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.
19#
20from pykickstart.base import *
21from pykickstart.errors import *
22from pykickstart.options import *
23
24import gettext
25import warnings
26_ = lambda x: gettext.ldgettext("pykickstart", x)
27
28class FC3_PartData(BaseData):
29 removedKeywords = BaseData.removedKeywords
30 removedAttrs = BaseData.removedAttrs
31
32 def __init__(self, *args, **kwargs):
33 BaseData.__init__(self, *args, **kwargs)
34 self.active = kwargs.get("active", False)
35 self.primOnly = kwargs.get("primOnly", False)
36 self.end = kwargs.get("end", 0)
37 self.fstype = kwargs.get("fstype", "")
38 self.grow = kwargs.get("grow", False)
39 self.maxSizeMB = kwargs.get("maxSizeMB", 0)
40 self.format = kwargs.get("format", True)
41 self.onbiosdisk = kwargs.get("onbiosdisk", "")
42 self.disk = kwargs.get("disk", "")
43 self.onPart = kwargs.get("onPart", "")
44 self.recommended = kwargs.get("recommended", False)
45 self.size = kwargs.get("size", None)
46 self.start = kwargs.get("start", 0)
47 self.mountpoint = kwargs.get("mountpoint", "")
48
49 def __eq__(self, y):
50 if self.mountpoint:
51 return self.mountpoint == y.mountpoint
52 else:
53 return False
54
55 def _getArgsAsStr(self):
56 retval = ""
57
58 if self.active:
59 retval += " --active"
60 if self.primOnly:
61 retval += " --asprimary"
62 if hasattr(self, "end") and self.end != 0:
63 retval += " --end=%s" % self.end
64 if self.fstype != "":
65 retval += " --fstype=\"%s\"" % self.fstype
66 if self.grow:
67 retval += " --grow"
68 if self.maxSizeMB > 0:
69 retval += " --maxsize=%d" % self.maxSizeMB
70 if not self.format:
71 retval += " --noformat"
72 if self.onbiosdisk != "":
73 retval += " --onbiosdisk=%s" % self.onbiosdisk
74 if self.disk != "":
75 retval += " --ondisk=%s" % self.disk
76 if self.onPart != "":
77 retval += " --onpart=%s" % self.onPart
78 if self.recommended:
79 retval += " --recommended"
80 if self.size and self.size != 0:
81 retval += " --size=%s" % self.size
82 if hasattr(self, "start") and self.start != 0:
83 retval += " --start=%s" % self.start
84
85 return retval
86
87 def __str__(self):
88 retval = BaseData.__str__(self)
89 if self.mountpoint:
90 mountpoint_str = "%s" % self.mountpoint
91 else:
92 mountpoint_str = "(No mount point)"
93 retval += "part %s%s\n" % (mountpoint_str, self._getArgsAsStr())
94 return retval
95
96class FC4_PartData(FC3_PartData):
97 removedKeywords = FC3_PartData.removedKeywords
98 removedAttrs = FC3_PartData.removedAttrs
99
100 def __init__(self, *args, **kwargs):
101 FC3_PartData.__init__(self, *args, **kwargs)
102 self.bytesPerInode = kwargs.get("bytesPerInode", 4096)
103 self.fsopts = kwargs.get("fsopts", "")
104 self.label = kwargs.get("label", "")
105
106 def _getArgsAsStr(self):
107 retval = FC3_PartData._getArgsAsStr(self)
108
109 if hasattr(self, "bytesPerInode") and self.bytesPerInode != 0:
110 retval += " --bytes-per-inode=%d" % self.bytesPerInode
111 if self.fsopts != "":
112 retval += " --fsoptions=\"%s\"" % self.fsopts
113 if self.label != "":
114 retval += " --label=%s" % self.label
115
116 return retval
117
118class F9_PartData(FC4_PartData):
119 removedKeywords = FC4_PartData.removedKeywords + ["bytesPerInode"]
120 removedAttrs = FC4_PartData.removedAttrs + ["bytesPerInode"]
121
122 def __init__(self, *args, **kwargs):
123 FC4_PartData.__init__(self, *args, **kwargs)
124 self.deleteRemovedAttrs()
125
126 self.fsopts = kwargs.get("fsopts", "")
127 self.label = kwargs.get("label", "")
128 self.fsprofile = kwargs.get("fsprofile", "")
129 self.encrypted = kwargs.get("encrypted", False)
130 self.passphrase = kwargs.get("passphrase", "")
131
132 def _getArgsAsStr(self):
133 retval = FC4_PartData._getArgsAsStr(self)
134
135 if self.fsprofile != "":
136 retval += " --fsprofile=\"%s\"" % self.fsprofile
137 if self.encrypted:
138 retval += " --encrypted"
139
140 if self.passphrase != "":
141 retval += " --passphrase=\"%s\"" % self.passphrase
142
143 return retval
144
145class F11_PartData(F9_PartData):
146 removedKeywords = F9_PartData.removedKeywords + ["start", "end"]
147 removedAttrs = F9_PartData.removedAttrs + ["start", "end"]
148
149class F12_PartData(F11_PartData):
150 removedKeywords = F11_PartData.removedKeywords
151 removedAttrs = F11_PartData.removedAttrs
152
153 def __init__(self, *args, **kwargs):
154 F11_PartData.__init__(self, *args, **kwargs)
155
156 self.escrowcert = kwargs.get("escrowcert", "")
157 self.backuppassphrase = kwargs.get("backuppassphrase", False)
158
159 def _getArgsAsStr(self):
160 retval = F11_PartData._getArgsAsStr(self)
161
162 if self.encrypted and self.escrowcert != "":
163 retval += " --escrowcert=\"%s\"" % self.escrowcert
164
165 if self.backuppassphrase:
166 retval += " --backuppassphrase"
167
168 return retval
169
170F14_PartData = F12_PartData
171
172class FC3_Partition(KickstartCommand):
173 removedKeywords = KickstartCommand.removedKeywords
174 removedAttrs = KickstartCommand.removedAttrs
175
176 def __init__(self, writePriority=130, *args, **kwargs):
177 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
178 self.op = self._getParser()
179
180 self.partitions = kwargs.get("partitions", [])
181
182 def __str__(self):
183 retval = ""
184
185 for part in self.partitions:
186 retval += part.__str__()
187
188 if retval != "":
189 return "# Disk partitioning information\n" + retval
190 else:
191 return ""
192
193 def _getParser(self):
194 def part_cb (option, opt_str, value, parser):
195 if value.startswith("/dev/"):
196 parser.values.ensure_value(option.dest, value[5:])
197 else:
198 parser.values.ensure_value(option.dest, value)
199
200 op = KSOptionParser()
201 op.add_option("--active", dest="active", action="store_true",
202 default=False)
203 op.add_option("--asprimary", dest="primOnly", action="store_true",
204 default=False)
205 op.add_option("--end", dest="end", action="store", type="int",
206 nargs=1)
207 op.add_option("--fstype", "--type", dest="fstype")
208 op.add_option("--grow", dest="grow", action="store_true", default=False)
209 op.add_option("--maxsize", dest="maxSizeMB", action="store", type="int",
210 nargs=1)
211 op.add_option("--noformat", dest="format", action="store_false",
212 default=True)
213 op.add_option("--onbiosdisk", dest="onbiosdisk")
214 op.add_option("--ondisk", "--ondrive", dest="disk")
215 op.add_option("--onpart", "--usepart", dest="onPart", action="callback",
216 callback=part_cb, nargs=1, type="string")
217 op.add_option("--recommended", dest="recommended", action="store_true",
218 default=False)
219 op.add_option("--size", dest="size", action="store", type="int",
220 nargs=1)
221 op.add_option("--start", dest="start", action="store", type="int",
222 nargs=1)
223 return op
224
225 def parse(self, args):
226 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
227
228 pd = self.handler.PartData()
229 self._setToObj(self.op, opts, pd)
230 pd.lineno = self.lineno
231 if extra:
232 pd.mountpoint = extra[0]
233 if pd in self.dataList():
234 warnings.warn(_("A partition with the mountpoint %s has already been defined.") % pd.mountpoint)
235 else:
236 pd.mountpoint = None
237
238 return pd
239
240 def dataList(self):
241 return self.partitions
242
243class FC4_Partition(FC3_Partition):
244 removedKeywords = FC3_Partition.removedKeywords
245 removedAttrs = FC3_Partition.removedAttrs
246
247 def __init__(self, writePriority=130, *args, **kwargs):
248 FC3_Partition.__init__(self, writePriority, *args, **kwargs)
249
250 def part_cb (option, opt_str, value, parser):
251 if value.startswith("/dev/"):
252 parser.values.ensure_value(option.dest, value[5:])
253 else:
254 parser.values.ensure_value(option.dest, value)
255
256 def _getParser(self):
257 op = FC3_Partition._getParser(self)
258 op.add_option("--bytes-per-inode", dest="bytesPerInode", action="store",
259 type="int", nargs=1)
260 op.add_option("--fsoptions", dest="fsopts")
261 op.add_option("--label", dest="label")
262 return op
263
264class F9_Partition(FC4_Partition):
265 removedKeywords = FC4_Partition.removedKeywords
266 removedAttrs = FC4_Partition.removedAttrs
267
268 def __init__(self, writePriority=130, *args, **kwargs):
269 FC4_Partition.__init__(self, writePriority, *args, **kwargs)
270
271 def part_cb (option, opt_str, value, parser):
272 if value.startswith("/dev/"):
273 parser.values.ensure_value(option.dest, value[5:])
274 else:
275 parser.values.ensure_value(option.dest, value)
276
277 def _getParser(self):
278 op = FC4_Partition._getParser(self)
279 op.add_option("--bytes-per-inode", deprecated=1)
280 op.add_option("--fsprofile")
281 op.add_option("--encrypted", action="store_true", default=False)
282 op.add_option("--passphrase")
283 return op
284
285class F11_Partition(F9_Partition):
286 removedKeywords = F9_Partition.removedKeywords
287 removedAttrs = F9_Partition.removedAttrs
288
289 def _getParser(self):
290 op = F9_Partition._getParser(self)
291 op.add_option("--start", deprecated=1)
292 op.add_option("--end", deprecated=1)
293 return op
294
295class F12_Partition(F11_Partition):
296 removedKeywords = F11_Partition.removedKeywords
297 removedAttrs = F11_Partition.removedAttrs
298
299 def _getParser(self):
300 op = F11_Partition._getParser(self)
301 op.add_option("--escrowcert")
302 op.add_option("--backuppassphrase", action="store_true", default=False)
303 return op
304
305class F14_Partition(F12_Partition):
306 removedKeywords = F12_Partition.removedKeywords
307 removedAttrs = F12_Partition.removedAttrs
308
309 def _getParser(self):
310 op = F12_Partition._getParser(self)
311 op.remove_option("--bytes-per-inode")
312 op.remove_option("--start")
313 op.remove_option("--end")
314 return op