Skip to contentSkip to conversation

tools: moveconfig: extract helper function for user confirmation

PATCH New Chris Packham 3 participants 12 messages May 2, 2017 – May 8, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/4 tools: moveconfig: extract helper function for user confirmation

Avoid repetitive code dealing with asking the user for confirmation.

---

Changes in v3: None
Changes in v2: None

 tools/moveconfig.py | 37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)
tools/moveconfig.py +18 -19
index dcca0ec..f8d4857 100755
@@ -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 ]
 
Signature · 1 line
2.10.1
#1 lore raw

PATCH v3 2/4 tools: moveconfig: cleanup whitelist entries

After moving to KConfig and removing from all headers options should be removed from config_whitelist.txt so the build starts complaining if someone adds them back.

---
Simon asked for it so here you go. I also thought about cleaning up the README file references too but that will take a little bit of work to parse reliably.

Changes in v3:
- Apply on top of cleanup patch

Changes in v2:
- Correct typo
- Collect ack from Masahiro

 tools/moveconfig.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/moveconfig.py +20 -0
index f8d4857..2361a43 100755
@@ -600,6 +600,25 @@ def cleanup_extra_options(configs, options):
         cleanup_one_extra_option(os.path.join('configs', defconfig), configs,
                                  options)
 
+def cleanup_whitelist(configs, options):
+    """Delete config whitelist entries
+
+    Arguments:
+      configs: A list of CONFIGs to remove.
+      options: option flags.
+    """
+    if not confirm(options, 'Clean up whitelist entries?'):
+        return
+
+    with open(os.path.join('scripts', 'config_whitelist.txt')) as f:
+        lines = f.readlines()
+
+    lines = [x for x in lines if x.strip() not in configs]
+
+    with open(os.path.join('scripts', 'config_whitelist.txt'), 'w') as f:
+        f.write(''.join(lines))
+
+
 ### classes ###
 class Progress:
 
@@ -1296,6 +1315,7 @@ def main():
     if configs:
         cleanup_headers(configs, options)
         cleanup_extra_options(configs, options)
+        cleanup_whitelist(configs, options)
 
     if options.commit:
         subprocess.call(['git', 'add', '-u'])
Signature · 1 line
2.10.1
#2 lore raw

PATCH v3 2/4 tools: moveconfig: cleanup whitelist entries

Quoted 14 lines · Chris Packham

After moving to KConfig and removing from all headers options should be removed from config_whitelist.txt so the build starts complaining if someone adds them back.

---
Simon asked for it so here you go. I also thought about cleaning up the README file references too but that will take a little bit of work to parse reliably.

Changes in v3:
- Apply on top of cleanup patch

Quoted 6 lines

Changes in v2:
- Correct typo
- Collect ack from Masahiro

 tools/moveconfig.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Thank you Chris.

#3 lore raw

PATCH v3 2/4 tools: moveconfig: cleanup whitelist entries

In reply to Chris Packham
Quoted 7 lines · Chris Packham

After moving to KConfig and removing from all headers options should be removed from config_whitelist.txt so the build starts complaining if someone adds them back.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170508/3bffb22d/attachment.sig>
#4 lore raw

PATCH v3 3/4 tools: moveconfig: cleanup README entires

In reply to Chris Packham

The Kconfig description replaces the description in the README file so as options are migrated they can be removed from the README.

---

Changes in v3: None
Changes in v2: None

 tools/moveconfig.py | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
tools/moveconfig.py +41 -0
index 2361a43..95ef352 100755
@@ -618,6 +618,46 @@ def cleanup_whitelist(configs, options):
     with open(os.path.join('scripts', 'config_whitelist.txt'), 'w') as f:
         f.write(''.join(lines))
 
+def find_matching(patterns, line):
+    for pat in patterns:
+        if pat.search(line):
+            return True
+    return False
+
+def cleanup_readme(configs, options):
+    """Delete config description in README
+
+    Arguments:
+      configs: A list of CONFIGs to remove.
+      options: option flags.
+    """
+    if not confirm(options, 'Clean up README?'):
+        return
+
+    patterns = []
+    for config in configs:
+        patterns.append(re.compile(r'^\s+%s' % config))
+
+    with open('README') as f:
+        lines = f.readlines()
+
+    found = False
+    newlines = []
+    for line in lines:
+        if not found:
+            found = find_matching(patterns, line)
+            if found:
+                continue
+
+        if found and re.search(r'^\s+CONFIG', line):
+            found = False
+
+        if not found:
+            newlines.append(line)
+
+    with open('README', 'w') as f:
+        f.write(''.join(newlines))
+
 
 ### classes ###
 class Progress:
@@ -1316,6 +1356,7 @@ def main():
         cleanup_headers(configs, options)
         cleanup_extra_options(configs, options)
         cleanup_whitelist(configs, options)
+        cleanup_readme(configs, options)
 
     if options.commit:
         subprocess.call(['git', 'add', '-u'])
Signature · 1 line
2.10.1
#5 lore raw

PATCH v3 3/4 tools: moveconfig: cleanup README entires

Quoted 12 lines · Chris Packham

The Kconfig description replaces the description in the README file so as options are migrated they can be removed from the README.

---

Changes in v3: None
Changes in v2: None

 tools/moveconfig.py | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
#6 lore raw

PATCH v3 3/4 tools: moveconfig: cleanup README entires

In reply to Chris Packham
Quoted 5 lines · Chris Packham

The Kconfig description replaces the description in the README file so as options are migrated they can be removed from the README.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170508/7efe2a11/attachment.sig>
#7 lore raw

PATCH v3 4/4 README: remove CONFIG_CMD_DATE

In reply to Chris Packham

CONFIG_CMD_DATE was recently moved to Kconfig. Remove the now duplicate description of the option.

---

Changes in v3: None
Changes in v2: None

 README | 1 -
 1 file changed, 1 deletion(-)
README +0 -1
index 0ac0136..78173e2 100644
@@ -828,7 +828,6 @@ The following options need to be configured:
 		CONFIG_CMD_CACHE	* icache, dcache
 		CONFIG_CMD_CONSOLE	  coninfo
 		CONFIG_CMD_CRC32	* crc32
-		CONFIG_CMD_DATE		* support for RTC, date/time...
 		CONFIG_CMD_DHCP		* DHCP support
 		CONFIG_CMD_DIAG		* Diagnostics
 		CONFIG_CMD_DS4510	* ds4510 I2C gpio commands
Signature · 1 line
2.10.1
#9 lore raw

PATCH v3 4/4 README: remove CONFIG_CMD_DATE

In reply to Chris Packham
Quoted 5 lines · Chris Packham

CONFIG_CMD_DATE was recently moved to Kconfig. Remove the now duplicate description of the option.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170508/e07f548a/attachment.sig>
#11 lore raw

PATCH v3 1/4 tools: moveconfig: extract helper function for user confirmation

In reply to Chris Packham
Quoted 4 lines · Chris Packham

Avoid repetitive code dealing with asking the user for confirmation.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170508/6746bf40/attachment.sig>