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