Merge "Improve checking for modified files"

This commit is contained in:
Jenkins 2013-09-30 15:17:38 +00:00 committed by Gerrit Code Review
commit 1c26b1d4d0
2 changed files with 82 additions and 50 deletions

66
test.py
View File

@ -415,36 +415,50 @@ def build_affected_books(rootdir, book_exceptions, file_exceptions,
os.chdir(root) os.chdir(root)
for f in files: # We can scan only for depth of one of inclusion
if (f.endswith('.xml') and # therefore skip the common directory since there's no
f != 'pom.xml' and # book build in it.
f not in file_exceptions): if not root.endswith('doc/common'):
path = os.path.abspath(os.path.join(root, f)) for f in files:
doc = etree.parse(path) if (f.endswith('.xml') and
f != 'pom.xml' and
# Check for inclusion of files as part of imagedata f not in file_exceptions):
for node in doc.findall( path = os.path.abspath(os.path.join(root, f))
'//{http://docbook.org/ns/docbook}imagedata'): # If the file itself is modified, build the book
href = node.get('fileref') if path in modified_files:
if (f not in file_exceptions and
os.path.abspath(href) in modified_files):
affected_books.append(book_root) affected_books.append(book_root)
break break
# If the file itself is modified, build the book.
# Note this is an optimization in most cases but
# needed for bk-*.xml since those are included by
# pom.xml and pom.xml is not checked for
# modification of included files.
doc = etree.parse(path)
# Check for inclusion of files as part of imagedata
for node in doc.findall(
'//{http://docbook.org/ns/docbook}imagedata'):
href = node.get('fileref')
if (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
# Check for inclusion of files as part of xi:include
ns = {"xi": "http://www.w3.org/2001/XInclude"}
for node in doc.xpath('//xi:include', namespaces=ns):
href = node.get('href')
if (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: if book_root in affected_books:
break break
# Check for inclusion of files as part of xi:include
ns = {"xi": "http://www.w3.org/2001/XInclude"}
for node in doc.xpath('//xi:include', namespaces=ns):
href = node.get('href')
if (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 not force and affected_books: if not force and affected_books:
books = affected_books books = affected_books
else: else:
@ -478,7 +492,7 @@ def build_affected_books(rootdir, book_exceptions, file_exceptions,
if voting and any_failures: if voting and any_failures:
sys.exit(1) sys.exit(1)
print("Building finished.")
def main(args): def main(args):

View File

@ -407,36 +407,53 @@ def build_affected_books(rootdir, book_exceptions, file_exceptions, force):
os.chdir(root) os.chdir(root)
for f in files: # We can scan only for depth of one of inclusion
if (f.endswith('.xml') and # therefore skip the common directory since there's no
f != 'pom.xml' and # book build in it.
f not in file_exceptions): if not root.endswith('doc/common'):
path = os.path.abspath(os.path.join(root, f)) for f in files:
doc = etree.parse(path) if (f.endswith('.xml') and
f != 'pom.xml' and
f not in file_exceptions):
path = os.path.abspath(os.path.join(root, f))
# Check for inclusion of files as part of imagedata # If the file itself is modified, build the book.
for node in doc.findall( # Note this is an optimization in most cases but
'//{http://docbook.org/ns/docbook}imagedata'): # needed for bk-*.xml since those are included by
href = node.get('fileref') # pom.xml and pom.xml is not checked for
if (f not in file_exceptions and # modification of included files.
os.path.abspath(href) in modified_files): if path in modified_files:
affected_books.append(book_root) affected_books.append(book_root)
break break
# Now check whether the file includes a file that
# was modified (scanning one level only)
doc = etree.parse(path)
# Check for inclusion of files as part of imagedata
for node in doc.findall(
'//{http://docbook.org/ns/docbook}imagedata'):
href = node.get('fileref')
if (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
# Check for inclusion of files as part of xi:include
ns = {"xi": "http://www.w3.org/2001/XInclude"}
for node in doc.xpath('//xi:include', namespaces=ns):
href = node.get('href')
if (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: if book_root in affected_books:
break break
# Check for inclusion of files as part of xi:include
ns = {"xi": "http://www.w3.org/2001/XInclude"}
for node in doc.xpath('//xi:include', namespaces=ns):
href = node.get('href')
if (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 not force and affected_books: if not force and affected_books:
books = affected_books books = affected_books
else: else:
@ -469,6 +486,7 @@ def build_affected_books(rootdir, book_exceptions, file_exceptions, force):
print("\n%s" % output) print("\n%s" % output)
if any_failures: if any_failures:
sys.exit(1) sys.exit(1)
print("Building finished.")
def main(rootdir, force, verbose): def main(rootdir, force, verbose):