|
|
65d6ac |
From e9a4bc14e15115e3493781fe8487fb4bd575ae9e Mon Sep 17 00:00:00 2001
|
|
|
65d6ac |
From: John Kacur <jkacur@redhat.com>
|
|
|
65d6ac |
Date: Mon, 30 May 2016 20:31:37 +0200
|
|
|
65d6ac |
Subject: [PATCH] tuna: tuna-cmd: Display usage instead of traceback -c missing
|
|
|
65d6ac |
args
|
|
|
65d6ac |
|
|
|
65d6ac |
Display a usage messaage instead of a python traceback when a required
|
|
|
65d6ac |
argument to the -c or --cpus is missing, or when the argument doesn't
|
|
|
65d6ac |
make sense. (Such as passing a nonsense string, instead of a comma separated list of numbers)
|
|
|
65d6ac |
|
|
|
65d6ac |
- In function pick_op, handle the unusual but possible case where an
|
|
|
65d6ac |
empty string is passed as an argument.
|
|
|
65d6ac |
- Display a usage message upon ValueError when caling cpustring_to_list
|
|
|
65d6ac |
when processing the -c option
|
|
|
65d6ac |
|
|
|
65d6ac |
This fixes various erroneous or missing input to -c, such as the
|
|
|
65d6ac |
following
|
|
|
65d6ac |
|
|
|
65d6ac |
./tuna-cmd.py -c -P
|
|
|
65d6ac |
Traceback (most recent call last):
|
|
|
65d6ac |
File "./tuna-cmd.py", line 656, in <module>
|
|
|
65d6ac |
main()
|
|
|
65d6ac |
File "./tuna-cmd.py", line 494, in main
|
|
|
65d6ac |
op_list = tuna.cpustring_to_list(a)
|
|
|
65d6ac |
File "/home/jkacur/source/tuna/tuna/tuna.py", line 124, in
|
|
|
65d6ac |
cpustring_to_list
|
|
|
65d6ac |
ends = [ int(a, 0) for a in field.split("-") ]
|
|
|
65d6ac |
ValueError: invalid literal for int() with base 0: 'P'
|
|
|
65d6ac |
|
|
|
65d6ac |
./tuna-cmd.py -c "" -P
|
|
|
65d6ac |
Traceback (most recent call last):
|
|
|
65d6ac |
File "./tuna-cmd.py", line 656, in <module>
|
|
|
65d6ac |
main()
|
|
|
65d6ac |
File "./tuna-cmd.py", line 493, in main
|
|
|
65d6ac |
(op, a) = pick_op(a)
|
|
|
65d6ac |
File "./tuna-cmd.py", line 408, in pick_op
|
|
|
65d6ac |
if argument[0] in ('+', '-'):
|
|
|
65d6ac |
IndexError: string index out of range
|
|
|
65d6ac |
|
|
|
65d6ac |
./tuna-cmd.py -c "nonesense" -P
|
|
|
65d6ac |
Traceback (most recent call last):
|
|
|
65d6ac |
File "./tuna-cmd.py", line 656, in <module>
|
|
|
65d6ac |
main()
|
|
|
65d6ac |
File "./tuna-cmd.py", line 494, in main
|
|
|
65d6ac |
op_list = tuna.cpustring_to_list(a)
|
|
|
65d6ac |
File "/home/jkacur/source/tuna/tuna/tuna.py", line 124, in
|
|
|
65d6ac |
cpustring_to_list
|
|
|
65d6ac |
ends = [ int(a, 0) for a in field.split("-") ]
|
|
|
65d6ac |
ValueError: invalid literal for int() with base 0: 'nonesense'
|
|
|
65d6ac |
|
|
|
65d6ac |
This fixes bugzilla 1268287
|
|
|
65d6ac |
|
|
|
65d6ac |
Signed-off-by: John Kacur <jkacur@redhat.com>
|
|
|
65d6ac |
---
|
|
|
65d6ac |
tuna-cmd.py | 8 +++++++-
|
|
|
65d6ac |
1 file changed, 7 insertions(+), 1 deletion(-)
|
|
|
65d6ac |
|
|
|
65d6ac |
diff --git a/tuna-cmd.py b/tuna-cmd.py
|
|
|
65d6ac |
index ae4f78ab7d56..3c9bfaa50bb4 100755
|
|
|
65d6ac |
--- a/tuna-cmd.py
|
|
|
65d6ac |
+++ b/tuna-cmd.py
|
|
|
65d6ac |
@@ -405,6 +405,8 @@ def irq_mapper(s):
|
|
|
65d6ac |
return irq_list
|
|
|
65d6ac |
|
|
|
65d6ac |
def pick_op(argument):
|
|
|
65d6ac |
+ if argument == "":
|
|
|
65d6ac |
+ return (None, argument)
|
|
|
65d6ac |
if argument[0] in ('+', '-'):
|
|
|
65d6ac |
return (argument[0], argument[1:])
|
|
|
65d6ac |
return (None, argument)
|
|
|
65d6ac |
@@ -491,7 +493,11 @@ def main():
|
|
|
65d6ac |
list_config()
|
|
|
65d6ac |
elif o in ("-c", "--cpus"):
|
|
|
65d6ac |
(op, a) = pick_op(a)
|
|
|
65d6ac |
- op_list = tuna.cpustring_to_list(a)
|
|
|
65d6ac |
+ try:
|
|
|
65d6ac |
+ op_list = tuna.cpustring_to_list(a)
|
|
|
65d6ac |
+ except ValueError:
|
|
|
65d6ac |
+ usage()
|
|
|
65d6ac |
+ return
|
|
|
65d6ac |
cpu_list = do_list_op(op, cpu_list, op_list)
|
|
|
65d6ac |
elif o in ("-N", "--nohz_full"):
|
|
|
65d6ac |
try:
|
|
|
65d6ac |
--
|
|
|
65d6ac |
2.4.11
|
|
|
65d6ac |
|