From: biao716.wang Date: Tue, 16 Aug 2022 08:53:42 +0000 (+0900) Subject: fix warning:'Namespace' object is not iterable X-Git-Tag: accepted/tools/devbase/tools/20250527.103804~38 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8cbc8af335da55b6ddbdad6796e55c56a38d9af6;p=tools%2Fmic.git fix warning:'Namespace' object is not iterable kickstart: allow partitions without mount points https://review.tizen.org/gerrit/gitweb?p=tools/mic.git;a=commit;h=86d6bfc99a34380e4f9576bbd4c6d332ccd15f0c Change-Id: I1be64d0ecec6f69e126a90dde5c84add9bd699ab Signed-off-by: biao716.wang --- diff --git a/mic/3rdparty/pykickstart/base.py b/mic/3rdparty/pykickstart/base.py index 31f7301..b1b7c19 100644 --- a/mic/3rdparty/pykickstart/base.py +++ b/mic/3rdparty/pykickstart/base.py @@ -178,7 +178,7 @@ class KickstartCommand(KickstartObject): of objects (like partitions, network devices, etc.) and need to populate a Data object. """ - for (key, val) in list(vars(namespace).items()): + for (key, val) in vars(namespace).items(): if val is not None: setattr(obj, key, val) diff --git a/mic/3rdparty/pykickstart/commands/partition.py b/mic/3rdparty/pykickstart/commands/partition.py index a4d6fc0..703f290 100644 --- a/mic/3rdparty/pykickstart/commands/partition.py +++ b/mic/3rdparty/pykickstart/commands/partition.py @@ -343,42 +343,6 @@ class FC3_Partition(KickstartCommand): If partitioning fails for any reason, diagnostic messages will appear on virtual console 3.""", version=FC3) - op.add_argument("mntpoint", metavar="", type=mountpoint, nargs=1, - version=FC3, help=""" - The ```` is where the partition will be mounted - and must be of one of the following forms: - - ``/`` - - For example, ``/``, ``/usr``, ``/home`` - - ``swap`` - - The partition will be used as swap space. - - ``raid.`` - - The partition will be used for software RAID. - Refer to the ``raid`` command. - - ``pv.`` - - The partition will be used for LVM. Refer to the - ``logvol`` command. - - ``btrfs.`` - - The partition will be used for BTRFS volume. Rerefer to - the ``btrfs`` command. - - ``biosboot`` - - The partition will be used for a BIOS Boot Partition. As - of Fedora 16 there must be a biosboot partition for the - bootloader to be successfully installed onto a disk that - contains a GPT/GUID partition table. Rerefer to the - ``bootloader`` command. - """) op.add_argument("--active", action="store_true", default=False, version=FC3, help="Set partition as active") op.add_argument("--asprimary", dest="primOnly", action="store_true", @@ -440,7 +404,7 @@ class FC3_Partition(KickstartCommand): return op def parse(self, args): - (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) + (ns, extra) = self.op.parse_known_args(args=args, lineno=self.lineno) pd = self.dataClass() # pylint: disable=not-callable self.set_to_obj(ns, pd) @@ -451,7 +415,6 @@ class FC3_Partition(KickstartCommand): warnings.warn(_("A partition with the mountpoint %s has already been defined.") % pd.mountpoint) else: pd.mountpoint = None - return pd def dataList(self): diff --git a/mic/3rdparty/pykickstart/commands/snapshot.py b/mic/3rdparty/pykickstart/commands/snapshot.py index c002a58..22d687c 100644 --- a/mic/3rdparty/pykickstart/commands/snapshot.py +++ b/mic/3rdparty/pykickstart/commands/snapshot.py @@ -100,7 +100,7 @@ class F26_Snapshot(KickstartCommand): help=""" Name of the newly created snapshot.""") # Show all possible options in meta message - meta_msg = "<%s>" % ("|".join(list(self.whenMap.keys()))) + meta_msg = "<%s>" % ("|".join(self.whenMap.keys())) op.add_argument("--when", metavar=meta_msg, type=self._when_cb, version=F26, required=True, help=""" You can specify two possible values: ``pre-install`` and ``post-install``. @@ -132,9 +132,9 @@ class F26_Snapshot(KickstartCommand): raise KickstartParseError(msg, lineno=self.lineno) # Check if value in a '--when' param is valid - if snap_data.when != "" and snap_data.when not in list(self.whenMap.values()): + if snap_data.when != "" and snap_data.when not in self.whenMap.values(): msg = (_("Snapshot when param must have one of these values %s!") % - list(self.whenMap.keys())) + self.whenMap.keys()) raise KickstartParseError(msg, lineno=self.lineno) return snap_data diff --git a/mic/3rdparty/pykickstart/sections.py b/mic/3rdparty/pykickstart/sections.py index e793dcb..2aafd14 100644 --- a/mic/3rdparty/pykickstart/sections.py +++ b/mic/3rdparty/pykickstart/sections.py @@ -822,7 +822,7 @@ class PackageSection(Section): for arg in args: for option, new_option in \ - list({"--instLangs": "--inst-langs", "--excludeWeakdeps": "--exclude-weakdeps"}.items()): + {"--instLangs": "--inst-langs", "--excludeWeakdeps": "--exclude-weakdeps"}.items(): if option in arg: warnings.warn(_("The %(option)s option on line %(lineno)s will be deprecated in " "future releases. Please modify your kickstart file to replace " diff --git a/mic/cmd_create.py b/mic/cmd_create.py index adc6ac0..c5a4827 100755 --- a/mic/cmd_create.py +++ b/mic/cmd_create.py @@ -156,7 +156,7 @@ def main(parser, args, argv): if args.block_recommends: configmgr.create['block_recommends']=args.block_recommends -if args.runtime: + if args.runtime: configmgr.set_runtime(args.runtime) if args.use_mic_in_bootstrap: diff --git a/mic/kickstart/custom_commands/desktop.py b/mic/kickstart/custom_commands/desktop.py index bb65417..899483b 100644 --- a/mic/kickstart/custom_commands/desktop.py +++ b/mic/kickstart/custom_commands/desktop.py @@ -21,6 +21,7 @@ from pykickstart.base import * from pykickstart.errors import * from pykickstart.options import * from pykickstart.version import DEVEL +from pykickstart.i18n import _ class Mic_Desktop(KickstartCommand): def __init__(self, writePriority=0, @@ -28,10 +29,8 @@ class Mic_Desktop(KickstartCommand): defaultdm=None, autologinuser=None, session=None): - KickstartCommand.__init__(self, writePriority) - self.__new_version = False self.op = self._getParser() self.defaultdesktop = defaultdesktop @@ -57,14 +56,7 @@ class Mic_Desktop(KickstartCommand): return retval def _getParser(self): - try: - #ingnore this pylit error, the lineno argument exist in olg version. using this way can compate old version. - op = KSOptionParser(prog='desktop', description='desktop', version=DEVEL, lineno=self.lineno) #pylint: disable=unexpected-keyword-arg - except TypeError: - # the latest version has not lineno argument - op = KSOptionParser(prog='desktop', description='desktop', version=DEVEL) - self.__new_version = True - + op = KSOptionParser(prog='desktop', description='desktop', version=DEVEL) op.add_argument("--defaultdesktop", dest="defaultdesktop", action="store", type=str, @@ -84,14 +76,9 @@ class Mic_Desktop(KickstartCommand): return op def parse(self, args): - if self.__new_version: - (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) - else: - (opts, extra) = self.op.parse_args(args=args) - - if extra: - m = ("Unexpected arguments to %(command)s command: %(options)s") \ - % {"command": "desktop", "options": extra} - raise KickstartValueError (formatErrorMsg(self.lineno, msg=m)) - self._setToSelf(self.op, opts) + (ns, extra) = self.op.parse_known_args(args=args, lineno=self.lineno) + if any(arg for arg in extra if arg.startswith("-")): + mapping = {"command": "desktop", "options": extra} + raise KickstartParseError(_("Unexpected arguments to %(command)s command: %(options)s") % mapping, lineno=self.lineno) + self.set_to_self(ns) diff --git a/mic/kickstart/custom_commands/installerfw.py b/mic/kickstart/custom_commands/installerfw.py index 51c4be2..bce1b8e 100644 --- a/mic/kickstart/custom_commands/installerfw.py +++ b/mic/kickstart/custom_commands/installerfw.py @@ -20,6 +20,8 @@ from pykickstart.options import * from mic import msger from pykickstart.version import DEVEL +from pykickstart.i18n import _ + class Mic_installerfw(KickstartCommand): """ This class implements the "installerfw_plugins" KS option. The argument of the option is a comman-separated list of MIC features which have to be @@ -54,13 +56,16 @@ class Mic_installerfw(KickstartCommand): return op def parse(self, args): - (_, extra) = self.op.parse_args(args=args, lineno=self.lineno) + print("NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN") + (ns, extra) = self.op.parse_known_args(args=args, lineno=self.lineno) + self.set_to_self(ns) if len(extra) != 1: - msg = "Kickstart command \"%s\" requires one " \ - "argumet - a list of legacy features to disable" % self.currentCmd - raise KickstartValueError (formatErrorMsg(self.lineno, msg = msg)) - - self.features = extra[0].split(",") + raise KickstartParseError(_("Kickstart command %s requires one argument") % "installerfw", lineno=self.lineno) + elif any(arg for arg in extra if arg.startswith("-")): + mapping = {"command": "installerfw", "options": extra} + raise KickstartParseError(_("Unexpected arguments to %(command)s command: %(options)s") % mapping, lineno=self.lineno) + else: + self.features = extra[0].split(",") return self