From 9e625c4821f4c63421b3d3747c0c4f358fef6c5f Mon Sep 17 00:00:00 2001
From: Douglas Anderson <danderson@ntia.doc.gov>
Date: Sun, 12 Feb 2017 15:52:19 -0800
Subject: python3: update non-GRC components to use python2 or python3

---
 gr-utils/python/modtool/modtool_rename.py | 42 +++++++++++++++++--------------
 1 file changed, 23 insertions(+), 19 deletions(-)

(limited to 'gr-utils/python/modtool/modtool_rename.py')

diff --git a/gr-utils/python/modtool/modtool_rename.py b/gr-utils/python/modtool/modtool_rename.py
index f0ff412a89..4973aa9e78 100644
--- a/gr-utils/python/modtool/modtool_rename.py
+++ b/gr-utils/python/modtool/modtool_rename.py
@@ -20,13 +20,17 @@
 #
 """ Module to rename blocks """
 
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import unicode_literals
+
 import os
 import re
 
-from util_functions import append_re_line_sequence, ask_yes_no
-from cmakefile_editor import CMakeFileEditor
-from modtool_base import ModTool, ModToolException
-from templates import Templates
+from .util_functions import append_re_line_sequence, ask_yes_no
+from .cmakefile_editor import CMakeFileEditor
+from .modtool_base import ModTool, ModToolException
+from .templates import Templates
 
 class ModToolRename(ModTool):
     """ Rename a block in the out-of-tree module. """
@@ -58,20 +62,20 @@ class ModToolRename(ModTool):
         # first make sure the old block name is provided
         self._info['oldname'] = options.blockname
         if self._info['oldname'] is None:
-            self._info['oldname'] = raw_input("Enter name of block/code to rename (without module name prefix): ")
+            self._info['oldname'] = eval(input("Enter name of block/code to rename (without module name prefix): "))
         if not re.match('[a-zA-Z0-9_]+', self._info['oldname']):
             raise ModToolException('Invalid block name.')
-        print "Block/code to rename identifier: " + self._info['oldname']
+        print("Block/code to rename identifier: " + self._info['oldname'])
         self._info['fulloldname'] = self._info['modname'] + '_' + self._info['oldname']
 
         # now get the new block name
         if options.new_name is None:
-            self._info['newname'] = raw_input("Enter name of block/code (without module name prefix): ")
+            self._info['newname'] = eval(input("Enter name of block/code (without module name prefix): "))
         else:
             self._info['newname'] = options.new_name[0]
         if not re.match('[a-zA-Z0-9_]+', self._info['newname']):
             raise ModToolException('Invalid block name.')
-        print "Block/code identifier: " + self._info['newname']
+        print("Block/code identifier: " + self._info['newname'])
         self._info['fullnewname'] = self._info['modname'] + '_' + self._info['newname']
 
     def run(self, options):
@@ -80,7 +84,7 @@ class ModToolRename(ModTool):
         module = self._info['modname']
         oldname = self._info['oldname']
         newname = self._info['newname']
-        print "In module '%s' rename block '%s' to '%s'" % (module, oldname, newname)
+        print("In module '%s' rename block '%s' to '%s'" % (module, oldname, newname))
         self._run_swig_rename(self._file['swig'], oldname, newname)
         self._run_grc_rename(self._info['modname'], oldname, newname)
         self._run_python_qa(self._info['modname'], oldname, newname)
@@ -93,11 +97,11 @@ class ModToolRename(ModTool):
         """ Rename SWIG includes and block_magic """
         nsubs = self._run_file_replace(swigfilename, old, new)
         if nsubs < 1:
-            print "Couldn't find '%s' in file '%s'." % (old, swigfilename)
+            print("Couldn't find '%s' in file '%s'." % (old, swigfilename))
         if nsubs == 2:
-            print "Changing 'noblock' type file"
+            print("Changing 'noblock' type file")
         if nsubs > 3:
-            print "Hm, changed more then expected while editing %s." % swigfilename
+            print("Hm, changed more then expected while editing %s." % swigfilename)
         return False
 
     def _run_lib(self, module, old, new):
@@ -117,7 +121,7 @@ class ModToolRename(ModTool):
         filename = 'qa_' + module + '.cc'
         nsubs = self._run_file_replace(path + filename, old, new)
         if nsubs > 0:
-            print "C++ QA code detected, renaming..."
+            print("C++ QA code detected, renaming...")
             filename = 'qa_' + old + '.cc'
             self._run_file_replace(path + filename, old, new)
             filename = 'qa_' + old + '.h'
