diff --git a/.gitignore b/.gitignore index c19e2b9..be37185 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,9 @@ api-ref/build *.log *.egg* +# Bytecompiled Python +*.py[cod] + # Editors *~ diff --git a/doc/requirements.txt b/doc/requirements.txt index 5eaa903..9b706f4 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -10,3 +10,4 @@ sphinx>=4.0.0 otcdocstheme reno>=3.1.0 # Apache-2.0 +git+https://git@gitea.eco.tsi-dev.otc-service.com/infra/otc-metadata.git diff --git a/doc/source/_ext/__pycache__/cont.cpython-38.pyc b/doc/source/_ext/__pycache__/cont.cpython-38.pyc deleted file mode 100644 index 61fba86..0000000 Binary files a/doc/source/_ext/__pycache__/cont.cpython-38.pyc and /dev/null differ diff --git a/doc/source/_ext/cont.py b/doc/source/_ext/cont.py index f503780..a6f64a5 100644 --- a/doc/source/_ext/cont.py +++ b/doc/source/_ext/cont.py @@ -18,6 +18,8 @@ from docutils.parsers.rst import Directive from docutils.parsers.rst import directives from sphinx.util import logging +import otc_metadata.services + LOG = logging.getLogger(__name__) @@ -33,47 +35,23 @@ class container_item(nodes.General, nodes.Element): pass -YAML_CACHE = {} +METADATA = otc_metadata.services.Services() class ServiceGroup(Directive): node_class = service_group option_spec = { 'class': directives.unchanged, - 'data': directives.unchanged_required, - 'category': directives.unchanged_required + 'service_category': directives.unchanged_required, + 'environment': directives.unchanged_required } has_content = False - def _load_data(self, fpath): - global YAML_CACHE - if fpath in YAML_CACHE: - return YAML_CACHE[fpath] - data = {} - try: - with open(fpath, 'r') as stream: - data = yaml.safe_load(stream) - except IOError: - LOG.warning( - "Parameters file not found, %s", fpath, - location=(self.state.document.settings.env.docname, None)) - return - except yaml.YAMLError as exc: - LOG.exception( - exc_info=exc, - msg="Error while parsing file [%s]." % fpath) - raise - - YAML_CACHE[fpath] = data - return data - def run(self): node = self.node_class() - _, fpath = self.state.document.settings.env.relfn2path( - self.options['data']) - data = self._load_data(fpath) - node['data'] = data['service_categories'][self.options['category']] + node['service_category'] = self.options.get('service_category') + node['environment'] = self.options.get('environment', 'public') node['class'] = self.options.get('class', 'navigator-container') return [node] @@ -82,41 +60,16 @@ class Navigator(Directive): node_class = navigator option_spec = { 'class': directives.unchanged, - 'data': directives.unchanged_required, - 'link_type': directives.unchanged + 'document_type': directives.unchanged, + 'environment': directives.unchanged_required } has_content = False - def _load_data(self, fpath): - global YAML_CACHE - if fpath in YAML_CACHE: - return YAML_CACHE[fpath] - data = {} - try: - with open(fpath, 'r') as stream: - data = yaml.safe_load(stream) - except IOError: - LOG.warning( - "Parameters file not found, %s", fpath, - location=(self.state.document.settings.env.docname, None)) - return - except yaml.YAMLError as exc: - LOG.exception( - exc_info=exc, - msg="Error while parsing file [%s]." % fpath) - raise - - YAML_CACHE[fpath] = data - return data - def run(self): node = self.node_class() - _, fpath = self.state.document.settings.env.relfn2path( - self.options['data']) - self.data = self._load_data(fpath) - node['data'] = self.data - node['link_type'] = self.options['link_type'] + node['document_type'] = self.options['document_type'] + node['environment'] = self.options.get('environment', 'public') node['class'] = self.options.get('class', 'navigator-container') return [node] @@ -186,29 +139,37 @@ def navigator_html(self, node): # This method renders containers of service groups with links to the # document of the specified type data = f'
' - for k, v in node['data']['service_categories'].items(): + + for cat in METADATA.service_categories: + category = cat["name"] + category_title = cat["title"] data += ( f'
' f'
' - f'
{v["title"]}
' + f'
{category_title}
' f'
' data += '' @@ -221,36 +182,24 @@ def service_group_html(self, node): # This method renders containers per each service of the category with all # links as individual list items data = '
' - for k, v in node['data']['services'].items(): - title = v["title"] + for k, v in METADATA.services_with_docs_by_category( + node['service_category'], environment=node['environment']).items(): + title = v["service_title"] data += ( f'
' f'
' - f'{v["title"]}
' + f'{title}
' f'