From accdc3ba41614b075921974f42588e4198e3bb93 Mon Sep 17 00:00:00 2001 From: Luigi Tibaldo Date: Thu, 23 Jan 2020 16:42:06 +0100 Subject: [PATCH] modified to work with both Python 2 and 3 --- dev/codegen.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/dev/codegen.py b/dev/codegen.py index c5f8dc9..85538ce 100755 --- a/dev/codegen.py +++ b/dev/codegen.py @@ -20,10 +20,9 @@ # ========================================================================== import os import sys -import glob -import commands import fileinput from datetime import date +from builtins import input import gammalib @@ -47,7 +46,7 @@ def confirm(text): # Confirmation loop waiting = True while waiting: - confirmation = str(raw_input(text+' (y/n): ')) + confirmation = str(input(text+' (y/n): ')) if confirmation == 'q': sys.exit() elif confirmation == 'y': @@ -87,7 +86,7 @@ def response(text, confirm_response=False): # Get response from input waiting = True while waiting: - response = str(raw_input('%s: ' % text)) + response = str(input('%s: ' % text)) if response == 'q': sys.exit() else: @@ -275,13 +274,13 @@ def add_ctool(name, tokens, baseclass): if 'libctools_la_LIBADD' in line.replace(' ', ''): last = line[-2] line = line.replace(line, line+insertline2+last+'\n') - print line, + print(line), # Update Python module for line in fileinput.FileInput('pyext/ctools/tools.i',inplace=1): if '%include "ctbin.i"' in line: print('%%include "%s.i"' % (name)) - print line, + print(line), # Update unit test for line in fileinput.FileInput('test/test_python_ctools.py',inplace=1): @@ -289,25 +288,25 @@ def add_ctool(name, tokens, baseclass): print('import test_%s' % (name)) elif 'test_ctbin.Test()' in line: print(' test_%s.Test(),' % (name)) - print line, + print(line), # Update export of unit test for line in fileinput.FileInput('pyext/Makefile.am',inplace=1): if '$(top_srcdir)/test/test_ctbin.py' in line: print(' $(top_srcdir)/test/test_%s.py \\' % (name)) - print line, + print(line), # Update configure.ac for line in fileinput.FileInput('configure.ac',inplace=1): if 'src/ctbin/Makefile' in line: print(' src/%s/Makefile' % (name)) - print line, + print(line), # Update reference manual index file for line in fileinput.FileInput('doc/source/users/reference_manual/index.rst',inplace=1): if 'ctbin --- Generates counts cube ' in line: print(' %s --- ToDo: Describe what tool is doing <%s>' % (name, name)) - print line, + print(line), # Return return @@ -356,7 +355,7 @@ def add_cscript(name, tokens, baseclass): print(' "%s",' % (name)) elif 'from cscripts.csworkflow import csworkflow' in line: print('from cscripts.%s import %s' % (name, name)) - print line, + print(line), # Update cscripts/Makefile.am file for line in fileinput.FileInput('cscripts/Makefile.am',inplace=1): @@ -368,7 +367,7 @@ def add_cscript(name, tokens, baseclass): print(' %s \\' % (name)) elif '$(top_srcdir)/test/test_csworkflow.py' in line: print(' $(top_srcdir)/test/test_%s.py \\' % (name)) - print line, + print(line), # Update test/test_python_cscripts.py file for line in fileinput.FileInput('test/test_python_cscripts.py',inplace=1): @@ -376,13 +375,13 @@ def add_cscript(name, tokens, baseclass): print('import test_%s' % (name)) elif 'test_csworkflow.Test()' in line: print(' test_%s.Test(),' % (name)) - print line, + print(line), # Update reference manual index file for line in fileinput.FileInput('doc/source/users/reference_manual/index.rst',inplace=1): if 'csbkgmodel --- Generates background model for 3D analysis ' in line: print(' %s --- ToDo: Describe what script is doing <%s>' % (name, name)) - print line, + print(line), # Return return @@ -414,7 +413,7 @@ def ctool_menu(): waiting = True choice = 1 while waiting: - choice = str(raw_input('Enter your choice: ')) + choice = str(input('Enter your choice: ')) if choice == '1' or choice == '2' or choice == '3': waiting = False if choice == '1': @@ -480,7 +479,7 @@ def cscript_menu(): waiting = True choice = 1 while waiting: - choice = str(raw_input('Enter your choice: ')) + choice = str(input('Enter your choice: ')) if choice == '1' or choice == '2' or choice == '3': waiting = False if choice == '1': @@ -535,7 +534,7 @@ def main_menu(): # Wait for the input waiting = True while waiting: - choice = str(raw_input('Enter your choice: ')) + choice = str(input('Enter your choice: ')) if choice == '1' or choice == '2' or choice == 'q': waiting = False -- libgit2 0.21.4