diff --git a/external_updater.py b/external_updater.py index 4ceaa21d3bcd7b54e49eebdc48851b595a2e4d61..4bc8aa30f30cf56f0d8e8eb4e12cce0ceb93fd51 100644 --- a/external_updater.py +++ b/external_updater.py @@ -36,8 +36,9 @@ UPDATERS = [GithubArchiveUpdater, GitUpdater] def color_string(string, color): """Changes the color of a string when print to terminal.""" colors = { - 'SUCCESS': '\x1b[92m', - 'FAILED': '\x1b[91m', + 'FRESH': '\x1b[32m', + 'STALE': '\x1b[31;1m', + 'ERROR': '\x1b[31m', } end_color = '\033[0m' return colors[color] + string + end_color @@ -59,14 +60,14 @@ def build_updater(proj_path): try: metadata = fileutils.read_metadata(proj_path) except text_format.ParseError as err: - print('{} {}.'.format(color_string('Invalid metadata file:', 'FAILED'), + print('{} {}.'.format(color_string('Invalid metadata file:', 'ERROR'), err)) return None try: updater = updater_utils.create_updater(metadata, proj_path, UPDATERS) except ValueError: - print(color_string('No supported URL.', 'FAILED')) + print(color_string('No supported URL.', 'ERROR')) return None return updater @@ -79,8 +80,7 @@ def check_update(proj_path): """ print( - '{} {}. '.format(color_string('Checking', 'SUCCESS'), - fileutils.get_relative_project_path(proj_path)), + 'Checking {}. '.format(fileutils.get_relative_project_path(proj_path)), end='') updater = build_updater(proj_path) if updater is None: @@ -88,12 +88,12 @@ def check_update(proj_path): try: new_version = updater.check() if new_version: - print(color_string(' New version found.', 'SUCCESS')) + print(color_string(' Out of date!', 'STALE')) else: - print(' No new version.') + print(color_string(' Up to date.', 'FRESH')) return (updater, new_version) except IOError as err: - print('{} {}.'.format(color_string('Failed.', 'FAILED'), + print('{} {}.'.format(color_string('Failed.', 'ERROR'), err)) return (None, None) except subprocess.CalledProcessError as err: @@ -101,7 +101,7 @@ def check_update(proj_path): '{} {}\nstdout: {}\nstderr: {}.'.format( color_string( 'Failed.', - 'FAILED'), + 'ERROR'), err, err.stdout, err.stderr))