@@ -125,7 +129,7 @@ class ModToolRename(ModTool):
             self._run_file_replace(path + filename, old.upper(), new.upper())
             self._run_file_rename(path, 'qa_' + old, 'qa_' + new)
         else:
-            print "No C++ QA code detected, skipping..."
+            print("No C++ QA code detected, skipping...")
 
     def _run_include(self, module, old, new):
         path = './include/' + module + '/'
@@ -140,13 +144,13 @@ class ModToolRename(ModTool):
         filename = '__init__.py'
         nsubs = self._run_file_replace(path + filename, old, new)
         if nsubs > 0:
-            print "Python block detected, renaming..."
+            print("Python block detected, renaming...")
             filename = old + '.py'
             self._run_file_replace(path + filename, old, new)
             self._run_cmakelists(path, old, new)
             self._run_file_rename(path, old, new)
         else:
-            print "Not a Python block, nothing to do here..."
+            print("Not a Python block, nothing to do here...")
 
     def _run_python_qa(self, module, old, new):
         new = 'qa_' + new
@@ -166,7 +170,7 @@ class ModToolRename(ModTool):
         filename = path + 'CMakeLists.txt'
         nsubs = self._run_file_replace(filename, first, second)
         if nsubs < 1:
-            print "'%s' wasn't in '%s'." % (first, filename)
+            print("'%s' wasn't in '%s'." % (first, filename))
 
     def _run_file_rename(self, path, old, new):
         files = os.listdir(path)
@@ -175,14 +179,14 @@ class ModToolRename(ModTool):
                 nl = file.replace(old, new)
                 src = path + file
                 dst = path + nl
-                print "Renaming file '%s' to '%s'." % (src, dst)
+                print("Renaming file '%s' to '%s'." % (src, dst))
                 os.rename(src, dst)
 
     def _run_file_replace(self, filename, old, new):
         if not os.path.isfile(filename):
             return False
         else:
-            print "In '%s' renaming occurences of '%s' to '%s'" % (filename, old, new)
+            print("In '%s' renaming occurences of '%s' to '%s'" % (filename, old, new))
 
         cfile = open(filename).read()
         (cfile, nsubs) = re.subn(old, new, cfile)
-- 
cgit v1.2.3


From 5ee319cb49a5a344521f33b123b4ad0d0927163a Mon Sep 17 00:00:00 2001
From: Håkon Vågsether <haakonsv@gmail.com>
Date: Mon, 21 Aug 2017 11:35:08 +0200
Subject: Fix typos from switch to Python 3

---
 docs/exploring-gnuradio/dial_tone.py                  | 2 +-
 docs/exploring-gnuradio/fm_demod.py                   | 2 +-
 gnuradio-runtime/examples/mp-sched/affinity_set.py    | 2 +-
 gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py | 2 +-
 gr-uhd/apps/uhd_siggen_base.py                        | 2 +-
 gr-utils/python/modtool/modtool_add.py                | 8 ++++----
 gr-utils/python/modtool/modtool_disable.py            | 2 +-
 gr-utils/python/modtool/modtool_makexml.py            | 2 +-
 gr-utils/python/modtool/modtool_newmod.py             | 2 +-
 gr-utils/python/modtool/modtool_rename.py             | 4 ++--
 gr-utils/python/modtool/modtool_rm.py                 | 2 +-
 gr-vocoder/examples/alaw_audio_loopback.py            | 2 +-
 gr-vocoder/examples/codec2_audio_loopback.py          | 2 +-
 gr-vocoder/examples/cvsd_audio_loopback.py            | 2 +-
 gr-vocoder/examples/g721_audio_loopback.py            | 2 +-
 gr-vocoder/examples/g723_24_audio_loopback.py         | 2 +-
 gr-vocoder/examples/g723_40_audio_loopback.py         | 2 +-
 gr-vocoder/examples/gsm_audio_loopback.py             | 2 +-
 gr-vocoder/examples/ulaw_audio_loopback.py            | 2 +-
 19 files changed, 23 insertions(+), 23 deletions(-)

(limited to 'gr-utils/python/modtool/modtool_rename.py')

diff --git a/docs/exploring-gnuradio/dial_tone.py b/docs/exploring-gnuradio/dial_tone.py
index 42cbf3c9d0..08498a84e0 100644
--- a/docs/exploring-gnuradio/dial_tone.py
+++ b/docs/exploring-gnuradio/dial_tone.py
@@ -41,5 +41,5 @@ def build_graph():
 if __name__ == '__main__':
     tb = build_graph()
     tb.start()
