mirror of
https://xff.cz/git/u-boot/
synced 2025-09-01 16:52:14 +02:00
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>
This commit is contained in:
committed by
Tom Rini
parent
f2f6981a14
commit
e9ea122159
@@ -276,13 +276,14 @@ def color_text(color_enabled, color, string):
|
|||||||
else:
|
else:
|
||||||
return string
|
return string
|
||||||
|
|
||||||
def show_diff(a, b, file_path):
|
def show_diff(a, b, file_path, color_enabled):
|
||||||
"""Show unidified diff.
|
"""Show unidified diff.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
a: A list of lines (before)
|
a: A list of lines (before)
|
||||||
b: A list of lines (after)
|
b: A list of lines (after)
|
||||||
file_path: Path to the file
|
file_path: Path to the file
|
||||||
|
color_enabled: Display the diff in color
|
||||||
"""
|
"""
|
||||||
|
|
||||||
diff = difflib.unified_diff(a, b,
|
diff = difflib.unified_diff(a, b,
|
||||||
@@ -290,7 +291,12 @@ def show_diff(a, b, file_path):
|
|||||||
tofile=os.path.join('b', file_path))
|
tofile=os.path.join('b', file_path))
|
||||||
|
|
||||||
for line in diff:
|
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):
|
def update_cross_compile(color_enabled):
|
||||||
"""Update per-arch CROSS_COMPILE via environment variables
|
"""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 += extended_matched
|
||||||
matched.sort()
|
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.
|
"""Clean regex-matched lines away from a file.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
header_path: path to the cleaned file.
|
header_path: path to the cleaned file.
|
||||||
patterns: list of regex patterns. Any lines matching to these
|
patterns: list of regex patterns. Any lines matching to these
|
||||||
patterns are deleted.
|
patterns are deleted.
|
||||||
dry_run: make no changes, but still display log.
|
options: option flags.
|
||||||
"""
|
"""
|
||||||
with open(header_path) as f:
|
with open(header_path) as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
@@ -436,21 +442,21 @@ def cleanup_one_header(header_path, patterns, dry_run):
|
|||||||
for i in reversed(matched):
|
for i in reversed(matched):
|
||||||
tolines.pop(i)
|
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
|
return
|
||||||
|
|
||||||
with open(header_path, 'w') as f:
|
with open(header_path, 'w') as f:
|
||||||
for line in tolines:
|
for line in tolines:
|
||||||
f.write(line)
|
f.write(line)
|
||||||
|
|
||||||
def cleanup_headers(configs, dry_run):
|
def cleanup_headers(configs, options):
|
||||||
"""Delete config defines from board headers.
|
"""Delete config defines from board headers.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
configs: A list of CONFIGs to remove.
|
configs: A list of CONFIGs to remove.
|
||||||
dry_run: make no changes, but still display log.
|
options: option flags.
|
||||||
"""
|
"""
|
||||||
while True:
|
while True:
|
||||||
choice = raw_input('Clean up headers? [y/n]: ').lower()
|
choice = raw_input('Clean up headers? [y/n]: ').lower()
|
||||||
@@ -473,7 +479,7 @@ def cleanup_headers(configs, dry_run):
|
|||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
if not fnmatch.fnmatch(filename, '*~'):
|
if not fnmatch.fnmatch(filename, '*~'):
|
||||||
cleanup_one_header(os.path.join(dirpath, filename),
|
cleanup_one_header(os.path.join(dirpath, filename),
|
||||||
patterns, dry_run)
|
patterns, options)
|
||||||
|
|
||||||
### classes ###
|
### classes ###
|
||||||
class Progress:
|
class Progress:
|
||||||
@@ -1145,7 +1151,7 @@ def main():
|
|||||||
move_config(configs, options)
|
move_config(configs, options)
|
||||||
|
|
||||||
if configs:
|
if configs:
|
||||||
cleanup_headers(configs, options.dry_run)
|
cleanup_headers(configs, options)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Reference in New Issue
Block a user