Salome HOME
fix some raw_input as input python2/3
authorChristian Van Wambeke <christian.van-wambeke@cea.fr>
Mon, 17 Dec 2018 14:58:58 +0000 (15:58 +0100)
committerChristian Van Wambeke <christian.van-wambeke@cea.fr>
Mon, 17 Dec 2018 14:58:58 +0000 (15:58 +0100)
commands/template.py
commands/test.py

index 95419d0e1bab5d199c3cd11d5d0edd632aad161c..c2a3ee6e9cdda2a1c448b0ce68e5e77b7389cb2a 100644 (file)
@@ -32,6 +32,15 @@ try:
 except NameError: 
     pass
 
+# Python 2/3 compatibility for execfile function
+try:
+    execfile
+except:
+    def execfile(somefile, global_vars, local_vars):
+        with open(somefile) as f:
+            code = compile(f.read(), somefile, 'exec')
+            exec(code, global_vars, local_vars)
+
 parser = src.options.Options()
 parser.add_option('n', 'name', 'string', 'name',
     _("""REQUIRED: the name of the module to create.
@@ -183,7 +192,7 @@ class TemplateSettings:
             
             val = ""
             while not tp.check_value(val):
-                val = raw_input(tp.prompt)
+                val = input(tp.prompt)
                 if len(val) == 0 and len(tp.default) > 0:
                     val = tp.default
             dico[tp.name] = val
@@ -193,7 +202,7 @@ class TemplateSettings:
         for p in filter(lambda l: not dico.has_key(l), pyconfparam):
             rep = ""
             while len(rep) == 0:
-                rep = raw_input("%s? " % p)
+                rep = input("%s? " % p)
             dico[p] = rep
 
         self.dico = dico
index 2daf44f438ad846ddaff277da55b9c87bbe409b3..a0fd6a28dcac94452a758a5c73b7777cac70cb72 100644 (file)
@@ -23,6 +23,13 @@ import subprocess
 import datetime
 import gzip
 
+# Compatibility python 2/3 for input function
+# input stays input for python 3 and input = raw_input for python 2
+try:
+    input = raw_input
+except NameError:
+    pass
+
 verbose = False
 
 try:
@@ -122,9 +129,9 @@ def parse_option(args, config):
 def ask_a_path():
     """ 
     """
-    path = raw_input("enter a path where to save the result: ")
+    path = input("enter a path where to save the result: ")
     if path == "":
-        result = raw_input("the result will be not save. Are you sure to "
+        result = input("the result will be not save. Are you sure to "
                            "continue ? [y/n] ")
         if result == "y":
             return path
@@ -132,7 +139,7 @@ def ask_a_path():
             return ask_a_path()
 
     elif os.path.exists(path):
-        result = raw_input("Warning, the content of %s will be deleted. Are you"
+        result = input("Warning, the content of %s will be deleted. Are you"
                            " sure to continue ? [y/n] " % path)
         if result == "y":
             return path