summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2016-01-14 14:12:52 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-01-18 11:47:05 +0000
commitf572f442146e3a36ac1f6994d561afaebc2d9092 (patch)
tree1007238eefb4df2f7c8084802f081970222f6629 /scripts/lib/wic
parente5e1905c367db00ed73aa2f893e4fa70e4d701fa (diff)
downloadpoky-f572f442146e3a36ac1f6994d561afaebc2d9092.tar.gz
wic: add kickstart parser module
This module will replace existing pykickstart machinery it contains only option used by wic, it's simple and clear. And It will allow to remove a lot of old complex code from 3rdparty/pykickstart/ and kickstart/custom_commands. (From OE-Core rev: c7b67ccfda8b22c090aa74d96b7c9af5a97a9a98) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic')
-rw-r--r--scripts/lib/wic/kickstart.py120
1 files changed, 120 insertions, 0 deletions
diff --git a/scripts/lib/wic/kickstart.py b/scripts/lib/wic/kickstart.py
new file mode 100644
index 0000000000..22083950f0
--- /dev/null
+++ b/scripts/lib/wic/kickstart.py
@@ -0,0 +1,120 @@
1#!/usr/bin/env python -tt
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
5# Copyright (c) 2016 Intel, Inc.
6#
7# This program is free software; you can redistribute it and/or modify it
8# under the terms of the GNU General Public License as published by the Free
9# Software Foundation; version 2 of the License
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14# for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program; if not, write to the Free Software Foundation, Inc., 59
18# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19#
20# DESCRIPTION
21# This module provides parser for kickstart format
22#
23# AUTHORS
24# Tom Zanussi <tom.zanussi (at] linux.intel.com>
25# Ed Bartosh <ed.bartosh> (at] linux.intel.com>
26
27
28
29import shlex
30from argparse import ArgumentParser, ArgumentTypeError
31
32from wic.partition import Partition
33
34def sizetype(arg):
35 """
36 Custom type for ArgumentParser
37 Converts size string in <num>[K|k|M|G] format into the integer value
38 """
39 if arg.isdigit():
40 return int(arg) * 1024L
41
42 if not arg[:-1].isdigit():
43 raise ArgumentTypeError("Invalid size: %r" % arg)
44
45 size = int(arg[:-1])
46 if arg.endswith("k") or arg.endswith("K"):
47 return size
48 if arg.endswith("M"):
49 return size * 1024L
50 if arg.endswith("G"):
51 return size * 1024L * 1024L
52
53 raise ArgumentTypeError("Invalid size: %r" % arg)
54
55def overheadtype(arg):
56 """
57 Custom type for ArgumentParser
58 Converts overhead string to float and checks if it's bigger than 1.0
59 """
60 try:
61 result = float(arg)
62 except ValueError:
63 raise ArgumentTypeError("Invalid value: %r" % arg)
64
65 if result < 1.0:
66 raise ArgumentTypeError("Overhead factor should be > 1.0" % arg)
67
68 return result
69
70class KickStart(object):
71 def __init__(self, confpath):
72
73 self.partitions = []
74 self.bootloader = None
75 self.lineno = 0
76
77 parser = ArgumentParser()
78 subparsers = parser.add_subparsers()
79
80 part = subparsers.add_parser('part')
81 part.add_argument('mountpoint')
82 part.add_argument('--active', action='store_true')
83 part.add_argument('--align', type=int)
84 part.add_argument("--extra-space", type=sizetype, default=10*1024L)
85 part.add_argument('--fsoptions', dest='fsopts')
86 part.add_argument('--fstype')
87 part.add_argument('--label')
88 part.add_argument('--no-table')
89 part.add_argument('--ondisk', '--ondrive', dest='disk')
90 part.add_argument("--overhead-factor", type=overheadtype, default=1.3)
91 part.add_argument('--part-type')
92 part.add_argument('--rootfs-dir')
93 part.add_argument('--size', type=sizetype, default=0)
94 part.add_argument('--source')
95 part.add_argument('--sourceparams')
96 part.add_argument('--use-uuid', action='store_true')
97 part.add_argument('--uuid')
98
99 bootloader = subparsers.add_parser('bootloader')
100 bootloader.add_argument('--append')
101 bootloader.add_argument('--configfile')
102 bootloader.add_argument('--ptable', choices=('msdos', 'gpt'),
103 default='msdos')
104 bootloader.add_argument('--timeout', type=int)
105 bootloader.add_argument('--source')
106
107 with open(confpath) as conf:
108 lineno = 0
109 for line in conf:
110 line = line.strip()
111 lineno += 1
112 if line and line[0] != '#':
113 parsed = parser.parse_args(shlex.split(line))
114 if line.startswith('part'):
115 self.partitions.append(Partition(parsed, lineno))
116 else:
117 if not self.bootloader:
118 self.bootloader = parsed
119 else:
120 raise KickStartError("Error: more than one bootloader specified")