diff options
Diffstat (limited to 'gnuradio-runtime/python/gnuradio/gru')
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/__init__.py | 22 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/daemon.py | 46 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/freqz.py | 32 | ||||
-rw-r--r--[-rwxr-xr-x] | gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py | 8 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/hexint.py | 1 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/listmisc.py | 1 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/mathmisc.py | 4 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/msgq_runner.py | 3 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/os_read_exactly.py | 1 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/seq_with_cursor.py | 13 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/socket_stuff.py | 5 |
12 files changed, 78 insertions, 59 deletions
diff --git a/gnuradio-runtime/python/gnuradio/gru/CMakeLists.txt b/gnuradio-runtime/python/gnuradio/gru/CMakeLists.txt index f0276a8d53..c1d7b701a9 100644 --- a/gnuradio-runtime/python/gnuradio/gru/CMakeLists.txt +++ b/gnuradio-runtime/python/gnuradio/gru/CMakeLists.txt @@ -32,5 +32,4 @@ GR_PYTHON_INSTALL(FILES socket_stuff.py daemon.py DESTINATION ${GR_PYTHON_DIR}/gnuradio/gru - COMPONENT "runtime_python" ) diff --git a/gnuradio-runtime/python/gnuradio/gru/__init__.py b/gnuradio-runtime/python/gnuradio/gru/__init__.py index 4e41d03a74..0948edb17f 100644 --- a/gnuradio-runtime/python/gnuradio/gru/__init__.py +++ b/gnuradio-runtime/python/gnuradio/gru/__init__.py @@ -1,13 +1,15 @@ +from __future__ import absolute_import +from __future__ import unicode_literals # make this a package # Import gru stuff -from daemon import * -from freqz import * -from gnuplot_freqz import * -from hexint import * -from listmisc import * -from mathmisc import * -from msgq_runner import * -from os_read_exactly import * -from seq_with_cursor import * -from socket_stuff import * +from .daemon import * +from .freqz import * +from .gnuplot_freqz import * +from .hexint import * +from .listmisc import * +from .mathmisc import * +from .msgq_runner import * +from .os_read_exactly import * +from .seq_with_cursor import * +from .socket_stuff import * diff --git a/gnuradio-runtime/python/gnuradio/gru/daemon.py b/gnuradio-runtime/python/gnuradio/gru/daemon.py index e04702152d..14138f9730 100644 --- a/gnuradio-runtime/python/gnuradio/gru/daemon.py +++ b/gnuradio-runtime/python/gnuradio/gru/daemon.py @@ -18,6 +18,10 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. # + +from __future__ import print_function +from __future__ import unicode_literals + import os, sys, signal # Turn application into a background daemon process. @@ -55,38 +59,38 @@ import os, sys, signal def daemonize(pidfile=None, logfile=None): # fork() into background try: - pid = os.fork() - except OSError, e: - raise Exception, "%s [%d]" % (e.strerror, e.errno) + pid = os.fork() + except OSError as e: + raise Exception("%s [%d]" % (e.strerror, e.errno)) if pid == 0: # First child of first fork() - # Become session leader of new session - os.setsid() + # Become session leader of new session + os.setsid() - # fork() into background again - try: - pid = os.fork() - except OSError, e: - raise Exception, "%s [%d]" % (e.strerror, e.errno) + # fork() into background again + try: + pid = os.fork() + except OSError as e: + raise Exception("%s [%d]" % (e.strerror, e.errno)) - if pid != 0: - os._exit(0) # Second child of second fork() + if pid != 0: + os._exit(0) # Second child of second fork() - else: # Second child of first fork() - os._exit(0) + else: # Second child of first fork() + os._exit(0) - os.umask(0111) + os.umask(0o111) # Write pid pid = os.getpid() if pidfile is not None: - open(pidfile, 'w').write('%d\n'%pid) + open(pidfile, 'w').write('%d\n'%pid) # Redirect streams if logfile is not None: - lf = open(logfile, 'a+') - sys.stdout = lf - sys.stderr = lf + lf = open(logfile, 'a+') + sys.stdout = lf + sys.stderr = lf # Prevent pinning any filesystem mounts os.chdir('/') @@ -97,6 +101,6 @@ def daemonize(pidfile=None, logfile=None): if __name__ == "__main__": import time daemonize() - print "Hello, world, from daemon process." + print("Hello, world, from daemon process.") time.sleep(20) - print "Goodbye, world, from daemon process." + print("Goodbye, world, from daemon process.") diff --git a/gnuradio-runtime/python/gnuradio/gru/freqz.py b/gnuradio-runtime/python/gnuradio/gru/freqz.py index a24d13ddee..edea6113b6 100644 --- a/gnuradio-runtime/python/gnuradio/gru/freqz.py +++ b/gnuradio-runtime/python/gnuradio/gru/freqz.py @@ -52,6 +52,8 @@ # DAMAGE. # +from __future__ import division +from __future__ import unicode_literals __all__ = ['freqz'] import numpy @@ -106,7 +108,7 @@ def polyval(p,x): y = x * y + p[i] return y -class poly1d: +class poly1d(object): """A one-dimensional polynomial class. p = poly1d([1,2,3]) constructs the polynomial x**2 + 2 x + 3 @@ -125,14 +127,14 @@ class poly1d: """ def __init__(self, c_or_r, r=0): if isinstance(c_or_r,poly1d): - for key in c_or_r.__dict__.keys(): + for key in list(c_or_r.__dict__.keys()): self.__dict__[key] = c_or_r.__dict__[key] return if r: c_or_r = poly(c_or_r) c_or_r = atleast_1d(c_or_r) if len(c_or_r.shape) > 1: - raise ValueError, "Polynomial must be 1d only." + raise ValueError("Polynomial must be 1d only.") c_or_r = trim_zeros(c_or_r, trim='f') if len(c_or_r) == 0: c_or_r = numpy.array([0]) @@ -227,7 +229,7 @@ class poly1d: def __pow__(self, val): if not isscalar(val) or int(val) != val or val < 0: - raise ValueError, "Power to non-negative integers only." + raise ValueError("Power to non-negative integers only.") res = [1] for k in range(val): res = polymul(self.coeffs, res) @@ -243,20 +245,20 @@ class poly1d: def __div__(self, other): if isscalar(other): - return poly1d(self.coeffs/other) + return poly1d(self.coeffs / other) else: other = poly1d(other) - return map(poly1d,polydiv(self.coeffs, other.coeffs)) + return list(map(poly1d,polydiv(self.coeffs, other.coeffs))) def __rdiv__(self, other): if isscalar(other): - return poly1d(other/self.coeffs) + return poly1d(other / self.coeffs) else: other = poly1d(other) - return map(poly1d,polydiv(other.coeffs, self.coeffs)) + return list(map(poly1d,polydiv(other.coeffs, self.coeffs))) def __setattr__(self, key, val): - raise ValueError, "Attributes cannot be changed this way." + raise ValueError("Attributes cannot be changed this way.") def __getattr__(self, key): if key in ['r','roots']: @@ -279,7 +281,7 @@ class poly1d: def __setitem__(self, key, val): ind = self.order - key if key < 0: - raise ValueError, "Does not support negative powers." + raise ValueError("Does not support negative powers.") if key > self.order: zr = numpy.zeros(key-self.order,self.coeffs.typecode()) self.__dict__['coeffs'] = numpy.concatenate((zr,self.coeffs)) @@ -323,22 +325,22 @@ def freqz(b, a, worN=None, whole=0, plot=None): h -- The frequency response. w -- The frequencies at which h was computed. """ - b, a = map(atleast_1d, (b,a)) + b, a = list(map(atleast_1d, (b,a))) if whole: lastpoint = 2*pi else: lastpoint = pi if worN is None: N = 512 - w = Num.arange(0,lastpoint,lastpoint/N) - elif isinstance(worN, types.IntType): + w = Num.arange(0,lastpoint,lastpoint / N) + elif isinstance(worN, int): N = worN - w = Num.arange(0,lastpoint,lastpoint/N) + w = Num.arange(0,lastpoint,lastpoint / N) else: w = worN w = atleast_1d(w) zm1 = exp(-1j*w) - h = polyval(b[::-1], zm1) / polyval(a[::-1], zm1) + h = polyval(b[::-1] / zm1, polyval(a[::-1], zm1)) # if not plot is None: # plot(w, h) return h, w diff --git a/gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py b/gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py index dd483e4277..71aee11f0b 100755..100644 --- a/gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py +++ b/gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py @@ -20,6 +20,8 @@ # Boston, MA 02110-1301, USA. # +from __future__ import division +from __future__ import unicode_literals __all__ = ['gnuplot_freqz'] import tempfile @@ -46,10 +48,10 @@ def gnuplot_freqz (hw, Fs=None, logfreq=False): h, w = hw ampl = 20 * numpy.log10 (numpy.absolute (h) + 1e-9) - phase = map (lambda x: math.atan2 (x.imag, x.real), h) + phase = [math.atan2 (x.imag, x.real) for x in h] if Fs: - w *= (Fs/(2*math.pi)) + w *= (Fs / (2*math.pi)) for freq, a, ph in zip (w, ampl, phase): data_file.write ("%g\t%g\t%g\n" % (freq, a, ph)) @@ -99,4 +101,4 @@ def test_plot (): if __name__ == '__main__': handle = test_plot () - raw_input ('Press Enter to continue: ') + input ('Press Enter to continue: ') diff --git a/gnuradio-runtime/python/gnuradio/gru/hexint.py b/gnuradio-runtime/python/gnuradio/gru/hexint.py index 0fb5ecde04..096b876701 100644 --- a/gnuradio-runtime/python/gnuradio/gru/hexint.py +++ b/gnuradio-runtime/python/gnuradio/gru/hexint.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals # # Copyright 2005 Free Software Foundation, Inc. # diff --git a/gnuradio-runtime/python/gnuradio/gru/listmisc.py b/gnuradio-runtime/python/gnuradio/gru/listmisc.py index 9e70eb863c..a981147337 100644 --- a/gnuradio-runtime/python/gnuradio/gru/listmisc.py +++ b/gnuradio-runtime/python/gnuradio/gru/listmisc.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals # # Copyright 2005 Free Software Foundation, Inc. # diff --git a/gnuradio-runtime/python/gnuradio/gru/mathmisc.py b/gnuradio-runtime/python/gnuradio/gru/mathmisc.py index 7e6f23a346..790d7c993c 100644 --- a/gnuradio-runtime/python/gnuradio/gru/mathmisc.py +++ b/gnuradio-runtime/python/gnuradio/gru/mathmisc.py @@ -1,3 +1,5 @@ +from __future__ import division +from __future__ import unicode_literals # # Copyright 2005 Free Software Foundation, Inc. # @@ -30,4 +32,4 @@ def lcm(a,b): return a * b / gcd(a, b) def log2(x): - return math.log(x)/math.log(2) + return math.log(x) / math.log(2) diff --git a/gnuradio-runtime/python/gnuradio/gru/msgq_runner.py b/gnuradio-runtime/python/gnuradio/gru/msgq_runner.py index 767a74a717..2d58480f5f 100644 --- a/gnuradio-runtime/python/gnuradio/gru/msgq_runner.py +++ b/gnuradio-runtime/python/gnuradio/gru/msgq_runner.py @@ -40,6 +40,7 @@ To manually stop the runner, call stop() on the object. To determine if the runner has exited, call exited() on the object. """ +from __future__ import unicode_literals from gnuradio import gr import gnuradio.gr.gr_threading as _threading @@ -66,7 +67,7 @@ class msgq_runner(_threading.Thread): else: try: self._callback(msg) - except Exception, e: + except Exception as e: if self._exit_on_error: self._exit_error = e self.stop() diff --git a/gnuradio-runtime/python/gnuradio/gru/os_read_exactly.py b/gnuradio-runtime/python/gnuradio/gru/os_read_exactly.py index 40b053770e..c079fc4e11 100644 --- a/gnuradio-runtime/python/gnuradio/gru/os_read_exactly.py +++ b/gnuradio-runtime/python/gnuradio/gru/os_read_exactly.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals # # Copyright 2005 Free Software Foundation, Inc. # diff --git a/gnuradio-runtime/python/gnuradio/gru/seq_with_cursor.py b/gnuradio-runtime/python/gnuradio/gru/seq_with_cursor.py index def3299b69..0aefbf83bb 100644 --- a/gnuradio-runtime/python/gnuradio/gru/seq_with_cursor.py +++ b/gnuradio-runtime/python/gnuradio/gru/seq_with_cursor.py @@ -21,8 +21,12 @@ # misc utilities +from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals + import types -import exceptions + class seq_with_cursor (object): __slots__ = [ 'items', 'index' ] @@ -40,7 +44,7 @@ class seq_with_cursor (object): elif initial_index >= 0 and initial_index < len (self.items): self.index = initial_index else: - raise exceptions.ValueError + raise ValueError def set_index_by_value(self, v): """ @@ -51,9 +55,9 @@ class seq_with_cursor (object): cv = self.current() more = True while cv < v and more: - cv, more = self.next() # side effect! + cv, more = next(self) # side effect! - def next (self): + def __next__ (self): new_index = self.index + 1 if new_index < len (self.items): self.index = new_index @@ -74,4 +78,3 @@ class seq_with_cursor (object): def get_seq (self): return self.items[:] # copy of items - diff --git a/gnuradio-runtime/python/gnuradio/gru/socket_stuff.py b/gnuradio-runtime/python/gnuradio/gru/socket_stuff.py index b7c5ac2fe1..ce08ce1e10 100644 --- a/gnuradio-runtime/python/gnuradio/gru/socket_stuff.py +++ b/gnuradio-runtime/python/gnuradio/gru/socket_stuff.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals # # Copyright 2005 Free Software Foundation, Inc. # @@ -37,7 +38,7 @@ def tcp_connect_or_die(sock_addr): s = socket.socket (socket.AF_INET, socket.SOCK_STREAM) try: s.connect(sock_addr) - except socket.error, err: + except socket.error as err: sys.stderr.write('Failed to connect to %s: %s\n' % (sock_addr, os.strerror (err.args[0]),)) sys.exit(1) @@ -55,7 +56,7 @@ def udp_connect_or_die(sock_addr): s = socket.socket (socket.AF_INET, socket.SOCK_DGRAM) try: s.connect(sock_addr) - except socket.error, err: + except socket.error as err: sys.stderr.write('Failed to connect to %s: %s\n' % (sock_addr, os.strerror (err.args[0]),)) sys.exit(1) |