From e222ae8e991896ef598d377723ee4f7320fc2e0d Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Mon, 30 Aug 2021 11:37:21 +0200 Subject: [PATCH] Replace cformat() with Color() --- bin/maintenance/update_header.py | 18 +++++++++--------- bin/utils/storage_checksums.py | 6 +++--- indico/cli/database.py | 20 ++++++++++---------- indico/cli/devserver.py | 4 ++-- indico/cli/i18n.py | 4 ++-- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/bin/maintenance/update_header.py b/bin/maintenance/update_header.py index 8a5e17004ef..7ca025f3a68 100644 --- a/bin/maintenance/update_header.py +++ b/bin/maintenance/update_header.py @@ -14,7 +14,7 @@ import click import yaml -from indico.util.console import cformat +from indico.vendor.colorclass import Color # Dictionary listing the files for which to change the header. @@ -127,14 +127,14 @@ def _update_header(file_path, config, substring, regex, data, ci): if shebang_line: content = shebang_line + '\n' + content if content != orig_content: - msg = 'Incorrect header in {}' if ci else cformat('%{green!}Updating header of %{blue!}{}') + msg = 'Incorrect header in {}' if ci else Color('{b}{green}Updating header of {blue}{}{reset}') print(msg.format(os.path.relpath(file_path))) if not ci: with open(file_path, 'w') as file_write: file_write.write(content) return True elif not found: - msg = 'Missing header in {}' if ci else cformat('%{red!}Missing header%{reset} in %{blue!}{}') + msg = 'Missing header in {}' if ci else Color('{b}{red}Missing header{reset} in {b}{blue}{}{reset}') print(msg.format(os.path.relpath(file_path))) return True @@ -174,8 +174,8 @@ def main(ctx, ci, year, path): error = False if path and os.path.isdir(path): if not ci: - print(cformat('Updating headers to the year %{yellow!}{year}%{reset} for all the files in ' - '%{yellow!}{path}%{reset}...').format(year=year, path=path)) + print(Color('Updating headers to the year {b}{yellow}{year}{reset} for all the files in ' + '{b}{yellow}{path}{reset}...').format(year=year, path=path)) for root, _, filenames in os.walk(path): for filename in filenames: if not blacklisted(path, root): @@ -183,14 +183,14 @@ def main(ctx, ci, year, path): error = True elif path and os.path.isfile(path): if not ci: - print(cformat('Updating headers to the year %{yellow!}{year}%{reset} for the file ' - '%{yellow!}{file}%{reset}...').format(year=year, file=path)) + print(Color('Updating headers to the year {b}{yellow}{year}{reset} for the file ' + '{b}{yellow}{file}{reset}...').format(year=year, file=path)) if update_header(path, year, ci): error = True else: if not ci: - print(cformat('Updating headers to the year %{yellow!}{year}%{reset} for all ' - 'git-tracked files...').format(year=year)) + print(Color('Updating headers to the year {b}{yellow}{year}{reset} for all ' + 'git-tracked files...').format(year=year)) try: for filepath in subprocess.check_output(['git', 'ls-files'], text=True).splitlines(): filepath = os.path.abspath(filepath) diff --git a/bin/utils/storage_checksums.py b/bin/utils/storage_checksums.py index bc47e378a97..28cb3fc2e37 100644 --- a/bin/utils/storage_checksums.py +++ b/bin/utils/storage_checksums.py @@ -15,8 +15,8 @@ from indico.core.db import db from indico.core.storage import StoredFileMixin from indico.modules.events.static.models.static import StaticSite, StaticSiteState -from indico.util.console import cformat from indico.util.fs import get_file_checksum +from indico.vendor.colorclass import Color from indico.web.flask.app import make_app @@ -49,7 +49,7 @@ def query_chunked(model, chunk_size): def main(): models = {model: make_query(model).count() for model in StoredFileMixin.__subclasses__()} models = {model: total for model, total in models.items() if total} - labels = {model: cformat('Processing %{blue!}{}%{reset} (%{cyan}{}%{reset} rows)').format(model.__name__, total) + labels = {model: Color('Processing {b}{blue}{}{reset} ({cyan}{}{reset} rows)').format(model.__name__, total) for model, total in models.items()} max_length = max(len(x) for x in labels.values()) labels = {model: label.ljust(max_length) for model, label in labels.items()} @@ -61,7 +61,7 @@ def main(): with obj.open() as f: checksum = get_file_checksum(f) except Exception as exc: - click.echo(cformat('\n%{red!}Could not open %{reset}%{yellow}{}%{red!}: %{reset}%{yellow!}{}') + click.echo(Color('\n{b}{red}Could not open {reset}{yellow}{}{b}{red}: {reset}{b}{yellow}{}{reset}') .format(obj, exc)) else: obj.md5 = checksum diff --git a/indico/cli/database.py b/indico/cli/database.py index a55e41ff449..8fabf7e13fd 100644 --- a/indico/cli/database.py +++ b/indico/cli/database.py @@ -21,7 +21,7 @@ from indico.core.db.sqlalchemy.migration import PluginScriptDirectory, migrate, prepare_db from indico.core.db.sqlalchemy.util.management import get_all_tables from indico.core.plugins import plugin_engine -from indico.util.console import cformat +from indico.vendor.colorclass import Color @cli_group() @@ -102,19 +102,19 @@ def reset_alembic(): def _safe_downgrade(*args, **kwargs): func = kwargs.pop('_func') - print(cformat('%{yellow!}*** DANGER')) - print(cformat('%{yellow!}***%{reset} ' - '%{red!}This operation may %{yellow!}PERMANENTLY ERASE %{red!}some data!%{reset}')) + print(Color('{b}{yellow}*** DANGER{reset}')) + print(Color('{b}{yellow}***{reset} ' + '{b}{red}This operation may {b}{yellow}PERMANENTLY ERASE {b}{red}some data!{reset}')) if current_app.debug: skip_confirm = os.environ.get('INDICO_ALWAYS_DOWNGRADE', '').lower() in ('1', 'yes') - print(cformat('%{yellow!}***%{reset} ' - "%{green!}Debug mode is active, so you probably won't destroy valuable data")) + print(Color('{b}{yellow}***{reset} ' + "{b}{green}Debug mode is active, so you probably won't destroy valuable data{reset}")) else: skip_confirm = False - print(cformat('%{yellow!}***%{reset} ' - '%{red!}Debug mode is NOT ACTIVE, so make sure you are on the right machine!')) - if not skip_confirm and input(cformat('%{yellow!}***%{reset} ' - 'To confirm this, enter %{yellow!}YES%{reset}: ')) != 'YES': + print(Color('{b}{yellow}***{reset} ' + '{b}{red}Debug mode is NOT ACTIVE, so make sure you are on the right machine!{reset}')) + if not skip_confirm and input(Color('{b}{yellow}***{reset} ' + 'To confirm this, enter {b}{yellow}YES{reset}: ')) != 'YES': click.secho('Aborted', fg='green') sys.exit(1) else: diff --git a/indico/cli/devserver.py b/indico/cli/devserver.py index 6988a429e11..d0fb30e9d78 100644 --- a/indico/cli/devserver.py +++ b/indico/cli/devserver.py @@ -37,8 +37,8 @@ def run_watchman(): try: Watchman().run() except pywatchman.WatchmanError as exc: - from indico.util.console import cformat - print(cformat('%{red!}watchman error: {}').format(exc)) + from indico.vendor.colorclass import Color + print(Color('{b}{red}watchman error: {}{reset}').format(exc)) def run_server(info, host, port, url, ssl, ssl_key, ssl_cert, quiet, proxy, enable_evalex, evalex_from, reloader_type): diff --git a/indico/cli/i18n.py b/indico/cli/i18n.py index 80736a9f3f5..f091fc95a26 100644 --- a/indico/cli/i18n.py +++ b/indico/cli/i18n.py @@ -20,7 +20,7 @@ from babel.messages.pofile import read_po from flask.helpers import get_root_path -from indico.util.console import cformat +from indico.vendor.colorclass import Color @click.group() @@ -181,7 +181,7 @@ def check_format_strings(): all_valid = False click.echo(f'Found invalid format strings in {os.path.relpath(path, root_path)}') for item in invalid: - click.echo(cformat('%{yellow}{}%{reset} | %{yellow!}{}%{reset}\n%{red}{}%{reset} != %{red!}{}%{reset}') + click.echo(Color('{yellow}{}{reset} | {b}{yellow}{}{reset}\n{red}{}{reset} != {b}{red}{}{reset}') .format(item['orig'], item['trans'], list(item['orig_placeholders']), list(item['trans_placeholders']))) click.echo()