add new option --fslabel in part section
[tools/mic.git] / mic / 3rdparty / pykickstart / commands / partition.py
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 #
20 from pykickstart.base import *
21 from pykickstart.errors import *
22 from pykickstart.options import *
23
24 import gettext
25 import warnings
26 _ = lambda x: gettext.ldgettext("pykickstart", x)
27
28 class 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
96 class 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         self.fslabel = kwargs.get("fslabel", "")
106
107     def _getArgsAsStr(self):
108         retval = FC3_PartData._getArgsAsStr(self)
109
110         if hasattr(self, "bytesPerInode") and self.bytesPerInode != 0:
111             retval += " --bytes-per-inode=%d" % self.bytesPerInode
112         if self.fsopts != "":
113             retval += " --fsoptions=\"%s\"" % self.fsopts
114         if self.label != "":
115             retval += " --label=%s" % self.label
116         if self.fslabel != "":
117             retval += " --fslabel=%s" % self.fslabel
118
119         return retval
120
121 class RHEL5_PartData(FC4_PartData):
122     removedKeywords = FC4_PartData.removedKeywords
123     removedAttrs = FC4_PartData.removedAttrs
124
125     def __init__(self, *args, **kwargs):
126         FC4_PartData.__init__(self, *args, **kwargs)
127         self.encrypted = kwargs.get("encrypted", False)
128         self.passphrase = kwargs.get("passphrase", "")
129
130     def _getArgsAsStr(self):
131         retval = FC4_PartData._getArgsAsStr(self)
132
133         if self.encrypted:
134             retval += " --encrypted"
135
136             if self.passphrase != "":
137                 retval += " --passphrase=\"%s\"" % self.passphrase
138
139         return retval
140
141 class F9_PartData(FC4_PartData):
142     removedKeywords = FC4_PartData.removedKeywords + ["bytesPerInode"]
143     removedAttrs = FC4_PartData.removedAttrs + ["bytesPerInode"]
144
145     def __init__(self, *args, **kwargs):
146         FC4_PartData.__init__(self, *args, **kwargs)
147         self.deleteRemovedAttrs()
148
149         self.fsopts = kwargs.get("fsopts", "")
150         self.label = kwargs.get("label", "")
151         self.fsprofile = kwargs.get("fsprofile", "")
152         self.encrypted = kwargs.get("encrypted", False)
153         self.passphrase = kwargs.get("passphrase", "")
154
155     def _getArgsAsStr(self):
156         retval = FC4_PartData._getArgsAsStr(self)
157
158         if self.fsprofile != "":
159             retval += " --fsprofile=\"%s\"" % self.fsprofile
160         if self.encrypted:
161             retval += " --encrypted"
162
163             if self.passphrase != "":
164                 retval += " --passphrase=\"%s\"" % self.passphrase
165
166         return retval
167
168 class F11_PartData(F9_PartData):
169     removedKeywords = F9_PartData.removedKeywords + ["start", "end"]
170     removedAttrs = F9_PartData.removedAttrs + ["start", "end"]
171
172 class F12_PartData(F11_PartData):
173     removedKeywords = F11_PartData.removedKeywords
174     removedAttrs = F11_PartData.removedAttrs
175
176     def __init__(self, *args, **kwargs):
177         F11_PartData.__init__(self, *args, **kwargs)
178
179         self.escrowcert = kwargs.get("escrowcert", "")
180         self.backuppassphrase = kwargs.get("backuppassphrase", False)
181
182     def _getArgsAsStr(self):
183         retval = F11_PartData._getArgsAsStr(self)
184
185         if self.encrypted and self.escrowcert != "":
186             retval += " --escrowcert=\"%s\"" % self.escrowcert
187
188             if self.backuppassphrase:
189                 retval += " --backuppassphrase"
190
191         return retval
192
193 F14_PartData = F12_PartData
194
195 class FC3_Partition(KickstartCommand):
196     removedKeywords = KickstartCommand.removedKeywords
197     removedAttrs = KickstartCommand.removedAttrs
198
199     def __init__(self, writePriority=130, *args, **kwargs):
200         KickstartCommand.__init__(self, writePriority, *args, **kwargs)
201         self.op = self._getParser()
202
203         self.partitions = kwargs.get("partitions", [])
204
205     def __str__(self):
206         retval = ""
207
208         for part in self.partitions:
209             retval += part.__str__()
210
211         if retval != "":
212             return "# Disk partitioning information\n" + retval
213         else:
214             return ""
215
216     def _getParser(self):
217         def part_cb (option, opt_str, value, parser):
218             if value.startswith("/dev/"):
219                 parser.values.ensure_value(option.dest, value[5:])
220             else:
221                 parser.values.ensure_value(option.dest, value)
222
223         op = KSOptionParser()
224         op.add_option("--active", dest="active", action="store_true",
225                       default=False)
226         op.add_option("--asprimary", dest="primOnly", action="store_true",
227                       default=False)
228         op.add_option("--end", dest="end", action="store", type="int",
229                       nargs=1)
230         op.add_option("--fstype", "--type", dest="fstype")
231         op.add_option("--grow", dest="grow", action="store_true", default=False)
232         op.add_option("--maxsize", dest="maxSizeMB", action="store", type="int",
233                       nargs=1)
234         op.add_option("--noformat", dest="format", action="store_false",
235                       default=True)
236         op.add_option("--onbiosdisk", dest="onbiosdisk")
237         op.add_option("--ondisk", "--ondrive", dest="disk")
238         op.add_option("--onpart", "--usepart", dest="onPart", action="callback",
239                       callback=part_cb, nargs=1, type="string")
240         op.add_option("--recommended", dest="recommended", action="store_true",
241                       default=False)
242         op.add_option("--size", dest="size", action="store", type="int",
243                       nargs=1)
244         op.add_option("--start", dest="start", action="store", type="int",
245                       nargs=1)
246         return op
247
248     def parse(self, args):
249         (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
250
251         pd = self.handler.PartData()
252         self._setToObj(self.op, opts, pd)
253         pd.lineno = self.lineno
254         if extra:
255             pd.mountpoint = extra[0]
256             if pd in self.dataList():
257                 warnings.warn(_("A partition with the mountpoint %s has already been defined.") % pd.mountpoint)
258         else:
259             pd.mountpoint = None
260
261         return pd
262
263     def dataList(self):
264         return self.partitions
265
266 class FC4_Partition(FC3_Partition):
267     removedKeywords = FC3_Partition.removedKeywords
268     removedAttrs = FC3_Partition.removedAttrs
269
270     def __init__(self, writePriority=130, *args, **kwargs):
271         FC3_Partition.__init__(self, writePriority, *args, **kwargs)
272
273         def part_cb (option, opt_str, value, parser):
274             if value.startswith("/dev/"):
275                 parser.values.ensure_value(option.dest, value[5:])
276             else:
277                 parser.values.ensure_value(option.dest, value)
278
279     def _getParser(self):
280         op = FC3_Partition._getParser(self)
281         op.add_option("--bytes-per-inode", dest="bytesPerInode", action="store",
282                       type="int", nargs=1)
283         op.add_option("--fsoptions", dest="fsopts")
284         op.add_option("--label", dest="label")
285         op.add_option("--fslabel", dest="fslabel")
286         return op
287
288 class RHEL5_Partition(FC4_Partition):
289     removedKeywords = FC4_Partition.removedKeywords
290     removedAttrs = FC4_Partition.removedAttrs
291
292     def __init__(self, writePriority=130, *args, **kwargs):
293         FC4_Partition.__init__(self, writePriority, *args, **kwargs)
294
295         def part_cb (option, opt_str, value, parser):
296             if value.startswith("/dev/"):
297                 parser.values.ensure_value(option.dest, value[5:])
298             else:
299                 parser.values.ensure_value(option.dest, value)
300
301     def _getParser(self):
302         op = FC4_Partition._getParser(self)
303         op.add_option("--encrypted", action="store_true", default=False)
304         op.add_option("--passphrase")
305         return op
306
307 class F9_Partition(FC4_Partition):
308     removedKeywords = FC4_Partition.removedKeywords
309     removedAttrs = FC4_Partition.removedAttrs
310
311     def __init__(self, writePriority=130, *args, **kwargs):
312         FC4_Partition.__init__(self, writePriority, *args, **kwargs)
313
314         def part_cb (option, opt_str, value, parser):
315             if value.startswith("/dev/"):
316                 parser.values.ensure_value(option.dest, value[5:])
317             else:
318                 parser.values.ensure_value(option.dest, value)
319
320     def _getParser(self):
321         op = FC4_Partition._getParser(self)
322         op.add_option("--bytes-per-inode", deprecated=1)
323         op.add_option("--fsprofile")
324         op.add_option("--encrypted", action="store_true", default=False)
325         op.add_option("--passphrase")
326         return op
327
328 class F11_Partition(F9_Partition):
329     removedKeywords = F9_Partition.removedKeywords
330     removedAttrs = F9_Partition.removedAttrs
331
332     def _getParser(self):
333         op = F9_Partition._getParser(self)
334         op.add_option("--start", deprecated=1)
335         op.add_option("--end", deprecated=1)
336         return op
337
338 class F12_Partition(F11_Partition):
339     removedKeywords = F11_Partition.removedKeywords
340     removedAttrs = F11_Partition.removedAttrs
341
342     def _getParser(self):
343         op = F11_Partition._getParser(self)
344         op.add_option("--escrowcert")
345         op.add_option("--backuppassphrase", action="store_true", default=False)
346         return op
347
348 class F14_Partition(F12_Partition):
349     removedKeywords = F12_Partition.removedKeywords
350     removedAttrs = F12_Partition.removedAttrs
351
352     def _getParser(self):
353         op = F12_Partition._getParser(self)
354         op.remove_option("--bytes-per-inode")
355         op.remove_option("--start")
356         op.remove_option("--end")
357         return op