From 29416875e00eb898065b81af3055b1d96c540fc2 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Thu, 15 Aug 2013 11:38:31 +0200 Subject: [PATCH] added scripts to cleanup spaces in XML files example for remove_trailing_whitespaces.sh: " testing \n" --> " testing\n" examples for remove_unnecessary_spaces.py: " foobar foobar" --> "foobar foobar" "foobar foobar " --> "foobar foobar" Change-Id: Ie15a7a1491bf412ff893c84e76061ef623581145 --- tools/cleanup/remove_trailing_whitespaces.sh | 13 +++++ tools/cleanup/remove_unnecessary_spaces.py | 56 ++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100755 tools/cleanup/remove_trailing_whitespaces.sh create mode 100755 tools/cleanup/remove_unnecessary_spaces.py diff --git a/tools/cleanup/remove_trailing_whitespaces.sh b/tools/cleanup/remove_trailing_whitespaces.sh new file mode 100755 index 0000000000..3d41284b16 --- /dev/null +++ b/tools/cleanup/remove_trailing_whitespaces.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +## copyright: B1 Systems GmbH , 2013. +## author: Christian Berendt , 2013. +## license: Apache License, Version 2.0 + +# Call ./tools/cleanup/remove_trailing_whitespaces.sh in the +# root of openstack-manuals. + +files=$(find doc/src/docbkx -name *.xml -not -name pom.xml) +for file in $files; do + sed -i -e 's/[[:space:]]*$//' $file +done diff --git a/tools/cleanup/remove_unnecessary_spaces.py b/tools/cleanup/remove_unnecessary_spaces.py new file mode 100755 index 0000000000..620dab08b1 --- /dev/null +++ b/tools/cleanup/remove_unnecessary_spaces.py @@ -0,0 +1,56 @@ +#!/usr/bin/python + +## copyright: B1 Systems GmbH , 2013. +## author: Christian Berendt , 2013. +## license: Apache License, Version 2.0 + +# Call ./tools/cleanup/remove_unnecessary_spaces.py in the +# root of openstack-manuals. + +import os +import re +import tempfile + +# should be the same like in tools/validate.py +FILE_EXCEPTIONS = ['ha-guide-docinfo.xml','bk001-ch003-associate-general.xml'] + +elements = [ + 'listitem', + 'para', + 'td', + 'th', + 'command', + 'literal', + 'title', + 'caption', + 'filename', + 'userinput', + 'programlisting' +] + +checks = [] +for element in elements: + checks.append(re.compile("(.*<%s>)\s+([\w\-().:!?{}\[\]]+.*\n)" % element)), + checks.append(re.compile("(.*[\w\-().:!?{}\[\]]+)\s+(<\/%s>.*\n)" % element)) + +for root, dirs, files in os.walk('doc/src/docbkx/'): + for f in files: + if (not (f.endswith('.xml') and + f != 'pom.xml' and + f not in FILE_EXCEPTIONS)): + continue + docfile = os.path.abspath(os.path.join(root, f)) + tmpfile = tempfile.mkstemp() + tmpfd = os.fdopen(tmpfile[0], "w") + match = False + for line in open(docfile, 'r'): + for check in checks: + if check.match(line): + line = check.sub(r"\1\2", line) + match = True + tmpfd.write(line) + tmpfd.close() + if match: + os.rename(tmpfile[1], docfile) + else: + os.unlink(tmpfile[1])