-    eval(input('Press Enter to quit: '))
+    input('Press Enter to quit: ')
     tb.stop()
diff --git a/docs/exploring-gnuradio/fm_demod.py b/docs/exploring-gnuradio/fm_demod.py
index 71d7f64c82..a297e78a76 100644
--- a/docs/exploring-gnuradio/fm_demod.py
+++ b/docs/exploring-gnuradio/fm_demod.py
@@ -82,7 +82,7 @@ class build_graph(gr.top_block):
 def main(args):
     tb = build_graph()
     tb.start()        # fork thread and return
-    eval(input('Press Enter to quit: '))
+    input('Press Enter to quit: ')
     tb.stop()
 
 if __name__ == '__main__':
diff --git a/gnuradio-runtime/examples/mp-sched/affinity_set.py b/gnuradio-runtime/examples/mp-sched/affinity_set.py
index b717e1e506..a253c8081c 100644
--- a/gnuradio-runtime/examples/mp-sched/affinity_set.py
+++ b/gnuradio-runtime/examples/mp-sched/affinity_set.py
@@ -59,7 +59,7 @@ if __name__ == '__main__':
     tb.start()
 
     while(1):
-        ret = eval(input('Enter a new Core # or Press Enter to quit: '))
+        ret = input('Enter a new Core # or Press Enter to quit: ')
 	if(len(ret) == 0):
             tb.stop()
 	    sys.exit(0)
diff --git a/gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py b/gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py
index 5a1ea91cad..71aee11f0b 100644
--- a/gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py
+++ b/gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py
@@ -101,4 +101,4 @@ def test_plot ():
 
 if __name__ == '__main__':
     handle = test_plot ()
-    eval(input ('Press Enter to continue: '))
+    input ('Press Enter to continue: ')
diff --git a/gr-uhd/apps/uhd_siggen_base.py b/gr-uhd/apps/uhd_siggen_base.py
index 98dda1084b..9714810cdd 100644
--- a/gr-uhd/apps/uhd_siggen_base.py
+++ b/gr-uhd/apps/uhd_siggen_base.py
@@ -295,7 +295,7 @@ def main():
         print(ex)
         exit(1)
     tb.start()
-    eval(input('[UHD-SIGGEN] Press Enter to quit:\n'))
+    input('[UHD-SIGGEN] Press Enter to quit:\n')
     tb.stop()
     tb.wait()
 
diff --git a/gr-utils/python/modtool/modtool_add.py b/gr-utils/python/modtool/modtool_add.py
index 74f11318d0..8c5eed29ec 100644
--- a/gr-utils/python/modtool/modtool_add.py
+++ b/gr-utils/python/modtool/modtool_add.py
@@ -76,14 +76,14 @@ class ModToolAdd(ModTool):
             # Print(list out of blocktypes to user for reference)
             print(str(self._block_types))
             while self._info['blocktype'] not in self._block_types:
-                self._info['blocktype'] = eval(input("Enter block type: "))
+                self._info['blocktype'] = input("Enter block type: ")
                 if self._info['blocktype'] not in self._block_types:
                     print('Must be one of ' + str(self._block_types))
         # Allow user to specify language interactively if not set
         self._info['lang'] = options.lang
         if self._info['lang'] is None:
             while self._info['lang'] not in ['c++', 'cpp', 'python']:
-                self._info['lang'] = eval(input("Language (python/cpp): "))
+                self._info['lang'] = input("Language (python/cpp): ")
         if self._info['lang'] == 'c++':
             self._info['lang'] = 'cpp'
 
@@ -94,7 +94,7 @@ class ModToolAdd(ModTool):
             raise ModToolException('Missing or skipping relevant subdir.')
 
         if self._info['blockname'] is None:
-            self._info['blockname'] = eval(input("Enter name of block/code (without module name prefix): "))
+            self._info['blockname'] = input("Enter name of block/code (without module name prefix): ")
         if not re.match('[a-zA-Z0-9_]+', self._info['blockname']):
             raise ModToolException('Invalid block name.')
         print("Block/code identifier: " + self._info['blockname'])
@@ -110,7 +110,7 @@ class ModToolAdd(ModTool):
         if options.argument_list is not None:
             self._info['arglist'] = options.argument_list
         else:
-            self._info['arglist'] = eval(input('Enter valid argument list, including default arguments: '))
+            self._info['arglist'] = input('Enter valid argument list, including default arguments: ')
 
         if not (self._info['blocktype'] in ('noblock') or self._skip_subdirs['python']):
             self._add_py_qa = options.add_python_qa
