From: Volker Theile Date: Thu, 29 Nov 2018 12:48:30 +0000 (+0100) Subject: ceph-volume: Adapt code to support Python3 X-Git-Tag: v13.2.5~133^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=29ccfb93e90046e8ad7a9d48d548ef57db6a3ffb;p=ceph.git 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) --- 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 2d3f904f85b3..1a094d33f5bc 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 73f404721ed4..43c9c9d6835d 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__) @@ -78,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: @@ -92,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)