diff mbox

[U-Boot,v3,1/4] tools: moveconfig: extract helper function for user confirmation

Message ID 20170502093049.20915-1-judge.packham@gmail.com
State Accepted
Commit 85edfc1f6fdf1630c00dc57a63ab66d51608092e
Delegated to: Tom Rini
Headers show

Commit Message

Chris Packham May 2, 2017, 9:30 a.m. UTC
Avoid repetitive code dealing with asking the user for confirmation.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
---

Changes in v3: None
Changes in v2: None

 tools/moveconfig.py | 37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)

Comments

Simon Glass May 4, 2017, 4:50 p.m. UTC | #1
On 2 May 2017 at 03:30, Chris Packham <judge.packham@gmail.com> wrote:
> Avoid repetitive code dealing with asking the user for confirmation.
>
> Signed-off-by: Chris Packham <judge.packham@gmail.com>
> ---
>
> Changes in v3: None
> Changes in v2: None
>
>  tools/moveconfig.py | 37 ++++++++++++++++++-------------------
>  1 file changed, 18 insertions(+), 19 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini May 8, 2017, 7:43 p.m. UTC | #2
On Tue, May 02, 2017 at 09:30:46PM +1200, Chris Packham wrote:

> Avoid repetitive code dealing with asking the user for confirmation.
> 
> Signed-off-by: Chris Packham <judge.packham@gmail.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/tools/moveconfig.py b/tools/moveconfig.py
index dcca0ec..f8d4857 100755
--- a/tools/moveconfig.py
+++ b/tools/moveconfig.py
@@ -435,6 +435,20 @@  def extend_matched_lines(lines, matched, pre_patterns, post_patterns, extend_pre
     matched += extended_matched
     matched.sort()
 
+def confirm(options, prompt):
+    if not options.yes:
+        while True:
+            choice = raw_input('{} [y/n]: '.format(prompt))
+            choice = choice.lower()
+            print choice
+            if choice == 'y' or choice == 'n':
+                break
+
+        if choice == 'n':
+            return False
+
+    return True
+
 def cleanup_one_header(header_path, patterns, options):
     """Clean regex-matched lines away from a file.
 
@@ -502,15 +516,8 @@  def cleanup_headers(configs, options):
       configs: A list of CONFIGs to remove.
       options: option flags.
     """
-    if not options.yes:
-        while True:
-            choice = raw_input('Clean up headers? [y/n]: ').lower()
-            print choice
-            if choice == 'y' or choice == 'n':
-                break
-
-        if choice == 'n':
-            return
+    if not confirm(options, 'Clean up headers?'):
+        return
 
     patterns = []
     for config in configs:
@@ -582,16 +589,8 @@  def cleanup_extra_options(configs, options):
       configs: A list of CONFIGs to remove.
       options: option flags.
     """
-    if not options.yes:
-        while True:
-            choice = (raw_input('Clean up CONFIG_SYS_EXTRA_OPTIONS? [y/n]: ').
-                      lower())
-            print choice
-            if choice == 'y' or choice == 'n':
-                break
-
-        if choice == 'n':
-            return
+    if not confirm(options, 'Clean up CONFIG_SYS_EXTRA_OPTIONS?'):
+        return
 
     configs = [ config[len('CONFIG_'):] for config in configs ]