mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 17:56:17 +01: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:
parent
e2054240c2
commit
dcc1fe09d0
@ -24,6 +24,7 @@ import sys
|
|||||||
from . import config
|
from . import config
|
||||||
from . import utils
|
from . import utils
|
||||||
from . import dbustypes
|
from . import dbustypes
|
||||||
|
from .utils import print_error
|
||||||
|
|
||||||
LICENSE_STR = '''/*
|
LICENSE_STR = '''/*
|
||||||
* Generated by gdbus-codegen {!s}. DO NOT EDIT.
|
* Generated by gdbus-codegen {!s}. DO NOT EDIT.
|
||||||
@ -1156,7 +1157,7 @@ class CodeGenerator:
|
|||||||
elif p.writable:
|
elif p.writable:
|
||||||
hint = 'Since the D-Bus property for this #GObject property is writable but not readable, it is meaningful to write to it on both the client- and service-side. It is only meaningful, however, to read from it on the service-side.'
|
hint = 'Since the D-Bus property for this #GObject property is writable but not readable, it is meaningful to write to it on both the client- and service-side. It is only meaningful, however, to read from it on the service-side.'
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
|
print_error('Cannot handle property "{}" that neither readable nor writable'.format(p.name))
|
||||||
self.c.write(self.docbook_gen.expand(
|
self.c.write(self.docbook_gen.expand(
|
||||||
' /**\n'
|
' /**\n'
|
||||||
' * %s:%s:\n'
|
' * %s:%s:\n'
|
||||||
@ -1202,7 +1203,7 @@ class CodeGenerator:
|
|||||||
elif p.arg.signature == 'aay':
|
elif p.arg.signature == 'aay':
|
||||||
s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
|
s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Unsupported gtype %s for GParamSpec'%(p.arg.gtype))
|
print_error('Unsupported gtype "{}" for GParamSpec'.format(p.arg.gtype))
|
||||||
self.c.write(' %s, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));'%s);
|
self.c.write(' %s, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));'%s);
|
||||||
self.c.write('\n')
|
self.c.write('\n')
|
||||||
|
|
||||||
@ -1221,7 +1222,7 @@ class CodeGenerator:
|
|||||||
elif p.writable:
|
elif p.writable:
|
||||||
hint = 'Since this D-Bus property is not readable, it is only meaningful to use this function on the service-side.'
|
hint = 'Since this D-Bus property is not readable, it is only meaningful to use this function on the service-side.'
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
|
print_error('Cannot handle property "{}" that neither readable nor writable'.format(p.name))
|
||||||
self.c.write(self.docbook_gen.expand(
|
self.c.write(self.docbook_gen.expand(
|
||||||
'/**\n'
|
'/**\n'
|
||||||
' * %s_get_%s: (skip)\n'
|
' * %s_get_%s: (skip)\n'
|
||||||
@ -1277,7 +1278,7 @@ class CodeGenerator:
|
|||||||
elif p.writable:
|
elif p.writable:
|
||||||
hint = 'Since this D-Bus property is writable, it is meaningful to use this function on both the client- and service-side.'
|
hint = 'Since this D-Bus property is writable, it is meaningful to use this function on both the client- and service-side.'
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
|
print_error('Cannot handle property "{}" that neither readable nor writable'.format(p.name))
|
||||||
self.c.write(self.docbook_gen.expand(
|
self.c.write(self.docbook_gen.expand(
|
||||||
'/**\n'
|
'/**\n'
|
||||||
' * %s_set_%s: (skip)\n'
|
' * %s_set_%s: (skip)\n'
|
||||||
@ -3397,7 +3398,7 @@ class CodeGenerator:
|
|||||||
elif isinstance(obj, dbustypes.Property):
|
elif isinstance(obj, dbustypes.Property):
|
||||||
thing = 'The D-Bus property'
|
thing = 'The D-Bus property'
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Cannot handle object ', obj)
|
print_error('Cannot handle object "{}"'.format(obj))
|
||||||
f.write(self.docbook_gen.expand(
|
f.write(self.docbook_gen.expand(
|
||||||
'%*s *\n'
|
'%*s *\n'
|
||||||
'%*s * Deprecated: %s has been deprecated.\n'
|
'%*s * Deprecated: %s has been deprecated.\n'
|
||||||
|
@ -24,11 +24,11 @@ import optparse
|
|||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
from . import config
|
from . import config
|
||||||
from . import utils
|
|
||||||
from . import dbustypes
|
from . import dbustypes
|
||||||
from . import parser
|
from . import parser
|
||||||
from . import codegen
|
from . import codegen
|
||||||
from . import codegen_docbook
|
from . import codegen_docbook
|
||||||
|
from .utils import print_error
|
||||||
|
|
||||||
def find_arg(arg_list, arg_name):
|
def find_arg(arg_list, arg_name):
|
||||||
for a in arg_list:
|
for a in arg_list:
|
||||||
@ -62,38 +62,38 @@ def apply_annotation(iface_list, iface, method, signal, prop, arg, key, value):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if iface_obj == None:
|
if iface_obj == None:
|
||||||
raise RuntimeError('No interface %s'%iface)
|
print_error('No interface "{}"'.format(iface))
|
||||||
|
|
||||||
target_obj = None
|
target_obj = None
|
||||||
|
|
||||||
if method:
|
if method:
|
||||||
method_obj = find_method(iface_obj, method)
|
method_obj = find_method(iface_obj, method)
|
||||||
if method_obj == None:
|
if method_obj == None:
|
||||||
raise RuntimeError('No method %s on interface %s'%(method, iface))
|
print_error('No method "{}" on interface "{}"'.format(method, iface))
|
||||||
if arg:
|
if arg:
|
||||||
arg_obj = find_arg(method_obj.in_args, arg)
|
arg_obj = find_arg(method_obj.in_args, arg)
|
||||||
if (arg_obj == None):
|
if (arg_obj == None):
|
||||||
arg_obj = find_arg(method_obj.out_args, arg)
|
arg_obj = find_arg(method_obj.out_args, arg)
|
||||||
if (arg_obj == None):
|
if (arg_obj == None):
|
||||||
raise RuntimeError('No arg %s on method %s on interface %s'%(arg, method, iface))
|
print_error('No arg "{}" on method "{}" on interface "{}"'.format(arg, method, iface))
|
||||||
target_obj = arg_obj
|
target_obj = arg_obj
|
||||||
else:
|
else:
|
||||||
target_obj = method_obj
|
target_obj = method_obj
|
||||||
elif signal:
|
elif signal:
|
||||||
signal_obj = find_signal(iface_obj, signal)
|
signal_obj = find_signal(iface_obj, signal)
|
||||||
if signal_obj == None:
|
if signal_obj == None:
|
||||||
raise RuntimeError('No signal %s on interface %s'%(signal, iface))
|
print_error('No signal "{}" on interface "{}"'.format(signal, iface))
|
||||||
if arg:
|
if arg:
|
||||||
arg_obj = find_arg(signal_obj.args, arg)
|
arg_obj = find_arg(signal_obj.args, arg)
|
||||||
if (arg_obj == None):
|
if (arg_obj == None):
|
||||||
raise RuntimeError('No arg %s on signal %s on interface %s'%(arg, signal, iface))
|
print_error('No arg "{}" on signal "{}" on interface "{}"'.format(arg, signal, iface))
|
||||||
target_obj = arg_obj
|
target_obj = arg_obj
|
||||||
else:
|
else:
|
||||||
target_obj = signal_obj
|
target_obj = signal_obj
|
||||||
elif prop:
|
elif prop:
|
||||||
prop_obj = find_prop(iface_obj, prop)
|
prop_obj = find_prop(iface_obj, prop)
|
||||||
if prop_obj == None:
|
if prop_obj == None:
|
||||||
raise RuntimeError('No property %s on interface %s'%(prop, iface))
|
print_error('No property "{}" on interface "{}"'.format(prop, iface))
|
||||||
target_obj = prop_obj
|
target_obj = prop_obj
|
||||||
else:
|
else:
|
||||||
target_obj = iface_obj
|
target_obj = iface_obj
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
# Author: David Zeuthen <davidz@redhat.com>
|
# Author: David Zeuthen <davidz@redhat.com>
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
|
from .utils import print_error
|
||||||
|
|
||||||
class Annotation:
|
class Annotation:
|
||||||
def __init__(self, key, value):
|
def __init__(self, key, value):
|
||||||
@ -322,7 +323,7 @@ class Property:
|
|||||||
elif self.access == 'write':
|
elif self.access == 'write':
|
||||||
self.writable = True
|
self.writable = True
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Invalid access type %s'%self.access)
|
print_error('Invalid access type "{}"'.format(self.access))
|
||||||
self.doc_string = ''
|
self.doc_string = ''
|
||||||
self.since = ''
|
self.since = ''
|
||||||
self.deprecated = False
|
self.deprecated = False
|
||||||
@ -399,7 +400,7 @@ class Interface:
|
|||||||
self.name_lower = cns_lower + overridden_name.lower()
|
self.name_lower = cns_lower + overridden_name.lower()
|
||||||
self.name_upper = overridden_name.upper()
|
self.name_upper = overridden_name.upper()
|
||||||
|
|
||||||
#raise RuntimeError('handle Ugly_Case ', overridden_name)
|
#print_error('handle Ugly_Case "{}"'.format(overridden_name))
|
||||||
else:
|
else:
|
||||||
if overridden_name:
|
if overridden_name:
|
||||||
name = overridden_name
|
name = overridden_name
|
||||||
|
@ -23,6 +23,7 @@ import sys
|
|||||||
import xml.parsers.expat
|
import xml.parsers.expat
|
||||||
|
|
||||||
from . import dbustypes
|
from . import dbustypes
|
||||||
|
from .utils import print_error
|
||||||
|
|
||||||
class DBusXMLParser:
|
class DBusXMLParser:
|
||||||
STATE_TOP = 'top'
|
STATE_TOP = 'top'
|
||||||
@ -203,7 +204,7 @@ class DBusXMLParser:
|
|||||||
elif direction == 'out':
|
elif direction == 'out':
|
||||||
self._cur_object.out_args.append(arg)
|
self._cur_object.out_args.append(arg)
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Invalid direction "%s"'%(direction))
|
print_error('Invalid direction "{}"'.format(direction))
|
||||||
self._cur_object = arg
|
self._cur_object = arg
|
||||||
elif name == DBusXMLParser.STATE_ANNOTATION:
|
elif name == DBusXMLParser.STATE_ANNOTATION:
|
||||||
self.state = DBusXMLParser.STATE_ANNOTATION
|
self.state = DBusXMLParser.STATE_ANNOTATION
|
||||||
@ -278,7 +279,7 @@ class DBusXMLParser:
|
|||||||
self.state = DBusXMLParser.STATE_IGNORED
|
self.state = DBusXMLParser.STATE_IGNORED
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Unhandled state "%s" while entering element with name "%s"'%(self.state, name))
|
print_error('Unhandled state "{}" while entering element with name "{}"'.format(self.state, name))
|
||||||
|
|
||||||
self.state_stack.append(old_state)
|
self.state_stack.append(old_state)
|
||||||
self._cur_object_stack.append(old_cur_object)
|
self._cur_object_stack.append(old_cur_object)
|
||||||
|
@ -20,6 +20,46 @@
|
|||||||
# Author: David Zeuthen <davidz@redhat.com>
|
# Author: David Zeuthen <davidz@redhat.com>
|
||||||
|
|
||||||
import distutils.version
|
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):
|
def strip_dots(s):
|
||||||
ret = ''
|
ret = ''
|
||||||
|
Loading…
Reference in New Issue
Block a user