---
tests/Makefile.am | 5 +-
tests/glade/validity/check_glade_validity.py | 75 ++++++++++++++++++++++++
tests/glade/validity/run_check_glade_validity.sh | 10 ++++
3 files changed, 89 insertions(+), 1 deletion(-)
create mode 100755 tests/glade/validity/check_glade_validity.py
create mode 100755 tests/glade/validity/run_check_glade_validity.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3d7f22d..5e7f31d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -40,6 +40,8 @@ dist_check_SCRIPTS = glade/accelerators/check_accelerators.py \
glade/accelerators/run_check_accelerators.sh \
glade/pw_visibility/check_pw_visibility.py \
glade/pw_visibility/run_check_pw_visibility.sh \
+ glade/validity/check_glade_validity.py \
+ glade/validity/run_check_glade_validity.sh \
nosetests.sh \
pylint/intl.py \
pylint/preconf.py \
@@ -58,7 +60,8 @@ TESTS = nosetests.sh \
gettext/gettext_potfiles.py \
storage/run_storage_tests.py \
glade/accelerators/run_check_accelerators.sh \
- glade/pw_visibility/run_check_pw_visibility.sh
+ glade/pw_visibility/run_check_pw_visibility.sh \
+ glade/validity/run_check_glade_validity.sh
clean-local:
-rm -rf pylint/.pylint.d
diff --git a/tests/glade/validity/check_glade_validity.py
b/tests/glade/validity/check_glade_validity.py
new file mode 100755
index 0000000..9f3695d
--- /dev/null
+++ b/tests/glade/validity/check_glade_validity.py
@@ -0,0 +1,75 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <
http://www.gnu.org/licenses/>.
+#
+# Author: David Shea <dshea(a)redhat.com>
+
+import sys
+
+from collections import Counter
+
+try:
+ from lxml import etree
+except ImportError:
+ print("You need to install the python-lxml package to run the glade
checks")
+ sys.exit(99)
+
+success = True
+
+def main(argv):
+ global success
+
+ for glade_file in argv:
+ # Parse the glade file to ensure it's well-formed
+ try:
+ glade_tree = etree.parse(glade_file)
+ except etree.XMLSyntaxError:
+ print("%s is not a valid XML file" % glade_file)
+ success = False
+ continue
+
+ # Check for duplicate IDs
+ # Build a Counter from a list of all ids, extracts the ones with count > 1
+ # Fun fact: glade uses <col id="<number>"> in GtkListStore
data, so ids
+ # aren't actually unique and getting an object with a particular ID
+ # isn't as simple as document.getElementById. Only check the IDs on objects.
+ for glade_id in [c for c in
Counter(glade_tree.xpath(".//object/(a)id")).most_common() \
+ if c[1] > 1]:
+ print("%s: ID %s appears %d times" % (glade_file, glade_id[0],
glade_id[1]))
+ success = False
+
+ # Check for ID references
+ # mnemonic_widget properties and action-widget elements need to refer to
+ # valid object ids.
+ for mnemonic_widget in
glade_tree.xpath(".//property[@name='mnemonic_widget']"):
+ if not glade_tree.xpath(".//object[@id='%s']" %
mnemonic_widget.text):
+ print("mnemonic_widget reference to invalid ID %s at line %d of
%s" % \
+ (mnemonic_widget.text, mnemonic_widget.sourceline, glade_file))
+ success = False
+
+ for action_widget in glade_tree.xpath(".//action-widget"):
+ if not glade_tree.xpath(".//object[@id='%s']" %
action_widget.text):
+ print("action-widget reference to invalid ID %s at line %d of
%s" % \
+ (action_widget.text, action_widget.sourceline, glade_file))
+ success = False
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
+ if success:
+ sys.exit(0)
+ else:
+ sys.exit(1)
diff --git a/tests/glade/validity/run_check_glade_validity.sh
b/tests/glade/validity/run_check_glade_validity.sh
new file mode 100755
index 0000000..a6e6fe1
--- /dev/null
+++ b/tests/glade/validity/run_check_glade_validity.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+if [ -z "$top_srcdir" ]; then
+ top_srcdir="$(dirname "$0")/../../.."
+ . "${top_srcdir}/tests/testenv.sh"
+fi
+
+srcdir="${top_srcdir}/tests/glade/validity"
+
+find "${top_srcdir}" -name '*.glade' -exec
"${srcdir}/check_glade_validity.py" "$@" {} +
--
1.8.5.2