Commit accdc3ba41614b075921974f42588e4198e3bb93
1 parent
ad59645c
modified to work with both Python 2 and 3
Showing
1 changed file
with
16 additions
and
17 deletions
dev/codegen.py
| @@ -20,10 +20,9 @@ | @@ -20,10 +20,9 @@ | ||
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | import os | 21 | import os |
| 22 | import sys | 22 | import sys |
| 23 | -import glob | ||
| 24 | -import commands | ||
| 25 | import fileinput | 23 | import fileinput |
| 26 | from datetime import date | 24 | from datetime import date |
| 25 | +from builtins import input | ||
| 27 | import gammalib | 26 | import gammalib |
| 28 | 27 | ||
| 29 | 28 | ||
| @@ -47,7 +46,7 @@ def confirm(text): | @@ -47,7 +46,7 @@ def confirm(text): | ||
| 47 | # Confirmation loop | 46 | # Confirmation loop |
| 48 | waiting = True | 47 | waiting = True |
| 49 | while waiting: | 48 | while waiting: |
| 50 | - confirmation = str(raw_input(text+' (y/n): ')) | 49 | + confirmation = str(input(text+' (y/n): ')) |
| 51 | if confirmation == 'q': | 50 | if confirmation == 'q': |
| 52 | sys.exit() | 51 | sys.exit() |
| 53 | elif confirmation == 'y': | 52 | elif confirmation == 'y': |
| @@ -87,7 +86,7 @@ def response(text, confirm_response=False): | @@ -87,7 +86,7 @@ def response(text, confirm_response=False): | ||
| 87 | # Get response from input | 86 | # Get response from input |
| 88 | waiting = True | 87 | waiting = True |
| 89 | while waiting: | 88 | while waiting: |
| 90 | - response = str(raw_input('%s: ' % text)) | 89 | + response = str(input('%s: ' % text)) |
| 91 | if response == 'q': | 90 | if response == 'q': |
| 92 | sys.exit() | 91 | sys.exit() |
| 93 | else: | 92 | else: |
| @@ -275,13 +274,13 @@ def add_ctool(name, tokens, baseclass): | @@ -275,13 +274,13 @@ def add_ctool(name, tokens, baseclass): | ||
| 275 | if 'libctools_la_LIBADD' in line.replace(' ', ''): | 274 | if 'libctools_la_LIBADD' in line.replace(' ', ''): |
| 276 | last = line[-2] | 275 | last = line[-2] |
| 277 | line = line.replace(line, line+insertline2+last+'\n') | 276 | line = line.replace(line, line+insertline2+last+'\n') |
| 278 | - print line, | 277 | + print(line), |
| 279 | 278 | ||
| 280 | # Update Python module | 279 | # Update Python module |
| 281 | for line in fileinput.FileInput('pyext/ctools/tools.i',inplace=1): | 280 | for line in fileinput.FileInput('pyext/ctools/tools.i',inplace=1): |
| 282 | if '%include "ctbin.i"' in line: | 281 | if '%include "ctbin.i"' in line: |
| 283 | print('%%include "%s.i"' % (name)) | 282 | print('%%include "%s.i"' % (name)) |
| 284 | - print line, | 283 | + print(line), |
| 285 | 284 | ||
| 286 | # Update unit test | 285 | # Update unit test |
| 287 | for line in fileinput.FileInput('test/test_python_ctools.py',inplace=1): | 286 | for line in fileinput.FileInput('test/test_python_ctools.py',inplace=1): |
| @@ -289,25 +288,25 @@ def add_ctool(name, tokens, baseclass): | @@ -289,25 +288,25 @@ def add_ctool(name, tokens, baseclass): | ||
| 289 | print('import test_%s' % (name)) | 288 | print('import test_%s' % (name)) |
| 290 | elif 'test_ctbin.Test()' in line: | 289 | elif 'test_ctbin.Test()' in line: |
| 291 | print(' test_%s.Test(),' % (name)) | 290 | print(' test_%s.Test(),' % (name)) |
| 292 | - print line, | 291 | + print(line), |
| 293 | 292 | ||
| 294 | # Update export of unit test | 293 | # Update export of unit test |
| 295 | for line in fileinput.FileInput('pyext/Makefile.am',inplace=1): | 294 | for line in fileinput.FileInput('pyext/Makefile.am',inplace=1): |
| 296 | if '$(top_srcdir)/test/test_ctbin.py' in line: | 295 | if '$(top_srcdir)/test/test_ctbin.py' in line: |
| 297 | print(' $(top_srcdir)/test/test_%s.py \\' % (name)) | 296 | print(' $(top_srcdir)/test/test_%s.py \\' % (name)) |
| 298 | - print line, | 297 | + print(line), |
| 299 | 298 | ||
| 300 | # Update configure.ac | 299 | # Update configure.ac |
| 301 | for line in fileinput.FileInput('configure.ac',inplace=1): | 300 | for line in fileinput.FileInput('configure.ac',inplace=1): |
| 302 | if 'src/ctbin/Makefile' in line: | 301 | if 'src/ctbin/Makefile' in line: |
| 303 | print(' src/%s/Makefile' % (name)) | 302 | print(' src/%s/Makefile' % (name)) |
| 304 | - print line, | 303 | + print(line), |
| 305 | 304 | ||
| 306 | # Update reference manual index file | 305 | # Update reference manual index file |
| 307 | for line in fileinput.FileInput('doc/source/users/reference_manual/index.rst',inplace=1): | 306 | for line in fileinput.FileInput('doc/source/users/reference_manual/index.rst',inplace=1): |
| 308 | if 'ctbin --- Generates counts cube <ctbin>' in line: | 307 | if 'ctbin --- Generates counts cube <ctbin>' in line: |
| 309 | print(' %s --- ToDo: Describe what tool is doing <%s>' % (name, name)) | 308 | print(' %s --- ToDo: Describe what tool is doing <%s>' % (name, name)) |
| 310 | - print line, | 309 | + print(line), |
| 311 | 310 | ||
| 312 | # Return | 311 | # Return |
| 313 | return | 312 | return |
| @@ -356,7 +355,7 @@ def add_cscript(name, tokens, baseclass): | @@ -356,7 +355,7 @@ def add_cscript(name, tokens, baseclass): | ||
| 356 | print(' "%s",' % (name)) | 355 | print(' "%s",' % (name)) |
| 357 | elif 'from cscripts.csworkflow import csworkflow' in line: | 356 | elif 'from cscripts.csworkflow import csworkflow' in line: |
| 358 | print('from cscripts.%s import %s' % (name, name)) | 357 | print('from cscripts.%s import %s' % (name, name)) |
| 359 | - print line, | 358 | + print(line), |
| 360 | 359 | ||
| 361 | # Update cscripts/Makefile.am file | 360 | # Update cscripts/Makefile.am file |
| 362 | for line in fileinput.FileInput('cscripts/Makefile.am',inplace=1): | 361 | for line in fileinput.FileInput('cscripts/Makefile.am',inplace=1): |
| @@ -368,7 +367,7 @@ def add_cscript(name, tokens, baseclass): | @@ -368,7 +367,7 @@ def add_cscript(name, tokens, baseclass): | ||
| 368 | print(' %s \\' % (name)) | 367 | print(' %s \\' % (name)) |
| 369 | elif '$(top_srcdir)/test/test_csworkflow.py' in line: | 368 | elif '$(top_srcdir)/test/test_csworkflow.py' in line: |
| 370 | print(' $(top_srcdir)/test/test_%s.py \\' % (name)) | 369 | print(' $(top_srcdir)/test/test_%s.py \\' % (name)) |
| 371 | - print line, | 370 | + print(line), |
| 372 | 371 | ||
| 373 | # Update test/test_python_cscripts.py file | 372 | # Update test/test_python_cscripts.py file |
| 374 | for line in fileinput.FileInput('test/test_python_cscripts.py',inplace=1): | 373 | for line in fileinput.FileInput('test/test_python_cscripts.py',inplace=1): |
| @@ -376,13 +375,13 @@ def add_cscript(name, tokens, baseclass): | @@ -376,13 +375,13 @@ def add_cscript(name, tokens, baseclass): | ||
| 376 | print('import test_%s' % (name)) | 375 | print('import test_%s' % (name)) |
| 377 | elif 'test_csworkflow.Test()' in line: | 376 | elif 'test_csworkflow.Test()' in line: |
| 378 | print(' test_%s.Test(),' % (name)) | 377 | print(' test_%s.Test(),' % (name)) |
| 379 | - print line, | 378 | + print(line), |
| 380 | 379 | ||
| 381 | # Update reference manual index file | 380 | # Update reference manual index file |
| 382 | for line in fileinput.FileInput('doc/source/users/reference_manual/index.rst',inplace=1): | 381 | for line in fileinput.FileInput('doc/source/users/reference_manual/index.rst',inplace=1): |
| 383 | if 'csbkgmodel --- Generates background model for 3D analysis <csbkgmodel>' in line: | 382 | if 'csbkgmodel --- Generates background model for 3D analysis <csbkgmodel>' in line: |
| 384 | print(' %s --- ToDo: Describe what script is doing <%s>' % (name, name)) | 383 | print(' %s --- ToDo: Describe what script is doing <%s>' % (name, name)) |
| 385 | - print line, | 384 | + print(line), |
| 386 | 385 | ||
| 387 | # Return | 386 | # Return |
| 388 | return | 387 | return |
| @@ -414,7 +413,7 @@ def ctool_menu(): | @@ -414,7 +413,7 @@ def ctool_menu(): | ||
| 414 | waiting = True | 413 | waiting = True |
| 415 | choice = 1 | 414 | choice = 1 |
| 416 | while waiting: | 415 | while waiting: |
| 417 | - choice = str(raw_input('Enter your choice: ')) | 416 | + choice = str(input('Enter your choice: ')) |
| 418 | if choice == '1' or choice == '2' or choice == '3': | 417 | if choice == '1' or choice == '2' or choice == '3': |
| 419 | waiting = False | 418 | waiting = False |
| 420 | if choice == '1': | 419 | if choice == '1': |
| @@ -480,7 +479,7 @@ def cscript_menu(): | @@ -480,7 +479,7 @@ def cscript_menu(): | ||
| 480 | waiting = True | 479 | waiting = True |
| 481 | choice = 1 | 480 | choice = 1 |
| 482 | while waiting: | 481 | while waiting: |
| 483 | - choice = str(raw_input('Enter your choice: ')) | 482 | + choice = str(input('Enter your choice: ')) |
| 484 | if choice == '1' or choice == '2' or choice == '3': | 483 | if choice == '1' or choice == '2' or choice == '3': |
| 485 | waiting = False | 484 | waiting = False |
| 486 | if choice == '1': | 485 | if choice == '1': |
| @@ -535,7 +534,7 @@ def main_menu(): | @@ -535,7 +534,7 @@ def main_menu(): | ||
| 535 | # Wait for the input | 534 | # Wait for the input |
| 536 | waiting = True | 535 | waiting = True |
| 537 | while waiting: | 536 | while waiting: |
| 538 | - choice = str(raw_input('Enter your choice: ')) | 537 | + choice = str(input('Enter your choice: ')) |
| 539 | if choice == '1' or choice == '2' or choice == 'q': | 538 | if choice == '1' or choice == '2' or choice == 'q': |
| 540 | waiting = False | 539 | waiting = False |
| 541 | 540 |