summaryrefslogtreecommitdiffstats
path: root/scripts/lib/mic/3rdparty/pykickstart/commands/partition.py
diff options
context:
space:
mode:
authorTom Zanussi <tom.zanussi@linux.intel.com>2013-08-24 15:31:34 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-10-01 22:56:03 +0100
commit9fc88f96d40b17c90bac53b90045a87b2d2cff84 (patch)
tree63010e5aabf895697655baf89bd668d6752b3f97 /scripts/lib/mic/3rdparty/pykickstart/commands/partition.py
parent53a1d9a788fd9f970af980da2ab975cca60685c4 (diff)
downloadpoky-9fc88f96d40b17c90bac53b90045a87b2d2cff84.tar.gz
wic: Add mic w/pykickstart
This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/mic/3rdparty/pykickstart/commands/partition.py')
-rw-r--r--scripts/lib/mic/3rdparty/pykickstart/commands/partition.py353
1 files changed, 353 insertions, 0 deletions
diff --git a/scripts/lib/mic/3rdparty/pykickstart/commands/partition.py b/scripts/lib/mic/3rdparty/pykickstart/commands/partition.py
new file mode 100644
index 0000000000..e65e012d02
--- /dev/null
+++ b/scripts/lib/mic/3rdparty/pykickstart/commands/partition.py
@@ -0,0 +1,353 @@
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 RHEL5_PartData(FC4_PartData):
119 removedKeywords = FC4_PartData.removedKeywords
120 removedAttrs = FC4_PartData.removedAttrs
121
122 def __init__(self, *args, **kwargs):
123 FC4_PartData.__init__(self, *args, **kwargs)
124 self.encrypted = kwargs.get("encrypted", False)
125 self.passphrase = kwargs.get("passphrase", "")
126
127 def _getArgsAsStr(self):
128 retval = FC4_PartData._getArgsAsStr(self)
129
130 if self.encrypted:
131 retval += " --encrypted"
132
133 if self.passphrase != "":
134 retval += " --passphrase=\"%s\"" % self.passphrase
135
136 return retval
137
138class F9_PartData(FC4_PartData):
139 removedKeywords = FC4_PartData.removedKeywords + ["bytesPerInode"]
140 removedAttrs = FC4_PartData.removedAttrs + ["bytesPerInode"]
141
142 def __init__(self, *args, **kwargs):
143 FC4_PartData.__init__(self, *args, **kwargs)
144 self.deleteRemovedAttrs()
145
146 self.fsopts = kwargs.get("fsopts", "")
147 self.label = kwargs.get("label", "")
148 self.fsprofile = kwargs.get("fsprofile", "")
149 self.encrypted = kwargs.get("encrypted", False)
150 self.passphrase = kwargs.get("passphrase", "")
151
152 def _getArgsAsStr(self):
153 retval = FC4_PartData._getArgsAsStr(self)
154
155 if self.fsprofile != "":
156 retval += " --fsprofile=\"%s\"" % self.fsprofile
157 if self.encrypted:
158 retval += " --encrypted"
159
160 if self.passphrase != "":
161 retval += " --passphrase=\"%s\"" % self.passphrase
162
163 return retval
164
165class F11_PartData(F9_PartData):
166 removedKeywords = F9_PartData.removedKeywords + ["start", "end"]
167 removedAttrs = F9_PartData.removedAttrs + ["start", "end"]
168
169class F12_PartData(F11_PartData):
170 removedKeywords = F11_PartData.removedKeywords
171 removedAttrs = F11_PartData.removedAttrs
172
173 def __init__(self, *args, **kwargs):
174 F11_PartData.__init__(self, *args, **kwargs)
175
176 self.escrowcert = kwargs.get("escrowcert", "")
177 self.backuppassphrase = kwargs.get("backuppassphrase", False)
178
179 def _getArgsAsStr(self):
180 retval = F11_PartData._getArgsAsStr(self)
181
182 if self.encrypted and self.escrowcert != "":
183 retval += " --escrowcert=\"%s\"" % self.escrowcert
184
185 if self.backuppassphrase:
186 retval += " --backuppassphrase"
187
188 return retval
189
190F14_PartData = F12_PartData
191
192class FC3_Partition(KickstartCommand):
193 removedKeywords = KickstartCommand.removedKeywords
194 removedAttrs = KickstartCommand.removedAttrs
195
196 def __init__(self, writePriority=130, *args, **kwargs):
197 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
198 self.op = self._getParser()
199
200 self.partitions = kwargs.get("partitions", [])
201
202 def __str__(self):
203 retval = ""
204
205 for part in self.partitions:
206 retval += part.__str__()
207
208 if retval != "":
209 return "# Disk partitioning information\n" + retval
210 else:
211 return ""
212
213 def _getParser(self):
214 def part_cb (option, opt_str, value, parser):
215 if value.startswith("/dev/"):
216 parser.values.ensure_value(option.dest, value[5:])
217 else:
218 parser.values.ensure_value(option.dest, value)
219
220 op = KSOptionParser()
221 op.add_option("--active", dest="active", action="store_true",
222 default=False)
223 op.add_option("--asprimary", dest="primOnly", action="store_true",
224 default=False)
225 op.add_option("--end", dest="end", action="store", type="int",
226 nargs=1)
227 op.add_option("--fstype", "--type", dest="fstype")
228 op.add_option("--grow", dest="grow", action="store_true", default=False)
229 op.add_option("--maxsize", dest="maxSizeMB", action="store", type="int",
230 nargs=1)
231 op.add_option("--noformat", dest="format", action="store_false",
232 default=True)
233 op.add_option("--onbiosdisk", dest="onbiosdisk")
234 op.add_option("--ondisk", "--ondrive", dest="disk")
235 op.add_option("--onpart", "--usepart", dest="onPart", action="callback",
236 callback=part_cb, nargs=1, type="string")
237 op.add_option("--recommended", dest="recommended", action="store_true",
238 default=False)
239 op.add_option("--size", dest="size", action="store", type="int",
240 nargs=1)
241 op.add_option("--start", dest="start", action="store", type="int",
242 nargs=1)
243 return op
244
245 def parse(self, args):
246 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
247
248 pd = self.handler.PartData()
249 self._setToObj(self.op, opts, pd)
250 pd.lineno = self.lineno
251 if extra:
252 pd.mountpoint = extra[0]
253 if pd in self.dataList():
254 warnings.warn(_("A partition with the mountpoint %s has already been defined.") % pd.mountpoint)
255 else:
256 pd.mountpoint = None
257
258 return pd
259
260 def dataList(self):
261 return self.partitions
262
263class FC4_Partition(FC3_Partition):
264 removedKeywords = FC3_Partition.removedKeywords
265 removedAttrs = FC3_Partition.removedAttrs
266
267 def __init__(self, writePriority=130, *args, **kwargs):
268 FC3_Partition.__init__(self, writePriority, *args, **kwargs)
269
270 def part_cb (option, opt_str, value, parser):
271 if value.startswith("/dev/"):
272 parser.values.ensure_value(option.dest, value[5:])
273 else:
274 parser.values.ensure_value(option.dest, value)
275
276 def _getParser(self):
277 op = FC3_Partition._getParser(self)
278 op.add_option("--bytes-per-inode", dest="bytesPerInode", action="store",
279 type="int", nargs=1)
280 op.add_option("--fsoptions", dest="fsopts")
281 op.add_option("--label", dest="label")
282 return op
283
284class RHEL5_Partition(FC4_Partition):
285 removedKeywords = FC4_Partition.removedKeywords
286 removedAttrs = FC4_Partition.removedAttrs
287
288 def __init__(self, writePriority=130, *args, **kwargs):
289 FC4_Partition.__init__(self, writePriority, *args, **kwargs)
290
291 def part_cb (option, opt_str, value, parser):
292 if value.startswith("/dev/"):
293 parser.values.ensure_value(option.dest, value[5:])
294 else:
295 parser.values.ensure_value(option.dest, value)
296
297 def _getParser(self):
298 op = FC4_Partition._getParser(self)
299 op.add_option("--encrypted", action="store_true", default=False)
300 op.add_option("--passphrase")
301 return op
302
303class F9_Partition(FC4_Partition):
304 removedKeywords = FC4_Partition.removedKeywords
305 removedAttrs = FC4_Partition.removedAttrs
306
307 def __init__(self, writePriority=130, *args, **kwargs):
308 FC4_Partition.__init__(self, writePriority, *args, **kwargs)
309
310 def part_cb (option, opt_str, value, parser):
311 if value.startswith("/dev/"):
312 parser.values.ensure_value(option.dest, value[5:])
313 else:
314 parser.values.ensure_value(option.dest, value)
315
316 def _getParser(self):
317 op = FC4_Partition._getParser(self)
318 op.add_option("--bytes-per-inode", deprecated=1)
319 op.add_option("--fsprofile")
320 op.add_option("--encrypted", action="store_true", default=False)
321 op.add_option("--passphrase")
322 return op
323
324class F11_Partition(F9_Partition):
325 removedKeywords = F9_Partition.removedKeywords
326 removedAttrs = F9_Partition.removedAttrs
327
328 def _getParser(self):
329 op = F9_Partition._getParser(self)
330 op.add_option("--start", deprecated=1)
331 op.add_option("--end", deprecated=1)
332 return op
333
334class F12_Partition(F11_Partition):
335 removedKeywords = F11_Partition.removedKeywords
336 removedAttrs = F11_Partition.removedAttrs
337
338 def _getParser(self):
339 op = F11_Partition._getParser(self)
340 op.add_option("--escrowcert")
341 op.add_option("--backuppassphrase", action="store_true", default=False)
342 return op
343
344class F14_Partition(F12_Partition):
345 removedKeywords = F12_Partition.removedKeywords
346 removedAttrs = F12_Partition.removedAttrs
347
348 def _getParser(self):
349 op = F12_Partition._getParser(self)
350 op.remove_option("--bytes-per-inode")
351 op.remove_option("--start")
352 op.remove_option("--end")
353 return op