From: Ed Bartosh <ed.bartosh@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [wic][PATCH 2/9] wic: add kickstart parser module
Date: Thu, 14 Jan 2016 14:12:52 +0200 [thread overview]
Message-ID: <324f3f4d48f32282e0e75ed58fc7b20a8e99fb7f.1452766193.git.ed.bartosh@linux.intel.com> (raw)
In-Reply-To: <cover.1452766193.git.ed.bartosh@linux.intel.com>
In-Reply-To: <cover.1452766193.git.ed.bartosh@linux.intel.com>
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.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
scripts/lib/wic/kickstart.py | 120 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 120 insertions(+)
create mode 100644 scripts/lib/wic/kickstart.py
diff --git a/scripts/lib/wic/kickstart.py b/scripts/lib/wic/kickstart.py
new file mode 100644
index 0000000..2208395
--- /dev/null
+++ b/scripts/lib/wic/kickstart.py
@@ -0,0 +1,120 @@
+#!/usr/bin/env python -tt
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# Copyright (c) 2016 Intel, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; version 2 of the License
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 59
+# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# DESCRIPTION
+# This module provides parser for kickstart format
+#
+# AUTHORS
+# Tom Zanussi <tom.zanussi (at] linux.intel.com>
+# Ed Bartosh <ed.bartosh> (at] linux.intel.com>
+
+
+
+import shlex
+from argparse import ArgumentParser, ArgumentTypeError
+
+from wic.partition import Partition
+
+def sizetype(arg):
+ """
+ Custom type for ArgumentParser
+ Converts size string in <num>[K|k|M|G] format into the integer value
+ """
+ if arg.isdigit():
+ return int(arg) * 1024L
+
+ if not arg[:-1].isdigit():
+ raise ArgumentTypeError("Invalid size: %r" % arg)
+
+ size = int(arg[:-1])
+ if arg.endswith("k") or arg.endswith("K"):
+ return size
+ if arg.endswith("M"):
+ return size * 1024L
+ if arg.endswith("G"):
+ return size * 1024L * 1024L
+
+ raise ArgumentTypeError("Invalid size: %r" % arg)
+
+def overheadtype(arg):
+ """
+ Custom type for ArgumentParser
+ Converts overhead string to float and checks if it's bigger than 1.0
+ """
+ try:
+ result = float(arg)
+ except ValueError:
+ raise ArgumentTypeError("Invalid value: %r" % arg)
+
+ if result < 1.0:
+ raise ArgumentTypeError("Overhead factor should be > 1.0" % arg)
+
+ return result
+
+class KickStart(object):
+ def __init__(self, confpath):
+
+ self.partitions = []
+ self.bootloader = None
+ self.lineno = 0
+
+ parser = ArgumentParser()
+ subparsers = parser.add_subparsers()
+
+ part = subparsers.add_parser('part')
+ part.add_argument('mountpoint')
+ part.add_argument('--active', action='store_true')
+ part.add_argument('--align', type=int)
+ part.add_argument("--extra-space", type=sizetype, default=10*1024L)
+ part.add_argument('--fsoptions', dest='fsopts')
+ part.add_argument('--fstype')
+ part.add_argument('--label')
+ part.add_argument('--no-table')
+ part.add_argument('--ondisk', '--ondrive', dest='disk')
+ part.add_argument("--overhead-factor", type=overheadtype, default=1.3)
+ part.add_argument('--part-type')
+ part.add_argument('--rootfs-dir')
+ part.add_argument('--size', type=sizetype, default=0)
+ part.add_argument('--source')
+ part.add_argument('--sourceparams')
+ part.add_argument('--use-uuid', action='store_true')
+ part.add_argument('--uuid')
+
+ bootloader = subparsers.add_parser('bootloader')
+ bootloader.add_argument('--append')
+ bootloader.add_argument('--configfile')
+ bootloader.add_argument('--ptable', choices=('msdos', 'gpt'),
+ default='msdos')
+ bootloader.add_argument('--timeout', type=int)
+ bootloader.add_argument('--source')
+
+ with open(confpath) as conf:
+ lineno = 0
+ for line in conf:
+ line = line.strip()
+ lineno += 1
+ if line and line[0] != '#':
+ parsed = parser.parse_args(shlex.split(line))
+ if line.startswith('part'):
+ self.partitions.append(Partition(parsed, lineno))
+ else:
+ if not self.bootloader:
+ self.bootloader = parsed
+ else:
+ raise KickStartError("Error: more than one bootloader specified")
--
2.1.4
next prev parent reply other threads:[~2016-01-14 14:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-14 12:12 [wic][PATCH 0/9] Reimplement kickstart parser Ed Bartosh
2016-01-14 12:12 ` [wic][PATCH 1/9] wic: add partition module Ed Bartosh
2016-01-14 12:12 ` Ed Bartosh [this message]
2016-01-14 12:12 ` [wic][PATCH 3/9] wic: use new kickstart parser Ed Bartosh
2016-01-14 12:12 ` [wic][PATCH 4/9] wic: remove pykickstart code Ed Bartosh
2016-01-14 12:12 ` [wic][PATCH 5/9] wic: adjust code for new data structure Ed Bartosh
2016-01-14 12:12 ` [wic][PATCH 6/9] wic: get rid of get_timeout getter Ed Bartosh
2016-01-14 12:12 ` [wic][PATCH 7/9] wic: get rid of get_rootfs and set_rootfs Ed Bartosh
2016-01-14 12:12 ` [wic][PATCH 8/9] wic: get rid of set_size and set_source_file setters Ed Bartosh
2016-01-14 12:12 ` [wic][PATCH 9/9] wic: get rid of 2 getters Ed Bartosh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=324f3f4d48f32282e0e75ed58fc7b20a8e99fb7f.1452766193.git.ed.bartosh@linux.intel.com \
--to=ed.bartosh@linux.intel.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox