Commit accdc3ba41614b075921974f42588e4198e3bb93

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