summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2016-07-25 19:15:26 +0900
committerTom Rini <trini@konsulko.com>2016-08-05 07:27:16 -0400
commite9ea122159ae9b17355f7891f09530ed79940441 (patch)
tree5e1ddfc30759f3f99665014c388d7ea2f866aea2 /tools
parentf2f6981a149572675ec7e59a33fb414440364739 (diff)
downloadu-boot-imx-e9ea122159ae9b17355f7891f09530ed79940441.zip
u-boot-imx-e9ea122159ae9b17355f7891f09530ed79940441.tar.gz
u-boot-imx-e9ea122159ae9b17355f7891f09530ed79940441.tar.bz2
tools: moveconfig: show diffs of cleaned headers in color
Show code diff in color if --color option is given. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/moveconfig.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/tools/moveconfig.py b/tools/moveconfig.py
index 8bca7e4..2535079 100755
--- a/tools/moveconfig.py
+++ b/tools/moveconfig.py
@@ -276,13 +276,14 @@ def color_text(color_enabled, color, string):
else:
return string
-def show_diff(a, b, file_path):
+def show_diff(a, b, file_path, color_enabled):
"""Show unidified diff.
Arguments:
a: A list of lines (before)
b: A list of lines (after)
file_path: Path to the file
+ color_enabled: Display the diff in color
"""
diff = difflib.unified_diff(a, b,
@@ -290,7 +291,12 @@ def show_diff(a, b, file_path):
tofile=os.path.join('b', file_path))
for line in diff:
- print line,
+ if line[0] == '-' and line[1] != '-':
+ print color_text(color_enabled, COLOR_RED, line),
+ elif line[0] == '+' and line[1] != '+':
+ print color_text(color_enabled, COLOR_GREEN, line),
+ else:
+ print line,
def update_cross_compile(color_enabled):
"""Update per-arch CROSS_COMPILE via environment variables
@@ -388,14 +394,14 @@ def extend_matched_lines(lines, matched, pre_patterns, post_patterns, extend_pre
matched += extended_matched
matched.sort()
-def cleanup_one_header(header_path, patterns, dry_run):
+def cleanup_one_header(header_path, patterns, options):
"""Clean regex-matched lines away from a file.
Arguments:
header_path: path to the cleaned file.
patterns: list of regex patterns. Any lines matching to these
patterns are deleted.
- dry_run: make no changes, but still display log.
+ options: option flags.
"""
with open(header_path) as f:
lines = f.readlines()
@@ -436,21 +442,21 @@ def cleanup_one_header(header_path, patterns, dry_run):
for i in reversed(matched):
tolines.pop(i)
- show_diff(lines, tolines, header_path)
+ show_diff(lines, tolines, header_path, options.color)
- if dry_run:
+ if options.dry_run:
return
with open(header_path, 'w') as f:
for line in tolines:
f.write(line)
-def cleanup_headers(configs, dry_run):
+def cleanup_headers(configs, options):
"""Delete config defines from board headers.
Arguments:
configs: A list of CONFIGs to remove.
- dry_run: make no changes, but still display log.
+ options: option flags.
"""
while True:
choice = raw_input('Clean up headers? [y/n]: ').lower()
@@ -473,7 +479,7 @@ def cleanup_headers(configs, dry_run):
for filename in filenames:
if not fnmatch.fnmatch(filename, '*~'):
cleanup_one_header(os.path.join(dirpath, filename),
- patterns, dry_run)
+ patterns, options)
### classes ###
class Progress:
@@ -1145,7 +1151,7 @@ def main():
move_config(configs, options)
if configs:
- cleanup_headers(configs, options.dry_run)
+ cleanup_headers(configs, options)
if __name__ == '__main__':
main()