diff --git a/gr-utils/python/modtool/modtool_disable.py b/gr-utils/python/modtool/modtool_disable.py
index 629a810cb0..619858978d 100644
--- a/gr-utils/python/modtool/modtool_disable.py
+++ b/gr-utils/python/modtool/modtool_disable.py
@@ -50,7 +50,7 @@ class ModToolDisable(ModTool):
         if options.blockname is not None:
             self._info['pattern'] = options.blockname
         else:
-            self._info['pattern'] = eval(input('Which blocks do you want to disable? (Regex): '))
+            self._info['pattern'] = input('Which blocks do you want to disable? (Regex): ')
         if len(self._info['pattern']) == 0:
             self._info['pattern'] = '.'
 
diff --git a/gr-utils/python/modtool/modtool_makexml.py b/gr-utils/python/modtool/modtool_makexml.py
index dffd403a37..74fed4b7a1 100644
--- a/gr-utils/python/modtool/modtool_makexml.py
+++ b/gr-utils/python/modtool/modtool_makexml.py
@@ -58,7 +58,7 @@ class ModToolMakeXML(ModTool):
         if options.blockname is not None:
             self._info['pattern'] = options.blockname
         else:
-            self._info['pattern'] = eval(input('Which blocks do you want to parse? (Regex): '))
+            self._info['pattern'] = input('Which blocks do you want to parse? (Regex): ')
         if len(self._info['pattern']) == 0:
             self._info['pattern'] = '.'
 
diff --git a/gr-utils/python/modtool/modtool_newmod.py b/gr-utils/python/modtool/modtool_newmod.py
index b3e384d122..c283204ee2 100644
--- a/gr-utils/python/modtool/modtool_newmod.py
+++ b/gr-utils/python/modtool/modtool_newmod.py
@@ -53,7 +53,7 @@ class ModToolNewModule(ModTool):
             if options.module_name:
                 self._info['modname'] = options.module_name
             else:
-                self._info['modname'] = eval(input('Name of the new module: '))
+                self._info['modname'] = input('Name of the new module: ')
         if not re.match('[a-zA-Z0-9_]+$', self._info['modname']):
             raise ModToolException('Invalid module name.')
         self._dir = options.directory
diff --git a/gr-utils/python/modtool/modtool_rename.py b/gr-utils/python/modtool/modtool_rename.py
index 4973aa9e78..c2229f28fb 100644
--- a/gr-utils/python/modtool/modtool_rename.py
+++ b/gr-utils/python/modtool/modtool_rename.py
@@ -62,7 +62,7 @@ class ModToolRename(ModTool):
         # first make sure the old block name is provided
         self._info['oldname'] = options.blockname
         if self._info['oldname'] is None:
-            self._info['oldname'] = eval(input("Enter name of block/code to rename (without module name prefix): "))
+            self._info['oldname'] = input("Enter name of block/code to rename (without module name prefix): ")
         if not re.match('[a-zA-Z0-9_]+', self._info['oldname']):
             raise ModToolException('Invalid block name.')
         print("Block/code to rename identifier: " + self._info['oldname'])
@@ -70,7 +70,7 @@ class ModToolRename(ModTool):
 
         # now get the new block name
         if options.new_name is None:
-            self._info['newname'] = eval(input("Enter name of block/code (without module name prefix): "))
+            self._info['newname'] = input("Enter name of block/code (without module name prefix): ")
         else:
             self._info['newname'] = options.new_name[0]
         if not re.match('[a-zA-Z0-9_]+', self._info['newname']):
diff --git a/gr-utils/python/modtool/modtool_rm.py b/gr-utils/python/modtool/modtool_rm.py
index 248d1b7ca8..dffd5c2e45 100644
--- a/gr-utils/python/modtool/modtool_rm.py
+++ b/gr-utils/python/modtool/modtool_rm.py
@@ -52,7 +52,7 @@ class ModToolRemove(ModTool):
         if options.blockname is not None:
             self._info['pattern'] = options.blockname
         else:
-            self._info['pattern'] = eval(input('Which blocks do you want to delete? (Regex): '))
+            self._info['pattern'] = input('Which blocks do you want to delete? (Regex): ')
         if len(self._info['pattern']) == 0:
             self._info['pattern'] = '.'
 
diff --git a/gr-vocoder/examples/alaw_audio_loopback.py b/gr-vocoder/examples/alaw_audio_loopback.py
index 6f43322470..7dbcbb209c 100644
--- a/gr-vocoder/examples/alaw_audio_loopback.py
+++ b/gr-vocoder/examples/alaw_audio_loopback.py
@@ -43,6 +43,6 @@ def build_graph():
 if __name__ == '__main__':
     tb = build_graph()
     tb.start()
