summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2010-06-17 17:40:26 -0400
committerColin Walters <walters@verbum.org>2010-06-17 17:40:26 -0400
commitd7fd695c29a72b1d9dc10427a675e7804b9858be (patch)
treea855f0698d7d12f2ee9c98d97f8c53bf31909b27
parent5a4fa2bf5648d60d9fc0feb69080c9153b2abe02 (diff)
downloadgobject-introspection-d7fd695c29a72b1d9dc10427a675e7804b9858be.tar.gz
Better error message for incompatible versions
-rw-r--r--giscanner/girparser.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index 57db0fb6..9d46d2ad 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -18,6 +18,8 @@
# Boston, MA 02111-1307, USA.
#
+import os
+
from xml.etree.cElementTree import parse
from .ast import (Alias, Array, Callback, Constant, Enum, Function, Field,
@@ -54,12 +56,16 @@ class GIRParser(object):
self._includes = set()
self._pkgconfig_packages = set()
self._namespace = None
+ self._filename_stack = []
# Public API
def parse(self, filename):
+ filename = os.path.abspath(filename)
+ self._filename_stack.append(filename)
tree = parse(filename)
self.parse_tree(tree)
+ self._filename_stack.pop()
def parse_tree(self, tree):
self._includes.clear()
@@ -90,6 +96,15 @@ class GIRParser(object):
# Private
+ def _get_current_file(self):
+ if not self._filename_stack:
+ return None
+ cwd = os.getcwd() + os.sep
+ curfile = self._filename_stack[-1]
+ if curfile.startswith(cwd):
+ return curfile[len(cwd):]
+ return curfile
+
def _add_node(self, node):
self._namespace.nodes.append(node)
@@ -97,8 +112,9 @@ class GIRParser(object):
assert root.tag == _corens('repository')
version = root.attrib['version']
if version != COMPATIBLE_GIR_VERSION:
- raise ValueError("Incompatible version %s (supported: %s)",
- version, COMPATIBLE_GIR_VERSION)
+ raise SystemExit("%s: Incompatible version %s (supported: %s)" \
+ % (self._get_current_file(),
+ version, COMPATIBLE_GIR_VERSION))
for node in root.getchildren():
if node.tag == _corens('include'):