[PATCH 3/6] Check that the Pango markup in glade files is valid

Vratislav Podzimek vpodzime at redhat.com
Fri Jan 10 08:09:11 UTC 2014


On Thu, 2014-01-09 at 13:31 -0500, David Shea wrote:
> When run with --translate, the script will also check the translations
> of markup strings.
> ---
>  tests/Makefile.am                      |   5 +-
>  tests/glade/markup/check_markup.py     | 125 +++++++++++++++++++++++++++++++++
>  tests/glade/markup/run_check_markup.sh |  21 ++++++
>  3 files changed, 150 insertions(+), 1 deletion(-)
>  create mode 100755 tests/glade/markup/check_markup.py
>  create mode 100755 tests/glade/markup/run_check_markup.sh
> 
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index cfebc7c..d67bf13 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -43,6 +43,8 @@ dist_check_SCRIPTS = glade/accelerators/check_accelerators.py \
>  		     glade/validity/check_glade_validity.py \
>  		     glade/validity/run_check_glade_validity.sh \
>  		     $(srcdir)/lib/*.py \
> +		     glade/markup/check_markup.py \
> +		     glade/markup/run_check_markup.sh \
>  		     nosetests.sh \
>  		     pylint/intl.py \
>  		     pylint/preconf.py \
> @@ -63,7 +65,8 @@ TESTS = nosetests.sh \
>  	storage/run_storage_tests.py \
>  	glade/accelerators/run_check_accelerators.sh \
>  	glade/pw_visibility/run_check_pw_visibility.sh \
> -	glade/validity/run_check_glade_validity.sh
> +	glade/validity/run_check_glade_validity.sh \
> +	glade/markup/run_check_markup.sh
>  
>  clean-local:
>  	-rm -rf pylint/.pylint.d
> diff --git a/tests/glade/markup/check_markup.py b/tests/glade/markup/check_markup.py
> new file mode 100755
> index 0000000..2778a7e
> --- /dev/null
> +++ b/tests/glade/markup/check_markup.py
> @@ -0,0 +1,125 @@
> +#!/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 at redhat.com>
> +#
> +
> +"""
> +Python script to check that properties in glade using Pango markup contain
> +valid markup.
> +"""
> +
> +import sys
> +import argparse
> +
> +# Import translation methods if needed
> +if ('-t' in sys.argv) or ('--translate' in sys.argv):
> +    try:
> +        from translatepo import translate_all
> +    except ImportError:
> +        print("Unable to load po translation module")
> +        sys.exit(99)
> +
> +from pangocheck import markup_nodes, markup_match
> +
> +try:
> +    from lxml import etree
> +except ImportError:
> +    print("You need to install the python-lxml package to use check_markup.py")
> +    sys.exit(99)
> +
> +class PangoElementException(Exception):
> +    def __init__(self, element):
> +        Exception.__init__(self)
> +        self.element = element
> +
> +    def __str__(self):
> +        return "Invalid element %s" % self.element
> +
> +# Raises a PangoElementException if the pango markup contains unknown elements
> +def _validate_pango_markup(root):
Could be a docstring.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list