-    eval(input ('Press Enter to exit: '))
+    input ('Press Enter to exit: ')
     tb.stop()
     tb.wait()
diff --git a/gr-vocoder/examples/codec2_audio_loopback.py b/gr-vocoder/examples/codec2_audio_loopback.py
index 9c51d2f49c..ea690861aa 100644
--- a/gr-vocoder/examples/codec2_audio_loopback.py
+++ b/gr-vocoder/examples/codec2_audio_loopback.py
@@ -44,6 +44,6 @@ def build_graph():
 if __name__ == '__main__':
     tb = build_graph()
     tb.start()
-    eval(input ('Press Enter to exit: '))
+    input ('Press Enter to exit: ')
     tb.stop()
     tb.wait()
diff --git a/gr-vocoder/examples/cvsd_audio_loopback.py b/gr-vocoder/examples/cvsd_audio_loopback.py
index 603a7194a4..15074d62cd 100644
--- a/gr-vocoder/examples/cvsd_audio_loopback.py
+++ b/gr-vocoder/examples/cvsd_audio_loopback.py
@@ -67,6 +67,6 @@ def build_graph():
 if __name__ == '__main__':
     tb = build_graph()
     tb.start()
-    eval(input ('Press Enter to exit: '))
+    input ('Press Enter to exit: ')
     tb.stop()
     tb.wait()
diff --git a/gr-vocoder/examples/g721_audio_loopback.py b/gr-vocoder/examples/g721_audio_loopback.py
index 790cbfcb48..afe9b04b91 100644
--- a/gr-vocoder/examples/g721_audio_loopback.py
+++ b/gr-vocoder/examples/g721_audio_loopback.py
@@ -43,6 +43,6 @@ def build_graph():
 if __name__ == '__main__':
     tb = build_graph()
     tb.start()
-    eval(input ('Press Enter to exit: '))
+    input ('Press Enter to exit: ')
     tb.stop()
     tb.wait()
diff --git a/gr-vocoder/examples/g723_24_audio_loopback.py b/gr-vocoder/examples/g723_24_audio_loopback.py
index 7390aa0151..62e58c1412 100644
--- a/gr-vocoder/examples/g723_24_audio_loopback.py
+++ b/gr-vocoder/examples/g723_24_audio_loopback.py
@@ -43,6 +43,6 @@ def build_graph():
 if __name__ == '__main__':
     tb = build_graph()
     tb.start()
-    eval(input ('Press Enter to exit: '))
+    input ('Press Enter to exit: ')
     tb.stop()
     tb.wait()
diff --git a/gr-vocoder/examples/g723_40_audio_loopback.py b/gr-vocoder/examples/g723_40_audio_loopback.py
index c016193382..edc8f5716e 100644
--- a/gr-vocoder/examples/g723_40_audio_loopback.py
+++ b/gr-vocoder/examples/g723_40_audio_loopback.py
@@ -43,6 +43,6 @@ def build_graph():
 if __name__ == '__main__':
     tb = build_graph()
     tb.start()
-    eval(input ('Press Enter to exit: '))
+    input ('Press Enter to exit: ')
     tb.stop()
     tb.wait()
diff --git a/gr-vocoder/examples/gsm_audio_loopback.py b/gr-vocoder/examples/gsm_audio_loopback.py
index b21b9da410..c71e6fd384 100644
--- a/gr-vocoder/examples/gsm_audio_loopback.py
+++ b/gr-vocoder/examples/gsm_audio_loopback.py
@@ -43,6 +43,6 @@ def build_graph():
 if __name__ == '__main__':
     tb = build_graph()
     tb.start()
-    eval(input ('Press Enter to exit: '))
+    input ('Press Enter to exit: ')
     tb.stop()
     tb.wait()
diff --git a/gr-vocoder/examples/ulaw_audio_loopback.py b/gr-vocoder/examples/ulaw_audio_loopback.py
index aeb7411e0b..6a8a493f30 100644
--- a/gr-vocoder/examples/ulaw_audio_loopback.py
+++ b/gr-vocoder/examples/ulaw_audio_loopback.py
@@ -43,6 +43,6 @@ def build_graph():
 if __name__ == '__main__':
     tb = build_graph()
     tb.start()
-    eval(input ('Press Enter to exit: '))
+    input ('Press Enter to exit: ')
     tb.stop()
     tb.wait()
-- 
cgit v1.2.3