From patchwork Thu May 5 02:03:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 755662 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4523aB0027599 for ; Thu, 5 May 2011 02:03:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752386Ab1EECDd (ORCPT ); Wed, 4 May 2011 22:03:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28279 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752237Ab1EECDd (ORCPT ); Wed, 4 May 2011 22:03:33 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4523Vks018183 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 4 May 2011 22:03:31 -0400 Received: from freedom.redhat.com (vpn-8-237.rdu.redhat.com [10.11.8.237]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4523TpB009486; Wed, 4 May 2011 22:03:30 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues Subject: [PATCH 1/2] Utils: Moving function ask to common lib utils Date: Wed, 4 May 2011 23:03:29 -0300 Message-Id: <1304561010-10271-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 05 May 2011 02:03:37 +0000 (UTC) This way we can use it in other interactive scripts in autotest. Signed-off-by: Lucas Meneghel Rodrigues --- client/common_lib/base_utils.py | 14 ++++++++++++++ utils/check_patch.py | 22 ++++------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/client/common_lib/base_utils.py b/client/common_lib/base_utils.py index c8f2f1a..db7b869 100644 --- a/client/common_lib/base_utils.py +++ b/client/common_lib/base_utils.py @@ -1715,3 +1715,17 @@ def get_unused_port(): # Check if this port is unused on the other protocol. if port and try_bind(port, socket.SOCK_DGRAM, socket.IPPROTO_UDP): return port + + +def ask(question, auto=False): + """ + Raw input with a prompt that emulates logging. + + @param question: Question to be asked + @param auto: Whether to return "y" instead of asking the question + """ + if auto: + logging.info("%s (y/n) y" % question) + return "y" + return raw_input("%s INFO | %s (y/n) " % + (time.strftime("%H:%M:%S", time.localtime()), question)) diff --git a/utils/check_patch.py b/utils/check_patch.py index 78af6b9..bd60d66 100755 --- a/utils/check_patch.py +++ b/utils/check_patch.py @@ -32,20 +32,6 @@ class CheckPatchLoggingConfig(logging_config.LoggingConfig): verbose=verbose) -def ask(question, auto=False): - """ - Raw input with a prompt that emulates logging. - - @param question: Question to be asked - @param auto: Whether to return "y" instead of asking the question - """ - if auto: - logging.info("%s (y/n) y" % question) - return "y" - return raw_input("%s INFO | %s (y/n) " % - (time.strftime("%H:%M:%S", time.localtime()), question)) - - class VCS(object): """ Abstraction layer to the version control system. @@ -307,8 +293,8 @@ class FileChecker(object): self._check_unittest() if self.corrective_actions: for action in self.corrective_actions: - answer = ask("Would you like to execute %s?" % action, - auto=self.confirm) + answer = utils.ask("Would you like to execute %s?" % action, + auto=self.confirm) if answer == "y": rc = utils.system(action, ignore_status=True) if rc != 0: @@ -334,7 +320,7 @@ class PatchChecker(object): if changed_files_before: logging.error("Repository has changed files prior to patch " "application. ") - answer = ask("Would you like to revert them?", auto=self.confirm) + answer = utils.ask("Would you like to revert them?", auto=self.confirm) if answer == "n": logging.error("Not safe to proceed without reverting files.") sys.exit(1) @@ -382,7 +368,7 @@ class PatchChecker(object): for untracked_file in add_to_vcs: logging.info(untracked_file) logging.info("Might need to be added to VCS") - answer = ask("Would you like to add them to VCS ?") + answer = utils.ask("Would you like to add them to VCS ?") if answer == "y": for untracked_file in add_to_vcs: self.vcs.add_untracked_file(untracked_file)