From 9b082bcb3c10b20874a5d33474788b29731427ed Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Thu, 29 Nov 2018 13:48:30 +0100 Subject: [PATCH] ceph-volume: Adapt code to support Python3 - raw_input() has been renamed to input() in Python3 - Changed signature of prompt_bool. Variables that are named like built-ins must be named like xxx_ and not _xxx Fixes: https://tracker.ceph.com/issues/37470 Signed-off-by: Volker Theile (cherry picked from commit fe25a0ea625e75c598f6d0749e7259eef167fa8e) --- src/ceph-volume/ceph_volume/tests/util/test_util.py | 8 ++++---- src/ceph-volume/ceph_volume/util/__init__.py | 10 +++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ceph-volume/ceph_volume/tests/util/test_util.py b/src/ceph-volume/ceph_volume/tests/util/test_util.py index 2d3f904f85b3a..1a094d33f5bcf 100644 --- a/src/ceph-volume/ceph_volume/tests/util/test_util.py +++ b/src/ceph-volume/ceph_volume/tests/util/test_util.py @@ -95,22 +95,22 @@ class TestPromptBool(object): def test_trueish(self, response): fake_input = lambda x: response qx = 'what the what?' - assert util.prompt_bool(qx, _raw_input=fake_input) is True + assert util.prompt_bool(qx, input_=fake_input) is True @pytest.mark.parametrize('response', false_responses()) def test_falseish(self, response): fake_input = lambda x: response qx = 'what the what?' - assert util.prompt_bool(qx, _raw_input=fake_input) is False + assert util.prompt_bool(qx, input_=fake_input) is False def test_try_again_true(self): responses = ['g', 'h', 'y'] fake_input = lambda x: responses.pop(0) qx = 'what the what?' - assert util.prompt_bool(qx, _raw_input=fake_input) is True + assert util.prompt_bool(qx, input_=fake_input) is True def test_try_again_false(self): responses = ['g', 'h', 'n'] fake_input = lambda x: responses.pop(0) qx = 'what the what?' - assert util.prompt_bool(qx, _raw_input=fake_input) is False + assert util.prompt_bool(qx, input_=fake_input) is False diff --git a/src/ceph-volume/ceph_volume/util/__init__.py b/src/ceph-volume/ceph_volume/util/__init__.py index db6e8c72451dc..43c9c9d6835d1 100644 --- a/src/ceph-volume/ceph_volume/util/__init__.py +++ b/src/ceph-volume/ceph_volume/util/__init__.py @@ -2,6 +2,10 @@ import logging from math import floor from ceph_volume import terminal +try: + input = raw_input # pylint: disable=redefined-builtin +except NameError: + pass logger = logging.getLogger(__name__) @@ -79,12 +83,12 @@ def str_to_bool(val): raise ValueError("Invalid input value: %s" % val) -def prompt_bool(question, _raw_input=None): +def prompt_bool(question, input_=None): """ Interface to prompt a boolean (or boolean-like) response from a user. Usually a confirmation. """ - input_prompt = _raw_input or raw_input + input_prompt = input_ or input prompt_format = '--> {question} '.format(question=question) response = input_prompt(prompt_format) try: @@ -93,4 +97,4 @@ def prompt_bool(question, _raw_input=None): terminal.error('Valid true responses are: y, yes, ') terminal.error('Valid false responses are: n, no') terminal.error('That response was invalid, please try again') - return prompt_bool(question, _raw_input=input_prompt) + return prompt_bool(question, input_=input_prompt) -- 2.39.5