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

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(-)
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 ]

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.
Acked-by: Masahiro Yamada yamada.masahiro@socionext.com Signed-off-by: Chris Packham judge.packham@gmail.com --- 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(+)
diff --git a/tools/moveconfig.py b/tools/moveconfig.py index f8d4857..2361a43 100755 --- a/tools/moveconfig.py +++ b/tools/moveconfig.py @@ -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'])

On 2 May 2017 at 03:30, Chris Packham judge.packham@gmail.com wrote:
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.
Acked-by: Masahiro Yamada yamada.masahiro@socionext.com Signed-off-by: Chris Packham judge.packham@gmail.com
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(+)
Thank you Chris.
Reviewed-by: Simon Glass sjg@chromium.org

On Tue, May 02, 2017 at 09:30:47PM +1200, Chris Packham wrote:
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.
Acked-by: Masahiro Yamada yamada.masahiro@socionext.com Signed-off-by: Chris Packham judge.packham@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

The Kconfig description replaces the description in the README file so as options are migrated they can be removed from the README.
Signed-off-by: Chris Packham judge.packham@gmail.com ---
Changes in v3: None Changes in v2: None
tools/moveconfig.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
diff --git a/tools/moveconfig.py b/tools/moveconfig.py index 2361a43..95ef352 100755 --- a/tools/moveconfig.py +++ b/tools/moveconfig.py @@ -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'])

On 2 May 2017 at 03:30, Chris Packham judge.packham@gmail.com wrote:
The Kconfig description replaces the description in the README file so as options are migrated they can be removed from the README.
Signed-off-by: Chris Packham judge.packham@gmail.com
Changes in v3: None Changes in v2: None
tools/moveconfig.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Tue, May 02, 2017 at 09:30:48PM +1200, Chris Packham wrote:
The Kconfig description replaces the description in the README file so as options are migrated they can be removed from the README.
Signed-off-by: Chris Packham judge.packham@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

CONFIG_CMD_DATE was recently moved to Kconfig. Remove the now duplicate description of the option.
Signed-off-by: Chris Packham judge.packham@gmail.com ---
Changes in v3: None Changes in v2: None
README | 1 - 1 file changed, 1 deletion(-)
diff --git a/README b/README index 0ac0136..78173e2 100644 --- a/README +++ b/README @@ -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

On 2 May 2017 at 03:30, Chris Packham judge.packham@gmail.com wrote:
CONFIG_CMD_DATE was recently moved to Kconfig. Remove the now duplicate description of the option.
Signed-off-by: Chris Packham judge.packham@gmail.com
Changes in v3: None Changes in v2: None
README | 1 - 1 file changed, 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Tue, May 02, 2017 at 09:30:49PM +1200, Chris Packham wrote:
CONFIG_CMD_DATE was recently moved to Kconfig. Remove the now duplicate description of the option.
Signed-off-by: Chris Packham judge.packham@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

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

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!
participants (3)
-
Chris Packham
-
Simon Glass
-
Tom Rini