Skip to content
Snippets Groups Projects
Commit 3f73a459 authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Distinguish more clearly between the three states.

Showing the things you need to fix in green was surprising to me.

Errors and successfully determining that a project is stale both deserve
to be red, but use bold so that we can see the projects that need to be
updated even while there are lots of unsupported METADATA files.

Bug: N/A
Test: manual
Change-Id: Idad71a46c675b19d1fa204268c27816375f3e394
parent 24950e79
No related branches found
No related tags found
No related merge requests found
...@@ -36,8 +36,9 @@ UPDATERS = [GithubArchiveUpdater, GitUpdater] ...@@ -36,8 +36,9 @@ UPDATERS = [GithubArchiveUpdater, GitUpdater]
def color_string(string, color): def color_string(string, color):
"""Changes the color of a string when print to terminal.""" """Changes the color of a string when print to terminal."""
colors = { colors = {
'SUCCESS': '\x1b[92m', 'FRESH': '\x1b[32m',
'FAILED': '\x1b[91m', 'STALE': '\x1b[31;1m',
'ERROR': '\x1b[31m',
} }
end_color = '\033[0m' end_color = '\033[0m'
return colors[color] + string + end_color return colors[color] + string + end_color
...@@ -59,14 +60,14 @@ def build_updater(proj_path): ...@@ -59,14 +60,14 @@ def build_updater(proj_path):
try: try:
metadata = fileutils.read_metadata(proj_path) metadata = fileutils.read_metadata(proj_path)
except text_format.ParseError as err: except text_format.ParseError as err:
print('{} {}.'.format(color_string('Invalid metadata file:', 'FAILED'), print('{} {}.'.format(color_string('Invalid metadata file:', 'ERROR'),
err)) err))
return None return None
try: try:
updater = updater_utils.create_updater(metadata, proj_path, UPDATERS) updater = updater_utils.create_updater(metadata, proj_path, UPDATERS)
except ValueError: except ValueError:
print(color_string('No supported URL.', 'FAILED')) print(color_string('No supported URL.', 'ERROR'))
return None return None
return updater return updater
...@@ -79,8 +80,7 @@ def check_update(proj_path): ...@@ -79,8 +80,7 @@ def check_update(proj_path):
""" """
print( print(
'{} {}. '.format(color_string('Checking', 'SUCCESS'), 'Checking {}. '.format(fileutils.get_relative_project_path(proj_path)),
fileutils.get_relative_project_path(proj_path)),
end='') end='')
updater = build_updater(proj_path) updater = build_updater(proj_path)
if updater is None: if updater is None:
...@@ -88,12 +88,12 @@ def check_update(proj_path): ...@@ -88,12 +88,12 @@ def check_update(proj_path):
try: try:
new_version = updater.check() new_version = updater.check()
if new_version: if new_version:
print(color_string(' New version found.', 'SUCCESS')) print(color_string(' Out of date!', 'STALE'))
else: else:
print(' No new version.') print(color_string(' Up to date.', 'FRESH'))
return (updater, new_version) return (updater, new_version)
except IOError as err: except IOError as err:
print('{} {}.'.format(color_string('Failed.', 'FAILED'), print('{} {}.'.format(color_string('Failed.', 'ERROR'),
err)) err))
return (None, None) return (None, None)
except subprocess.CalledProcessError as err: except subprocess.CalledProcessError as err:
...@@ -101,7 +101,7 @@ def check_update(proj_path): ...@@ -101,7 +101,7 @@ def check_update(proj_path):
'{} {}\nstdout: {}\nstderr: {}.'.format( '{} {}\nstdout: {}\nstderr: {}.'.format(
color_string( color_string(
'Failed.', 'Failed.',
'FAILED'), 'ERROR'),
err, err,
err.stdout, err.stdout,
err.stderr)) err.stderr))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment