diff options
Diffstat (limited to 'gnuradio-runtime/python/gnuradio')
-rw-r--r-- | gnuradio-runtime/python/gnuradio/ctrlport/monitor.py | 17 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/eng_arg.py | 4 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/eng_notation.py | 9 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/eng_option.py | 4 |
4 files changed, 18 insertions, 16 deletions
diff --git a/gnuradio-runtime/python/gnuradio/ctrlport/monitor.py b/gnuradio-runtime/python/gnuradio/ctrlport/monitor.py index 87d6cb9e7f..0cc05be63e 100644 --- a/gnuradio-runtime/python/gnuradio/ctrlport/monitor.py +++ b/gnuradio-runtime/python/gnuradio/ctrlport/monitor.py @@ -33,15 +33,12 @@ class monitor(object): self.tool = tool atexit.register(self.shutdown) - try: - # setup export prefs - gr.prefs().singleton().set_bool("ControlPort","on",True); - if(tool == "gr-perf-monitorx"): - gr.prefs().singleton().set_bool("ControlPort","edges_list",True); - gr.prefs().singleton().set_bool("PerfCounters","on",True); - gr.prefs().singleton().set_bool("PerfCounters","export",True); - except: - print("no support for gr.prefs setting") + # setup export prefs + gr.prefs().singleton().set_bool("ControlPort","on",True); + if(tool == "gr-perf-monitorx"): + gr.prefs().singleton().set_bool("ControlPort","edges_list",True); + gr.prefs().singleton().set_bool("PerfCounters","on",True); + gr.prefs().singleton().set_bool("PerfCounters","export",True); def __del__(self): if(self.started): @@ -57,7 +54,7 @@ class monitor(object): print("running: %s"%(str(cmd))) self.proc = subprocess.Popen(cmd); self.started = True - except: + except (ValueError, OSError): self.proc = None print("failed to to start ControlPort Monitor on specified port") diff --git a/gnuradio-runtime/python/gnuradio/eng_arg.py b/gnuradio-runtime/python/gnuradio/eng_arg.py index 5983352443..f620e34b1f 100644 --- a/gnuradio-runtime/python/gnuradio/eng_arg.py +++ b/gnuradio-runtime/python/gnuradio/eng_arg.py @@ -34,7 +34,7 @@ def intx(string): """ try: return int(string, 0) - except: + except (ValueError, TypeError): raise argparse.ArgumentTypeError( "Invalid integer value: {}".format(string) ) @@ -47,7 +47,7 @@ def eng_float(string): """ try: return eng_notation.str_to_num(string) - except: + except (TypeError, ValueError): raise argparse.ArgumentTypeError( "Invalid engineering notation value: {}".format(string) ) diff --git a/gnuradio-runtime/python/gnuradio/eng_notation.py b/gnuradio-runtime/python/gnuradio/eng_notation.py index 391dc5838f..ec35b0db5b 100644 --- a/gnuradio-runtime/python/gnuradio/eng_notation.py +++ b/gnuradio-runtime/python/gnuradio/eng_notation.py @@ -23,6 +23,9 @@ Display numbers as strings using engineering notation. """ from __future__ import unicode_literals +import six + + scale_factor = {} scale_factor['E'] = 1e18 scale_factor['P'] = 1e15 @@ -66,11 +69,13 @@ def num_to_str (n, precision=6): def str_to_num (value): '''Convert a string in engineering notation to a number. E.g., '15m' -> 15e-3''' try: + if not isinstance(value, six.string_types): + raise TypeError("Value must be a string") scale = 1.0 suffix = value[-1] if suffix in scale_factor: return float (value[0:-1]) * scale_factor[suffix] return float (value) - except: - raise RuntimeError ( + except (TypeError, KeyError, ValueError): + raise ValueError ( "Invalid engineering notation value: %r" % (value,)) diff --git a/gnuradio-runtime/python/gnuradio/eng_option.py b/gnuradio-runtime/python/gnuradio/eng_option.py index 565780be28..51add1499e 100644 --- a/gnuradio-runtime/python/gnuradio/eng_option.py +++ b/gnuradio-runtime/python/gnuradio/eng_option.py @@ -30,14 +30,14 @@ from . import eng_notation def check_eng_float (option, opt, value): try: return eng_notation.str_to_num(value) - except: + except (ValueError, TypeError): raise OptionValueError ( "option %s: invalid engineering notation value: %r" % (opt, value)) def check_intx (option, opt, value): try: return int (value, 0) - except: + except (ValueError, TypeError): raise OptionValueError ( "option %s: invalid integer value: %r" % (opt, value)) |