Use scripts.utils for colors in scripts.

This commit is contained in:
Florian Bruhin 2014-09-22 20:29:37 +02:00
parent e26606b0d6
commit a7c1f38344
3 changed files with 22 additions and 26 deletions

View File

@ -43,13 +43,14 @@ import functools
import contextlib
import traceback
import colorama as col
import pep257
import pkg_resources as pkg
sys.path.insert(0, os.getcwd())
from scripts import utils
# We need to do this because pyroma is braindead enough to use logging instead
# of print...
@ -159,7 +160,7 @@ def check_git():
untracked.append(name)
if untracked:
status = False
print("{}Untracked files:{}".format(col.Fore.RED, col.Fore.RESET))
utils.print_col("Untracked files:", 'red')
print('\n'.join(untracked))
else:
status = True
@ -277,7 +278,6 @@ def _checker_enabled(args, group, name):
def main():
"""Main entry point."""
col.init()
exit_status = collections.OrderedDict()
exit_status_bool = {}
parser = argparse.ArgumentParser(description='Run various checkers.')
@ -295,11 +295,10 @@ def main():
for group in groups:
print()
print("{}==================== {} ===================={}".format(
col.Fore.YELLOW, group, col.Fore.RESET))
utils.print_col("==================== {} ====================".format(
group), 'yellow')
for name, func in checkers[group].items():
print("{}------ {} ------{}".format(col.Fore.CYAN, name,
col.Fore.RESET))
utils.print_col("------ {} ------".format(name), 'cyan')
if _checker_enabled(args, group, name):
status = func()
key = '{}_{}'.format(group, name)
@ -314,15 +313,14 @@ def main():
# means problems.
exit_status_bool[key] = (status == 0)
else:
print("{}Checker disabled.{}".format(
col.Fore.BLUE, col.Fore.RESET))
utils.print_col("Checker disabled.", 'blue')
print()
print("{}Exit status values:{}".format(col.Fore.YELLOW, col.Fore.RESET))
utils.print_col("Exit status values:", 'yellow')
for (k, v) in exit_status.items():
ok = exit_status_bool[k]
color = col.Fore.GREEN if ok else col.Fore.RED
print('{} {} - {} ({}){}'.format(color, k, 'ok' if ok else 'FAIL',
v, col.Fore.RESET))
color = 'green' if ok else 'red'
utils.print_col(
' {} - {} ({})'.format(k, 'ok' if ok else 'FAIL', v), color)
if all(exit_status_bool):
return 0

View File

@ -25,7 +25,9 @@ import signal
import sys
import subprocess
import colorama as col
sys.path.insert(0, os.getcwd())
from scripts import utils
SCRIPT = """
@ -53,11 +55,11 @@ app.exec_()
def print_ret(ret):
"""Print information about an exit status."""
if ret == 0:
print("{}success{}".format(col.Fore.GREEN, col.Fore.RESET))
utils.print_col("success", 'green')
elif ret == -signal.SIGSEGV:
print("{}segfault{}".format(col.Fore.RED, col.Fore.RESET))
utils.print_col("segfault", 'red')
else:
print("{}error {}{}".format(col.Fore.YELLOW, ret, col.Fore.RESET))
utils.print_col("error {}".format(ret), 'yellow')
print()
@ -86,8 +88,7 @@ def main():
else:
pages = [(e, True) for e in sys.argv[1:]]
for page, test_harfbuzz in pages:
print("{}==== {} ===={}".format(col.Style.BRIGHT, page,
col.Style.NORMAL))
utils.print_bold("==== {} ====".format(page))
if test_harfbuzz:
print("With system harfbuzz:")
ret = subprocess.call([sys.executable, '-c', SCRIPT, page])

View File

@ -31,17 +31,15 @@ import collections
import tempfile
import argparse
import colorama as col
sys.path.insert(0, os.getcwd())
# We import qutebrowser.app so all @cmdutils-register decorators are run.
import qutebrowser.app
from scripts import asciidoc2html
from scripts import asciidoc2html, utils
from qutebrowser import qutebrowser
from qutebrowser.commands import cmdutils
from qutebrowser.config import configdata
from qutebrowser.utils import utils
from qutebrowser.utils import utils as quteutils
class UsageFormatter(argparse.HelpFormatter):
@ -153,7 +151,7 @@ def _get_command_doc(name, cmd):
if syntax != name:
output.append('Syntax: +:{}+'.format(syntax))
output.append("")
parser = utils.DocstringParser(cmd.handler)
parser = quteutils.DocstringParser(cmd.handler)
output.append(parser.short_desc)
if parser.long_desc:
output.append("")
@ -397,8 +395,7 @@ def regenerate_manpage(filename):
def main():
"""Regenerate all documentation."""
print("{}Generating asciidoc files...{}".format(
col.Fore.CYAN, col.Fore.RESET))
utils.print_col("Generating asciidoc files...", 'cyan')
regenerate_manpage('doc/qutebrowser.1.asciidoc')
generate_settings('doc/help/settings.asciidoc')
generate_commands('doc/help/commands.asciidoc')