mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-24 19:07:52 +02:00
gdbus-codegen: Use Color's print_* methods
`glib-genmarshal` and `glib-mkenums` use a `Color` class which implements a number of print_* methods to print colored messages to the standard error output. In order to be consistent with those programs' output, `gdbus-codegen` has also started using that same class and methods. https://bugzilla.gnome.org/show_bug.cgi?id=791015
This commit is contained in:
@@ -20,6 +20,46 @@
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import distutils.version
|
||||
import os
|
||||
import sys
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class Color:
|
||||
'''ANSI Terminal colors'''
|
||||
GREEN = '\033[1;32m'
|
||||
BLUE = '\033[1;34m'
|
||||
YELLOW = '\033[1;33m'
|
||||
RED = '\033[1;31m'
|
||||
END = '\033[0m'
|
||||
|
||||
def print_color(msg, color=Color.END, prefix='MESSAGE'):
|
||||
'''Print a string with a color prefix'''
|
||||
if os.isatty(sys.stderr.fileno()):
|
||||
real_prefix = '{start}{prefix}{end}'.format(start=color, prefix=prefix, end=Color.END)
|
||||
else:
|
||||
real_prefix = prefix
|
||||
sys.stderr.write('{prefix}: {msg}\n'.format(prefix=real_prefix, msg=msg))
|
||||
|
||||
def print_error(msg):
|
||||
'''Print an error, and terminate'''
|
||||
print_color(msg, color=Color.RED, prefix='ERROR')
|
||||
sys.exit(1)
|
||||
|
||||
def print_warning(msg, fatal=False):
|
||||
'''Print a warning, and optionally terminate'''
|
||||
if fatal:
|
||||
color = Color.RED
|
||||
prefix = 'ERROR'
|
||||
else:
|
||||
color = Color.YELLOW
|
||||
prefix = 'WARNING'
|
||||
print_color(msg, color, prefix)
|
||||
if fatal:
|
||||
sys.exit(1)
|
||||
|
||||
def print_info(msg):
|
||||
'''Print a message'''
|
||||
print_color(msg, color=Color.GREEN, prefix='INFO')
|
||||
|
||||
def strip_dots(s):
|
||||
ret = ''
|
||||
|
Reference in New Issue
Block a user