Commit 06a460b3 authored by Christoph Reiter's avatar Christoph Reiter 🐍

message: simplify handling of error levels

Instead of allowing each error level to be enabled just enable all of them
through the enable_warnings() method. This matches what the code is currently
doing (minus that one helper script) and simplifies things.

Also remove the error count, it's not used.
parent 9826d952
......@@ -95,9 +95,8 @@ class MessageLogger(object):
self._cwd = os.getcwd()
self._output = output
self._namespace = namespace
self._enable_warnings = []
self._enable_warnings = False
self._warning_count = 0
self._error_count = 0
@classmethod
def get(cls, *args, **kwargs):
......@@ -105,15 +104,12 @@ class MessageLogger(object):
cls._instance = cls(*args, **kwargs)
return cls._instance
def enable_warnings(self, log_types):
self._enable_warnings = log_types
def enable_warnings(self, value):
self._enable_warnings = bool(value)
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, marker_pos=None, marker_line=None):
"""
Log a warning, using optional file positioning information.
......@@ -123,7 +119,7 @@ class MessageLogger(object):
self._warning_count += 1
if log_type not in self._enable_warnings:
if not self._enable_warnings:
return
if type(positions) == set:
......@@ -142,7 +138,6 @@ class MessageLogger(object):
error_type = "Warning"
elif log_type == ERROR:
error_type = "Error"
self._error_count += 1
elif log_type == FATAL:
error_type = "Fatal"
......
......@@ -550,7 +550,7 @@ def scanner_main(args):
namespace = create_namespace(options)
logger = message.MessageLogger.get(namespace=namespace)
if options.warn_all:
logger.enable_warnings((message.WARNING, message.ERROR, message.FATAL))
logger.enable_warnings(True)
transformer = create_transformer(namespace, options)
......
......@@ -189,7 +189,7 @@ if __name__ == '__main__':
logger = MessageLogger.get(namespace=None)
parser = GtkDocCommentBlockParser()
writer = GtkDocCommentBlockWriter(indent=True)
logger.enable_warnings((ERROR, FATAL))
logger.enable_warnings(True)
with io.open(path, 'r') as f:
lines = f.readlines()
......
......@@ -33,7 +33,7 @@ import xml.etree.ElementTree as etree
from giscanner.annotationparser import GtkDocCommentBlockParser, GtkDocCommentBlockWriter
from giscanner.ast import Namespace
from giscanner.message import MessageLogger, WARNING, ERROR, FATAL
from giscanner.message import MessageLogger
XML_NS = 'http://schemas.gnome.org/gobject-introspection/2013/test'
......@@ -410,7 +410,7 @@ def create_test_cases():
# Initialize message logger
namespace = Namespace('Test', '1.0')
logger = MessageLogger.get(namespace=namespace)
logger.enable_warnings((WARNING, ERROR, FATAL))
logger.enable_warnings(True)
test_cases = {}
# Load test cases from disc
......
......@@ -10,7 +10,7 @@ os.environ['GI_SCANNER_DISABLE_CACHE'] = '1'
from giscanner import ast
from giscanner.sourcescanner import SourceScanner
from giscanner.transformer import Transformer
from giscanner.message import MessageLogger, WARNING, ERROR, FATAL
from giscanner.message import MessageLogger
def create_scanner_from_source_string(source):
......@@ -85,7 +85,7 @@ class TestStructTypedefs(unittest.TestCase):
# Hack to set logging singleton
self.namespace = ast.Namespace('Test', '1.0')
logger = MessageLogger.get(namespace=self.namespace)
logger.enable_warnings((WARNING, ERROR, FATAL))
logger.enable_warnings(True)
def test_anonymous_typedef(self):
load_namespace_from_source_string(self.namespace, """
......@@ -280,7 +280,7 @@ class TestNestedStructs(unittest.TestCase):
# Hack to set logging singleton
self.namespace = ast.Namespace('Test', '1.0')
logger = MessageLogger.get(namespace=self.namespace)
logger.enable_warnings((WARNING, ERROR, FATAL))
logger.enable_warnings(True)
def test_nested_named(self):
load_namespace_from_source_string(self.namespace, """
......@@ -387,7 +387,7 @@ class TestUnions(unittest.TestCase):
# Hack to set logging singleton
self.namespace = ast.Namespace('Test', '1.0')
logger = MessageLogger.get(namespace=self.namespace)
logger.enable_warnings((WARNING, ERROR, FATAL))
logger.enable_warnings(True)
def test_union_with_struct(self):
load_namespace_from_source_string(self.namespace, """
......@@ -472,7 +472,7 @@ class TestCallbacks(unittest.TestCase):
# Hack to set logging singleton
self.namespace = ast.Namespace('Test', '1.0')
logger = MessageLogger.get(namespace=self.namespace)
logger.enable_warnings((WARNING, ERROR, FATAL))
logger.enable_warnings(True)
def test_union_with_struct(self):
load_namespace_from_source_string(self.namespace, """
......@@ -488,7 +488,7 @@ class TestArrays(unittest.TestCase):
# Hack to set logging singleton
self.namespace = ast.Namespace('Test', '1.0')
logger = MessageLogger.get(namespace=self.namespace)
logger.enable_warnings((WARNING, ERROR, FATAL))
logger.enable_warnings(True)
def test_multidimensional_arrays(self):
"""Multidimensional arrays are flattend into a single dimension."""
......
......@@ -15,7 +15,7 @@ from giscanner.annotationparser import GtkDocCommentBlockParser
from giscanner.ast import Include, Namespace
from giscanner.introspectablepass import IntrospectablePass
from giscanner.maintransformer import MainTransformer
from giscanner.message import MessageLogger, WARNING, ERROR, FATAL
from giscanner.message import MessageLogger
from giscanner.sourcescanner import SourceScanner
from giscanner.transformer import Transformer
from giscanner.scannermain import process_packages
......@@ -98,7 +98,7 @@ def check(args):
output = ChunkedIO()
namespace = Namespace('Test', '1.0')
logger = MessageLogger.get(namespace=namespace, output=output)
logger.enable_warnings((WARNING, ERROR, FATAL))
logger.enable_warnings(True)
transformer = Transformer(namespace)
transformer.set_include_paths([
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment