clean up settings for url checks

Use a namedtuple-based class for specifying the URL settings so it is
easier to extend.

Change-Id: Ib5372d8b35285e154498da5315889707f3829e8f
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2018-09-12 12:57:58 -04:00 committed by Frode Nordahl
parent 57147ba4e7
commit a9a10d3d7a
1 changed files with 60 additions and 24 deletions

View File

@ -169,25 +169,56 @@ def _check_url(args):
# NOTE(dhellmann): We use URLs with explicit index.html to ensure that
# a real page is published to the location, and we are not retrieving
# a file list generated by the web server.
URLSettings = collections.namedtuple(
'URLSettings',
['flag_name', 'types', 'template'],
)
_URLS = [
(None, [],
'https://docs.openstack.org/{name}/{series}/index.html'),
('has_install_guide', ['service'],
'https://docs.openstack.org/{name}/{series}/install/index.html'),
('has_admin_guide', ['service'],
'https://docs.openstack.org/{name}/{series}/admin/index.html'),
('has_config_ref', ['service', 'library'],
'https://docs.openstack.org/{name}/{series}/configuration/index.html'),
('has_in_tree_api_docs', ['service'],
'https://docs.openstack.org/{name}/{series}/api/index.html'),
('has_user_guide', ['service'],
'https://docs.openstack.org/{name}/{series}/user/index.html'),
('has_api_ref', ['service'],
'https://developer.openstack.org/api-ref/{service_type}/index.html'),
('has_api_guide', ['service'],
'https://developer.openstack.org/api-guide/{service_type}/index.html'),
('has_deployment_guide', ['deployment'],
'https://docs.openstack.org/project-deploy-guide/{name}/{series}/index.html'), # noqa
URLSettings(
flag_name=None,
types=[],
template='https://docs.openstack.org/{name}/{series}/index.html',
),
URLSettings(
flag_name='has_install_guide',
types=['service'],
template='https://docs.openstack.org/{name}/{series}/install/index.html', # noqa
),
URLSettings(
flag_name='has_admin_guide',
types=['service'],
template='https://docs.openstack.org/{name}/{series}/admin/index.html',
),
URLSettings(
flag_name='has_config_ref',
types=['service', 'library'],
template='https://docs.openstack.org/{name}/{series}/configuration/index.html', # noqa
),
URLSettings(
flag_name='has_in_tree_api_docs',
types=['service'],
template='https://docs.openstack.org/{name}/{series}/api/index.html',
),
URLSettings(
flag_name='has_user_guide',
types=['service'],
template='https://docs.openstack.org/{name}/{series}/user/index.html',
),
URLSettings(
flag_name='has_api_ref',
types=['service'],
template='https://developer.openstack.org/api-ref/{service_type}/index.html', # noqa
),
URLSettings(
flag_name='has_api_guide',
types=['service'],
template='https://developer.openstack.org/api-guide/{service_type}/index.html', # noqa
),
URLSettings(
flag_name='has_deployment_guide',
types=['deployment'],
template='https://docs.openstack.org/project-deploy-guide/{name}/{series}/index.html', # noqa
),
]
@ -288,18 +319,21 @@ 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.
if not skip_links:
for flag, types, url_template in _URLS:
if flag is None:
for url_info in _URLS:
if url_info.flag_name is None:
flag_val = True
else:
flag_val = project.get(flag, False)
if (not flag_val) and types and project_type not in types:
flag_val = project.get(url_info.flag_name, False)
if ((not flag_val) and
url_info.types and
project_type not in url_info.types):
# This type of project isn't expected to have
# this type of link, so if we are not
# explicitly told to check for it don't.
continue
try:
url = url_template.format(series=series, **project)
url = url_info.template.format(
series=series, **project)
except KeyError:
# The project data does not include a field needed
# to build the URL (typically the
@ -315,7 +349,9 @@ def load_project_data(source_directory,
logger.info('%s:%s looking for %s',
series, project['name'], url)
links_to_check.append(
(url, project['name'], flag, flag_val)
(url, project['name'],
url_info.flag_name,
flag_val)
)
if links_to_check: