From 82c76849e35d38ccff553fb57c2e47ba19f81b2b Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Thu, 15 Aug 2013 10:22:58 +0200 Subject: [PATCH] take care of books with sources in subdirectories At the moment the validation doesn't take care of books where the pom.xml is in an other directory than the sources of the book. This patch will fix this issue. For example: the pom.xml of basic-install is available at doc/src/docbkx/basic-install/pom.xml but the sources of the books are in doc/src/docbkx/basic-install/src. Because the path to the pom.xml differs from the path of the sources the validation will not check the files in the sources directory for xi:include elements. Change-Id: I3b92c3c4bff46ba6f9ac53b3ec56d24e7caf6ff6 --- validate.py | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/validate.py b/validate.py index c8c3c868..96bcf861 100755 --- a/validate.py +++ b/validate.py @@ -226,27 +226,32 @@ def build_affected_books(rootdir, book_exceptions, file_exceptions): modified_files = get_modified_files() affected_books = [] books = [] + book_root = rootdir for root, dirs, files in os.walk(rootdir): - if ("pom.xml" in files and - os.path.basename(root) not in book_exceptions): + if os.path.basename(root) in book_exceptions: + break + elif "pom.xml" in files: books.append(root) - os.chdir(root) - for f in files: - if (f.endswith('.xml') and - f != 'pom.xml' and - f not in file_exceptions): - path = os.path.abspath(os.path.join(root, f)) - doc = etree.parse(path) - ns = {"xi": "http://www.w3.org/2001/XInclude"} - for node in doc.xpath('//xi:include', namespaces=ns): - href = node.get('href') - if (href.endswith('.xml') and - f not in file_exceptions and - os.path.abspath(href) in modified_files): - affected_books.append(root) - break - if root in affected_books: - break + book_root = root + + os.chdir(root) + + for f in files: + if (f.endswith('.xml') and + f != 'pom.xml' and + f not in file_exceptions): + path = os.path.abspath(os.path.join(root, f)) + doc = etree.parse(path) + ns = {"xi": "http://www.w3.org/2001/XInclude"} + for node in doc.xpath('//xi:include', namespaces=ns): + href = node.get('href') + if (href.endswith('.xml') and + f not in file_exceptions and + os.path.abspath(href) in modified_files): + affected_books.append(book_root) + break + if book_root in affected_books: + break if affected_books: books = affected_books