From fe25a0ea625e75c598f6d0749e7259eef167fa8e 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 --- src/ceph-volume/ceph_volume/tests/util/test_util.py | 8 ++++---- src/ceph-volume/ceph_volume/util/__init__.py | 11 ++++++++--- 2 files changed, 12 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 82f2ef27f64..20c4f7861ad 100644 --- a/src/ceph-volume/ceph_volume/tests/util/test_util.py +++ b/src/ceph-volume/ceph_volume/tests/util/test_util.py @@ -75,22 +75,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 dfa83fc46d3..3415679a82e 100644 --- a/src/ceph-volume/ceph_volume/util/__init__.py +++ b/src/ceph-volume/ceph_volume/util/__init__.py @@ -2,6 +2,11 @@ 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__) @@ -67,12 +72,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: @@ -81,4 +86,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