summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/recipes-devtools/python/python-smartpm/smart-improve-error-reporting.patch91
-rw-r--r--meta/recipes-devtools/python/python-smartpm_git.bb1
2 files changed, 0 insertions, 92 deletions
diff --git a/meta/recipes-devtools/python/python-smartpm/smart-improve-error-reporting.patch b/meta/recipes-devtools/python/python-smartpm/smart-improve-error-reporting.patch
deleted file mode 100644
index b82265b3ff..0000000000
--- a/meta/recipes-devtools/python/python-smartpm/smart-improve-error-reporting.patch
+++ /dev/null
@@ -1,91 +0,0 @@
1Improve error reporting in smart
2
3Add code to check proper command line arguments for various
4smart commands. Exit with error if erroneous/additional arguments
5are given in the command line.
6
7Upstream-Status: Pending
8
9Signed-off-by: Bogdan Marinescu <bogdan.a.marinescu@intel.com>
10
11diff --git a/smart/util/optparse.py b/smart/util/optparse.py
12index 6fff1bc..f445a3b 100644
13--- a/smart/util/optparse.py
14+++ b/smart/util/optparse.py
15@@ -70,6 +70,8 @@ import sys, os
16 import types
17 import textwrap
18 from gettext import gettext as _
19+from smart import Error
20+import re
21
22 def _repr(self):
23 return "<%s at 0x%x: %s>" % (self.__class__.__name__, id(self), self)
24@@ -710,6 +712,12 @@ class Option:
25 self.action, self.dest, opt, value, values, parser)
26
27 def take_action(self, action, dest, opt, value, values, parser):
28+ # Keep all the options in the command line in the '_given_opts' array
29+ # This will be used later to validate the command line
30+ given_opts = getattr(parser.values, "_given_opts", [])
31+ user_opt = re.sub(r"^\-*", "", opt).replace("-", "_")
32+ given_opts.append(user_opt)
33+ setattr(parser.values, "_given_opts", given_opts)
34 if action == "store":
35 setattr(values, dest, value)
36 elif action == "store_const":
37@@ -821,6 +829,54 @@ class Values:
38 setattr(self, attr, value)
39 return getattr(self, attr)
40
41+ # Check if the given option has the specified number of arguments
42+ # Raise an error if the option has an invalid number of arguments
43+ # A negative number for 'nargs' means "at least |nargs| arguments are needed"
44+ def check_args_of_option(self, opt, nargs, err=None):
45+ given_opts = getattr(self, "_given_opts", [])
46+ if not opt in given_opts:
47+ return
48+ values = getattr(self, opt, [])
49+ if type(values) != type([]):
50+ return
51+ if nargs < 0:
52+ nargs = -nargs
53+ if len(values) >= nargs:
54+ return
55+ if not err:
56+ if nargs == 1:
57+ err = _("Option '%s' requires at least one argument") % opt
58+ else:
59+ err = _("Option '%s' requires at least %d arguments") % (opt, nargs)
60+ raise Error, err
61+ elif nargs == 0:
62+ if len( values ) == 0:
63+ return
64+ raise Error, err
65+ else:
66+ if len(values) == nargs:
67+ return
68+ if not err:
69+ if nargs == 1:
70+ err = _("Option '%s' requires one argument") % opt
71+ else:
72+ err = _("Option '%s' requires %d arguments") % (opt, nargs)
73+ raise Error, err
74+
75+ # Check that at least one of the options in 'actlist' was given as an argument
76+ # to the command 'cmdname'
77+ def ensure_action(self, cmdname, actlist):
78+ given_opts = getattr(self, "_given_opts", [])
79+ for action in actlist:
80+ if action in given_opts:
81+ return
82+ raise Error, _("No action specified for command '%s'") % cmdname
83+
84+ # Check if there are any other arguments left after parsing the command line and
85+ # raise an error if such arguments are found
86+ def check_remaining_args(self):
87+ if self.args:
88+ raise Error, _("Invalid argument(s) '%s'" % str(self.args))
89
90 class OptionContainer:
91
diff --git a/meta/recipes-devtools/python/python-smartpm_git.bb b/meta/recipes-devtools/python/python-smartpm_git.bb
index 0d37dae3cb..5acfb0aa09 100644
--- a/meta/recipes-devtools/python/python-smartpm_git.bb
+++ b/meta/recipes-devtools/python/python-smartpm_git.bb
@@ -15,7 +15,6 @@ SRC_URI = "\
15 git://github.com/smartpm/smart.git \ 15 git://github.com/smartpm/smart.git \
16 file://smartpm-rpm5-nodig.patch \ 16 file://smartpm-rpm5-nodig.patch \
17 file://smart-recommends.patch \ 17 file://smart-recommends.patch \
18 file://smart-improve-error-reporting.patch \
19 file://smart-channelsdir.patch \ 18 file://smart-channelsdir.patch \
20 file://smart-rpm-transaction-failure-check.patch \ 19 file://smart-rpm-transaction-failure-check.patch \
21 file://smart-attempt.patch \ 20 file://smart-attempt.patch \