From 6a064c9f9d2603f11a2b776533977c3353bc4a25 Mon Sep 17 00:00:00 2001 From: dbs Date: Fri, 13 Jun 2008 11:35:25 +0000 Subject: [PATCH] Add script for checking DTD entities and usage git-svn-id: svn://svn.open-ils.org/ILS/trunk@9823 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- build/i18n/tests/check_entities.py | 162 +++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 build/i18n/tests/check_entities.py diff --git a/build/i18n/tests/check_entities.py b/build/i18n/tests/check_entities.py new file mode 100644 index 0000000000..3355581a9f --- /dev/null +++ b/build/i18n/tests/check_entities.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python +# ----------------------------------------------------------------------- +# Copyright (C) 2008 Laurentian University +# Dan Scott +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# 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 General Public License for more details. +# ----------------------------------------------------------------------- + +# vim:et:sw=4:ts=4: set fileencoding=utf-8 : + +""" +Parse DTD files and XUL files looking for trouble + * Missing entities +""" + +import os +import re + +DEBUG = False + +DTD_DIRS = ( + '../../../Open-ILS/web/opac/locale/en-US/', + ) + +XUL_DIRS = ( + '../../../Open-ILS/xul/staff_client/server/', + '../../../Open-ILS/xul/staff_client/chrome/', + ) + +def parse_entities(): + """ + Parse entities files in known places + """ + + basedir = os.path.normpath(os.path.dirname(os.path.abspath(__file__))) + + entities = { + "amp" : "&", + "lt" : "<", + "gt" : ">", + "nbsp" : ">", + "quot" : ">", + } + + dtd_files = [] + + for p_dir in DTD_DIRS: + p_dir = os.path.normpath(os.path.join(basedir, p_dir)) + file_list = os.listdir(p_dir) + for d_file in file_list: + if os.path.splitext(d_file)[1] == '.dtd': + dtd_files.append(os.path.join(p_dir, d_file)) + + prefix = os.path.commonprefix(dtd_files) + + for d_file in dtd_files: + + # Get the shortest unique address for this file + short_df = d_file[len(prefix):] + + dtd_file = open(d_file, 'r') + + line_num = 1 + + for line in dtd_file: + line_num += 1 + + # Get rid of trailing linefeed + line = line[0:-1] + + # Parse entity/value + unpack = re.search(r'', line) + if DEBUG and unpack: + print unpack.groups() + + # Skip anything other than entity definitions + # Note that this makes some massive assumptions: + # 1. that we only have with one entity defined per line + # 2. that we only have single-line entities + # 3. that the entity begins in position 0 on the line + if not unpack or not line or not line.startswith('