mirror of
https://git.yoctoproject.org/git/poky
synced 2026-01-01 13:58:04 +00:00
* Remove the following patches since the are already in the source: smart-config-ignore-all-recommends.patch smart-conflict-provider.patch smart-dflags.patch smart-filename-NAME_MAX.patch smart-flag-exclude-packages.patch smart-flag-ignore-recommends.patch smart-metadata-match.patch smart-multilib-fixes.patch smart-rpm-extra-macros.patch smart-rpm-md-parse.patch smart-rpm-root.patch smart-tmpdir.patch smart-yaml-error.patch * Update the following patches, part of the code are already in the source: smart-attempt.patch smart-improve-error-reporting.patch smart-recommends.patch smartpm-rpm5-nodig.patch * Use github and git repo as the SRC_URI. (From OE-Core rev: 5fc580fc444e45d00de0e50d32b6e6e0b2e6b7ea) Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
92 lines
3.4 KiB
Diff
92 lines
3.4 KiB
Diff
Improve error reporting in smart
|
|
|
|
Add code to check proper command line arguments for various
|
|
smart commands. Exit with error if erroneous/additional arguments
|
|
are given in the command line.
|
|
|
|
Upstream-Status: Pending
|
|
|
|
Signed-off-by: Bogdan Marinescu <bogdan.a.marinescu@intel.com>
|
|
|
|
diff --git a/smart/util/optparse.py b/smart/util/optparse.py
|
|
index 6fff1bc..f445a3b 100644
|
|
--- a/smart/util/optparse.py
|
|
+++ b/smart/util/optparse.py
|
|
@@ -70,6 +70,8 @@ import sys, os
|
|
import types
|
|
import textwrap
|
|
from gettext import gettext as _
|
|
+from smart import Error
|
|
+import re
|
|
|
|
def _repr(self):
|
|
return "<%s at 0x%x: %s>" % (self.__class__.__name__, id(self), self)
|
|
@@ -710,6 +712,12 @@ class Option:
|
|
self.action, self.dest, opt, value, values, parser)
|
|
|
|
def take_action(self, action, dest, opt, value, values, parser):
|
|
+ # Keep all the options in the command line in the '_given_opts' array
|
|
+ # This will be used later to validate the command line
|
|
+ given_opts = getattr(parser.values, "_given_opts", [])
|
|
+ user_opt = re.sub(r"^\-*", "", opt).replace("-", "_")
|
|
+ given_opts.append(user_opt)
|
|
+ setattr(parser.values, "_given_opts", given_opts)
|
|
if action == "store":
|
|
setattr(values, dest, value)
|
|
elif action == "store_const":
|
|
@@ -821,6 +829,54 @@ class Values:
|
|
setattr(self, attr, value)
|
|
return getattr(self, attr)
|
|
|
|
+ # Check if the given option has the specified number of arguments
|
|
+ # Raise an error if the option has an invalid number of arguments
|
|
+ # A negative number for 'nargs' means "at least |nargs| arguments are needed"
|
|
+ def check_args_of_option(self, opt, nargs, err=None):
|
|
+ given_opts = getattr(self, "_given_opts", [])
|
|
+ if not opt in given_opts:
|
|
+ return
|
|
+ values = getattr(self, opt, [])
|
|
+ if type(values) != type([]):
|
|
+ return
|
|
+ if nargs < 0:
|
|
+ nargs = -nargs
|
|
+ if len(values) >= nargs:
|
|
+ return
|
|
+ if not err:
|
|
+ if nargs == 1:
|
|
+ err = _("Option '%s' requires at least one argument") % opt
|
|
+ else:
|
|
+ err = _("Option '%s' requires at least %d arguments") % (opt, nargs)
|
|
+ raise Error, err
|
|
+ elif nargs == 0:
|
|
+ if len( values ) == 0:
|
|
+ return
|
|
+ raise Error, err
|
|
+ else:
|
|
+ if len(values) == nargs:
|
|
+ return
|
|
+ if not err:
|
|
+ if nargs == 1:
|
|
+ err = _("Option '%s' requires one argument") % opt
|
|
+ else:
|
|
+ err = _("Option '%s' requires %d arguments") % (opt, nargs)
|
|
+ raise Error, err
|
|
+
|
|
+ # Check that at least one of the options in 'actlist' was given as an argument
|
|
+ # to the command 'cmdname'
|
|
+ def ensure_action(self, cmdname, actlist):
|
|
+ given_opts = getattr(self, "_given_opts", [])
|
|
+ for action in actlist:
|
|
+ if action in given_opts:
|
|
+ return
|
|
+ raise Error, _("No action specified for command '%s'") % cmdname
|
|
+
|
|
+ # Check if there are any other arguments left after parsing the command line and
|
|
+ # raise an error if such arguments are found
|
|
+ def check_remaining_args(self):
|
|
+ if self.args:
|
|
+ raise Error, _("Invalid argument(s) '%s'" % str(self.args))
|
|
|
|
class OptionContainer:
|
|
|