From 545d52d0e35c9862e0bab2bfd1ec59d6e48cb289 Mon Sep 17 00:00:00 2001 From: Christian Van Wambeke Date: Mon, 17 Dec 2018 15:58:58 +0100 Subject: [PATCH] fix some raw_input as input python2/3 --- commands/template.py | 13 +++++++++++-- commands/test.py | 13 ++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/commands/template.py b/commands/template.py index 95419d0..c2a3ee6 100644 --- a/commands/template.py +++ b/commands/template.py @@ -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 diff --git a/commands/test.py b/commands/test.py index 2daf44f..a0fd6a2 100644 --- a/commands/test.py +++ b/commands/test.py @@ -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 -- 2.39.2