diff options
author | Dieter Verfaillie <dieterv@optionexplicit.be> | 2013-07-24 16:56:20 +0200 |
---|---|---|
committer | Dieter Verfaillie <dieterv@optionexplicit.be> | 2013-10-08 20:55:05 +0200 |
commit | 6d9022311b5d3bfb48895466880c2a15235b63a6 (patch) | |
tree | 5cf1c16e44b0fce7e74e4002b2585b54ca636679 /giscanner/message.py | |
parent | db34cca45f4a726e20f2452615068fe1e04bc428 (diff) | |
download | gobject-introspection-6d9022311b5d3bfb48895466880c2a15235b63a6.tar.gz |
giscanner: give message.ERROR a purpose
It's not yet being used but will be in the future by
annotationparser.py to signal the difference between
message.WARNING:
something is wrong but the comment block can still
be parsed and serialized back into a comment block
without information being lost
message.ERROR:
something is wrong and the comment block can *not*
be parsed and serialized back into a comment block
without information being lost
Different tools can then act accordingly. Nothing will
change for g-ir-scanner but this will be important for
the GTK-Doc comment block rewriting tool to prevent
extremely broken input leading to even more broken
output...
Diffstat (limited to 'giscanner/message.py')
-rw-r--r-- | giscanner/message.py | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/giscanner/message.py b/giscanner/message.py index 58908352..1a0a6c52 100644 --- a/giscanner/message.py +++ b/giscanner/message.py @@ -31,7 +31,8 @@ from . import utils class Position(object): - """Represents a position in the source file which we + """ + Represents a position in the source file which we want to inform about. """ @@ -47,10 +48,8 @@ class Position(object): (other.filename, other.line, other.column)) def __repr__(self): - return '<Position %s:%d:%d>' % ( - os.path.basename(self.filename), - self.line or -1, - self.column or -1) + return '<Position %s:%d:%d>' % (os.path.basename(self.filename), self.line or -1, + self.column or -1) def format(self, cwd): filename = os.path.realpath(self.filename) @@ -76,8 +75,9 @@ class MessageLogger(object): self._cwd = os.getcwd() self._output = output self._namespace = namespace - self._enable_warnings = False + self._enable_warnings = [] self._warning_count = 0 + self._error_count = 0 @classmethod def get(cls, *args, **kwargs): @@ -85,24 +85,27 @@ class MessageLogger(object): cls._instance = cls(*args, **kwargs) return cls._instance - def enable_warnings(self, enable): - self._enable_warnings = enable + def enable_warnings(self, log_types): + self._enable_warnings = log_types def get_warning_count(self): return self._warning_count + def get_error_count(self): + return self._error_count + def log(self, log_type, text, positions=None, prefix=None): - """Log a warning, using optional file positioning information. -If the warning is related to a ast.Node type, see log_node().""" + """ + Log a warning, using optional file positioning information. + If the warning is related to a ast.Node type, see log_node(). + """ utils.break_on_debug_flag('warning') self._warning_count += 1 - if not self._enable_warnings and log_type != FATAL: + if not log_type in self._enable_warnings: return - # Always drop through on fatal - if type(positions) == set: positions = list(positions) if isinstance(positions, Position): @@ -119,8 +122,10 @@ If the warning is related to a ast.Node type, see log_node().""" error_type = "Warning" elif log_type == ERROR: error_type = "Error" + self._error_count += 1 elif log_type == FATAL: error_type = "Fatal" + if prefix: text = ('%s: %s: %s: %s: %s\n' % (last_position, error_type, self._namespace.name, prefix, text)) @@ -132,16 +137,19 @@ If the warning is related to a ast.Node type, see log_node().""" text = ('%s: %s: %s\n' % (last_position, error_type, text)) self._output.write(text) + if log_type == FATAL: utils.break_on_debug_flag('fatal') raise SystemExit(text) def log_node(self, log_type, node, text, context=None, positions=None): - """Log a warning, using information about file positions from -the given node. The optional context argument, if given, should be -another ast.Node type which will also be displayed. If no file position -information is available from the node, the position data from the -context will be used.""" + """ + Log a warning, using information about file positions from + the given node. The optional context argument, if given, should be + another ast.Node type which will also be displayed. If no file position + information is available from the node, the position data from the + context will be used. + """ if positions: pass elif getattr(node, 'file_positions', None): @@ -185,6 +193,11 @@ def warn_symbol(symbol, text): ml.log_symbol(WARNING, symbol, text) +def error(text, positions=None, prefix=None): + ml = MessageLogger.get() + ml.log(ERROR, text, positions, prefix) + + def fatal(text, positions=None, prefix=None): ml = MessageLogger.get() ml.log(FATAL, text, positions, prefix) |