Merge "Require hacking for additional checks"

This commit is contained in:
Jenkins 2014-01-03 10:58:06 +00:00 committed by Gerrit Code Review
commit 90a2dd0652
6 changed files with 34 additions and 25 deletions

View File

@ -17,13 +17,13 @@
# For an example of usage, run this program with the -h switch. # For an example of usage, run this program with the -h switch.
# #
import common
import sys import sys
# this is for the internationalisation function in gettext # this is for the internationalisation function in gettext
import __builtin__ import __builtin__
__builtin__.__dict__['_'] = lambda x: x __builtin__.__dict__['_'] = lambda x: x
import common
def main(action, file, format, repo, verbose=0, name=False, test=False): def main(action, file, format, repo, verbose=0, name=False, test=False):

View File

@ -12,9 +12,10 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import sys
from os import path
import glob import glob
import os
import sys
from xml.dom import minidom from xml.dom import minidom
from xml.sax.saxutils import escape from xml.sax.saxutils import escape

View File

@ -20,8 +20,8 @@
import os import os
import re import re
import tempfile
import shutil import shutil
import tempfile
# should be the same like in tools/validate.py # should be the same like in tools/validate.py
FILE_EXCEPTIONS = ['ha-guide-docinfo.xml', FILE_EXCEPTIONS = ['ha-guide-docinfo.xml',

View File

@ -31,9 +31,6 @@ Requires:
- Maven - Maven
''' '''
import os_doc_tools
from lxml import etree
import argparse import argparse
import multiprocessing import multiprocessing
@ -44,6 +41,11 @@ import subprocess
import sys import sys
import urllib2 import urllib2
from lxml import etree
import os_doc_tools
# These are files that are known to not be in DocBook format # These are files that are known to not be in DocBook format
FILE_EXCEPTIONS = ['st-training-guides.xml', FILE_EXCEPTIONS = ['st-training-guides.xml',
'ha-guide-docinfo.xml'] 'ha-guide-docinfo.xml']
@ -93,7 +95,7 @@ def check_output(*popenargs, **kwargs):
def get_schema(is_api_site=False): def get_schema(is_api_site=False):
"""Return the DocBook RELAX NG schema""" """Return the DocBook RELAX NG schema."""
if is_api_site: if is_api_site:
url = "http://docs.rackspace.com/rackbook/rackbook.rng" url = "http://docs.rackspace.com/rackbook/rackbook.rng"
else: else:
@ -103,7 +105,7 @@ def get_schema(is_api_site=False):
def get_wadl_schema(): def get_wadl_schema():
"""Return the Wadl schema""" """Return the Wadl schema."""
url = "http://docs.rackspace.com/rackbook/wadl.xsd" url = "http://docs.rackspace.com/rackbook/wadl.xsd"
xmlschema_doc = etree.parse(urllib2.urlopen(url)) xmlschema_doc = etree.parse(urllib2.urlopen(url))
return etree.XMLSchema(xmlschema_doc) return etree.XMLSchema(xmlschema_doc)
@ -115,7 +117,8 @@ def validation_failed(schema, doc):
This will ignore validation failures of the type: IDREF attribute linkend This will ignore validation failures of the type: IDREF attribute linkend
references an unknown ID. This is because we are validating individual references an unknown ID. This is because we are validating individual
files that are being imported, and sometimes the reference isn't present files that are being imported, and sometimes the reference isn't present
in the current file.""" in the current file.
"""
return not schema.validate(doc) and \ return not schema.validate(doc) and \
any(log.type_name != "DTD_UNKNOWN_ID" for log in schema.error_log) any(log.type_name != "DTD_UNKNOWN_ID" for log in schema.error_log)
@ -123,7 +126,8 @@ def validation_failed(schema, doc):
def verify_section_tags_have_xmid(doc): def verify_section_tags_have_xmid(doc):
"""Check that all section tags have an xml:id attribute """Check that all section tags have an xml:id attribute
Will throw an exception if there's at least one missing""" Will throw an exception if there's at least one missing.
"""
ns = {"docbook": "http://docbook.org/ns/docbook"} ns = {"docbook": "http://docbook.org/ns/docbook"}
for node in doc.xpath('//docbook:section', namespaces=ns): for node in doc.xpath('//docbook:section', namespaces=ns):
if "{http://www.w3.org/XML/1998/namespace}id" not in node.attrib: if "{http://www.w3.org/XML/1998/namespace}id" not in node.attrib:
@ -169,13 +173,13 @@ def verify_attribute_profiling(doc, attribute, known_values):
def verify_profiling(doc): def verify_profiling(doc):
""""Check profiling information""" """"Check profiling information."""
verify_attribute_profiling(doc, "os", KNOWN_OS_VALUES) verify_attribute_profiling(doc, "os", KNOWN_OS_VALUES)
verify_attribute_profiling(doc, "audience", KNOWN_AUDIENCE_VALUES) verify_attribute_profiling(doc, "audience", KNOWN_AUDIENCE_VALUES)
def verify_nice_usage_of_whitespaces(docfile): def verify_nice_usage_of_whitespaces(docfile):
"""Check that no unnecessary whitespaces are used""" """Check that no unnecessary whitespaces are used."""
checks = [ checks = [
re.compile(".*\s+\n$"), re.compile(".*\s+\n$"),
] ]
@ -237,7 +241,7 @@ def error_message(error_log):
def only_www_touched(): def only_www_touched():
"""Check whether only files in www directory are touched""" """Check whether only files in www directory are touched."""
try: try:
git_args = ["git", "diff", "--name-only", "HEAD~1", "HEAD"] git_args = ["git", "diff", "--name-only", "HEAD~1", "HEAD"]
@ -258,7 +262,7 @@ def only_www_touched():
def ha_guide_touched(): def ha_guide_touched():
"""Check whether files in high-availability-guide directory are touched""" """Check whether files in high-availability-guide directory are touched."""
try: try:
git_args = ["git", "diff", "--name-only", "HEAD~1", "HEAD"] git_args = ["git", "diff", "--name-only", "HEAD~1", "HEAD"]
@ -305,7 +309,7 @@ def check_modified_affects_all(rootdir, verbose):
def get_modified_files(rootdir, filtering=None): def get_modified_files(rootdir, filtering=None):
"""Get modified files below doc directory""" """Get modified files below doc directory."""
# There are several tree traversals in this program that do a # There are several tree traversals in this program that do a
# chdir, we need to run this git command always from the rootdir, # chdir, we need to run this git command always from the rootdir,
@ -325,10 +329,10 @@ def get_modified_files(rootdir, filtering=None):
def check_deleted_files(rootdir, file_exceptions, verbose): def check_deleted_files(rootdir, file_exceptions, verbose):
""" Check whether files got deleted and verify that no other file """Check whether files got deleted and verify that no other file
references them. references them.
""" """
print("Checking that no removed files are referenced...") print("Checking that no removed files are referenced...")
deleted_files = get_modified_files(rootdir, "--diff-filter=D") deleted_files = get_modified_files(rootdir, "--diff-filter=D")
if not deleted_files: if not deleted_files:
@ -400,7 +404,7 @@ def check_deleted_files(rootdir, file_exceptions, verbose):
def validate_one_file(schema, rootdir, path, verbose, def validate_one_file(schema, rootdir, path, verbose,
check_syntax, check_niceness): check_syntax, check_niceness):
"""Validate a single file""" """Validate a single file."""
# We pass schema in as a way of caching it, generating it is expensive # We pass schema in as a way of caching it, generating it is expensive
any_failures = False any_failures = False
@ -427,7 +431,7 @@ def validate_one_file(schema, rootdir, path, verbose,
def is_xml(filename): def is_xml(filename):
"""Returns true if file ends with .xml and is not a pom.xml file""" """Returns true if file ends with .xml and is not a pom.xml file."""
return filename.endswith('.xml') and not filename.endswith('/pom.xml') return filename.endswith('.xml') and not filename.endswith('/pom.xml')
@ -443,7 +447,7 @@ def is_xml_wadl(filename):
def is_wadl(filename): def is_wadl(filename):
"""Returns true if file ends with .wadl""" """Returns true if file ends with .wadl."""
return filename.endswith('.wadl') return filename.endswith('.wadl')
@ -559,12 +563,12 @@ def validate_all_files(rootdir, exceptions, verbose,
def logging_build_book(result): def logging_build_book(result):
"""Callback for book building""" """Callback for book building."""
RESULTS_OF_BUILDS.append(result) RESULTS_OF_BUILDS.append(result)
def build_book(book): def build_book(book):
"""Build book(s) in directory book""" """Build book(s) in directory book."""
# Note that we cannot build in parallel several books in the same # Note that we cannot build in parallel several books in the same
# directory like the Install Guide. Thus we build sequentially per # directory like the Install Guide. Thus we build sequentially per
@ -935,7 +939,9 @@ def default_root():
"""Return the location of openstack-manuals """Return the location of openstack-manuals
The current working directory must be inside of the openstack-manuals The current working directory must be inside of the openstack-manuals
repository for this method to succeed""" repository for this method to succeed
"""
try: try:
git_args = ["git", "rev-parse", "--show-toplevel"] git_args = ["git", "rev-parse", "--show-toplevel"]
gitroot = check_output(git_args).rstrip() gitroot = check_output(git_args).rstrip()

View File

@ -1,3 +1,4 @@
coverage>=3.6 coverage>=3.6
flake8==2.0 flake8==2.0
pep8==1.4.5 pep8==1.4.5
hacking>=0.8,<0.9

View File

@ -27,8 +27,9 @@ commands = python setup.py testr --coverage --testr-args='{posargs}'
[flake8] [flake8]
# H803 skipped on purpose per list discussion. # H803 skipped on purpose per list discussion.
# E123, E125 skipped as they are invalid PEP-8. # E123, E125 skipped as they are invalid PEP-8.
# autogenerate-config-tools skipped until it passes all tests
show-source = True show-source = True
ignore = E123,E125,H803 ignore = E123,E125,H803
builtins = _ builtins = _
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,autogenerate-config-docs