summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Kacur <jkacur@redhat.com>2016-05-30 20:54:13 +0200
committerJiri Kastner <jkastner@redhat.com>2016-05-31 21:36:29 +0200
commita705294be5aa8f4021b4388e86d2ea28f2875fbe (patch)
treebcf49bce5ca82343c67f5a21727bf83f866b8a49
parent8d4b784feda43cbe67b721c425439e973cd58173 (diff)
downloadtuna-a705294be5aa8f4021b4388e86d2ea28f2875fbe.tar.gz
tuna: tuna-cmd: Display usage instead of traceback -c missing args
Display a usage messaage instead of a python traceback when a required argument to the -c or --cpus is missing, or when the argument doesn't make sense. (Such as passing a nonsense string, instead of a comma separated list of numbers) - In function pick_op, handle the unusual but possible case where an empty string is passed as an argument. - Display a usage message upon ValueError when caling cpustring_to_list when processing the -c option This fixes various erroneous or missing input to -c, such as the following ./tuna-cmd.py -c -P Traceback (most recent call last): File "./tuna-cmd.py", line 656, in <module> main() File "./tuna-cmd.py", line 494, in main op_list = tuna.cpustring_to_list(a) File "/home/jkacur/source/tuna/tuna/tuna.py", line 124, in cpustring_to_list ends = [ int(a, 0) for a in field.split("-") ] ValueError: invalid literal for int() with base 0: 'P' ./tuna-cmd.py -c "" -P Traceback (most recent call last): File "./tuna-cmd.py", line 656, in <module> main() File "./tuna-cmd.py", line 493, in main (op, a) = pick_op(a) File "./tuna-cmd.py", line 408, in pick_op if argument[0] in ('+', '-'): IndexError: string index out of range ./tuna-cmd.py -c "nonesense" -P Traceback (most recent call last): File "./tuna-cmd.py", line 656, in <module> main() File "./tuna-cmd.py", line 494, in main op_list = tuna.cpustring_to_list(a) File "/home/jkacur/source/tuna/tuna/tuna.py", line 124, in cpustring_to_list ends = [ int(a, 0) for a in field.split("-") ] ValueError: invalid literal for int() with base 0: 'nonesense' This fixes bugzilla 1268287 Signed-off-by: John Kacur <jkacur@redhat.com> Signed-off-by: Jiri Kastner <jkastner@redhat.com>
-rwxr-xr-xtuna-cmd.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/tuna-cmd.py b/tuna-cmd.py
index ae4f78a..3c9bfaa 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -405,6 +405,8 @@ def irq_mapper(s):
return irq_list
def pick_op(argument):
+ if argument == "":
+ return (None, argument)
if argument[0] in ('+', '-'):
return (argument[0], argument[1:])
return (None, argument)
@@ -491,7 +493,11 @@ def main():
list_config()
elif o in ("-c", "--cpus"):
(op, a) = pick_op(a)
- op_list = tuna.cpustring_to_list(a)
+ try:
+ op_list = tuna.cpustring_to_list(a)
+ except ValueError:
+ usage()
+ return
cpu_list = do_list_op(op, cpu_list, op_list)
elif o in ("-N", "--nohz_full"):
try: