add flag to www-generator to look for links to enable

Add --check-all-links option to www-generator.py and have it report a
warning for links that do exist for a project but that are not enabled
in the project data file. This can be used to update that data file to
turn on flags and link to additional documentation.

Change-Id: I7941c6fd8ef53c37bd309542d5938699fa6fb475
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2017-07-10 16:31:54 -04:00 committed by Andreas Jaeger
parent 0253400c4c
commit 0d07be764f
2 changed files with 37 additions and 13 deletions

@ -1,9 +1,11 @@
#!/bin/bash -xe
.tox/checkbuild/bin/python tools/www-generator.py --verbose --source-directory www/ \
--output-directory publish-docs/www/
--output-directory publish-docs/www/ $@
rsync -a www/static/ publish-docs/www/
if [[ $? -eq 0 ]]; then
rsync -a www/static/ publish-docs/www/
fi
# publish-docs/www-index.html is the trigger for openstack-indexpage
# to include the file.
#mv publish-docs/www/www-index.html publish-docs/www-index.html

@ -51,9 +51,13 @@ def parse_command_line_arguments():
parser.add_argument("--verbose", help="Be more verbose.",
action="store_true", default=False)
parser.add_argument("--source-directory", type=str,
default='www', help='')
default='www', help='Set source directory.')
parser.add_argument("--output-directory", type=str,
default='publish-docs/www', help='')
default='publish-docs/www',
help='Set output directory.')
parser.add_argument("--check-all-links", action="store_true",
default=False,
help='Check for links with flags set false.')
return parser.parse_args()
@ -93,7 +97,7 @@ def _get_service_types():
return service_types
def load_project_data(source_directory):
def load_project_data(source_directory, check_all_links=False):
"Return a dict with project data grouped by series."
logger = logging.getLogger()
project_data = {}
@ -151,17 +155,34 @@ def load_project_data(source_directory):
# If the project claims to have a separately published guide
# of some sort, look for it before allowing the flag to stand.
for flag, url_template in _URLS:
if project.get(flag):
flag_val = project.get(flag, False)
try:
url = url_template.format(series=series, **project)
except KeyError:
# The project data does not include a field needed
# to build the URL (typically the
# service_type). Ignore this URL, unless the flag
# is set.
if flag_val:
raise
continue
# Only try to fetch the URL if we're going to do
# something with the result.
if flag_val or check_all_links:
logger.info('%s:%s looking for %s',
series, project['name'], url)
exists, status = _check_url(url)
if not exists:
logger.error(
'%s set for %s but %s does not exist (%s)',
flag, project['name'], url, status,
)
fail = True
if flag_val and not exists:
logger.error(
'%s set for %s but %s does not exist (%s)',
flag, project['name'], url, status,
)
fail = True
elif (not flag_val) and check_all_links and exists:
logger.warning(
'%s not set for %s but %s does exist',
flag, project['name'], url,
)
if fail:
raise ValueError('invalid input in %s' % filename)
project_data[series] = data
@ -199,7 +220,8 @@ def main():
args = parse_command_line_arguments()
logger = initialize_logging(args.debug, args.verbose)
project_data = load_project_data(args.source_directory)
project_data = load_project_data(args.source_directory,
args.check_all_links)
regular_repos, infra_repos = _get_official_repos()
# Set up jinja to discover the templates.