From e7bedb91a7114dda22a97b57de6e98d7794d8a1e Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Mon, 18 Jan 2016 14:22:46 +0200 Subject: wic: rename kickstarter.py -> ksparser.py kickstarter.py was not the best name for this module as previously there was a directory with the same name in scripts/lib/wic/. All files were removed from it, but .pyc files could still stay there causing imports from wic.kickstart to fail with ImportError: cannot import name KickStart. (From OE-Core rev: b9d400be06bc4a4bb9f9c6a6a0c8e5ecfd4e2dfb) Signed-off-by: Ed Bartosh Signed-off-by: Richard Purdie --- scripts/lib/wic/conf.py | 2 +- scripts/lib/wic/kickstart.py | 136 ------------------------------------------- scripts/lib/wic/ksparser.py | 136 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 137 deletions(-) delete mode 100644 scripts/lib/wic/kickstart.py create mode 100644 scripts/lib/wic/ksparser.py diff --git a/scripts/lib/wic/conf.py b/scripts/lib/wic/conf.py index 922a0f68e6..f7d56d046b 100644 --- a/scripts/lib/wic/conf.py +++ b/scripts/lib/wic/conf.py @@ -17,7 +17,7 @@ import os -from wic.kickstart import KickStart, KickStartError +from wic.ksparser import KickStart, KickStartError from wic import msger from wic.utils import misc diff --git a/scripts/lib/wic/kickstart.py b/scripts/lib/wic/kickstart.py deleted file mode 100644 index 7dbe052714..0000000000 --- a/scripts/lib/wic/kickstart.py +++ /dev/null @@ -1,136 +0,0 @@ -#!/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 -# Ed Bartosh (at] linux.intel.com> - - - -import shlex -from argparse import ArgumentParser, ArgumentError, ArgumentTypeError - -from wic.partition import Partition - -class KickStartError(Exception): - pass - -class KickStartParser(ArgumentParser): - """ - This class overwrites error method to throw exception - instead of producing usage message(default argparse behavior). - """ - def error(self, message): - raise ArgumentError(None, message) - -def sizetype(arg): - """ - Custom type for ArgumentParser - Converts size string in [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 = KickStartParser() - 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] != '#': - try: - parsed = parser.parse_args(shlex.split(line)) - except ArgumentError as err: - raise KickStartError('%s:%d: %s' % \ - (confpath, lineno, err)) - if line.startswith('part'): - self.partitions.append(Partition(parsed, lineno)) - else: - if not self.bootloader: - self.bootloader = parsed - else: - raise KickStartError("%s:%d: more than one bootloader "\ - "specified" % (confpath, lineno)) diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py new file mode 100644 index 0000000000..7dbe052714 --- /dev/null +++ b/scripts/lib/wic/ksparser.py @@ -0,0 +1,136 @@ +#!/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 +# Ed Bartosh (at] linux.intel.com> + + + +import shlex +from argparse import ArgumentParser, ArgumentError, ArgumentTypeError + +from wic.partition import Partition + +class KickStartError(Exception): + pass + +class KickStartParser(ArgumentParser): + """ + This class overwrites error method to throw exception + instead of producing usage message(default argparse behavior). + """ + def error(self, message): + raise ArgumentError(None, message) + +def sizetype(arg): + """ + Custom type for ArgumentParser + Converts size string in [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 = KickStartParser() + 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] != '#': + try: + parsed = parser.parse_args(shlex.split(line)) + except ArgumentError as err: + raise KickStartError('%s:%d: %s' % \ + (confpath, lineno, err)) + if line.startswith('part'): + self.partitions.append(Partition(parsed, lineno)) + else: + if not self.bootloader: + self.bootloader = parsed + else: + raise KickStartError("%s:%d: more than one bootloader "\ + "specified" % (confpath, lineno)) -- cgit 1.2.3-korg