Commit d03c95a5 authored by Roland Denis's avatar Roland Denis

json2rst and rst directives for the complete json scheme

parent 15b11d54
Pipeline #6671 passed with stages
in 1 minute and 59 seconds
......@@ -50,6 +50,13 @@ class storage(nodes.General, nodes.Element):
""" storage description """
class node_type_list(nodes.General, nodes.Element):
""" node list """
class node_type(nodes.General, nodes.Element):
""" node description """
###############################################################################
# Directives
......@@ -170,6 +177,86 @@ class Cluster(Directive):
return [node]
class StorageList(Directive):
required_arguments = 0
optional_arguments = 0
final_argument_whitespace = True
option_spec = {}
has_content = True
def run(self):
node = storage_list()
if self.content:
self.state.nested_parse(self.content, self.content_offset, node)
return [node]
class Storage(Directive):
required_arguments = 0
optional_arguments = 1
final_argument_whitespace = True
option_spec = { # Option name in lowercase!
'typename': str,
'name': str,
'filesystemtype': str,
'size': float,
}
has_content = True
def run(self):
node = storage()
node['name'] = self.arguments[0] if self.arguments else ''
for key in self.option_spec:
node[key] = self.options.get(key, None)
self.state.nested_parse(self.content, self.content_offset, node)
return [node]
class NodeTypeList(Directive):
required_arguments = 0
optional_arguments = 0
final_argument_whitespace = True
option_spec = {}
has_content = True
def run(self):
node = node_type_list()
if self.content:
self.state.nested_parse(self.content, self.content_offset, node)
return [node]
class NodeType(Directive):
required_arguments = 0
optional_arguments = 1
final_argument_whitespace = True
option_spec = { # Option name in lowercase!
'gputype': str,
'gpunumber': int,
'cputype': str,
'corenumber': int,
'cpunumber': int,
'memory': float,
'localdisk': float,
'nodenumber': int,
}
has_content = True
def run(self):
node = node_type()
node['name'] = self.arguments[0] if self.arguments else ''
for key in self.option_spec:
node[key] = self.options.get(key, None)
self.state.nested_parse(self.content, self.content_offset, node)
return [node]
def register():
directives.register_directive('region', Region)
......@@ -177,4 +264,8 @@ def register():
directives.register_directive('meso', Meso)
directives.register_directive('cluster_list', ClusterList)
directives.register_directive('cluster', Cluster)
directives.register_directive('storage_list', StorageList)
directives.register_directive('storage', Storage)
directives.register_directive('node_type_list', NodeTypeList)
directives.register_directive('node_type', NodeType)
......@@ -86,6 +86,29 @@ class myHTMLTranslator(PelicanHTMLTranslator):
def depart_cluster(self, node):
pass
def visit_storage_list(self, node):
pass
def depart_storage_list(self, node):
pass
def visit_storage(self, node):
pass
def depart_storage(self, node):
pass
def visit_node_type_list(self, node):
pass
def depart_node_type_list(self, node):
pass
def visit_node_type(self, node):
pass
def depart_node_type(self, node):
pass
# Overwrite default translator so that extensions can be chained
readers.PelicanHTMLTranslator = myHTMLTranslator
......
......@@ -44,15 +44,31 @@ def build_meso(meso):
'options': filter_options(directives.Meso, meso),
'content': meso.get('fullDescription', ''),
'cluster_list': list(map(build_cluster, meso.get('clusterList', []))),
'storage_list': list(map(build_storage, meso.get('storageList', []))),
}
def build_cluster(cluster):
""" Fitlers and formats attributes of a cluster depending on the Cluster directive """
""" Filters and formats attributes of a cluster depending on the Cluster directive """
return {
'name': cluster.get('name', ''),
'options': filter_options(directives.Cluster, cluster),
'storage_list': list(map(build_storage, cluster.get('storageType', []))),
'node_type_list': list(map(build_node_type, cluster.get('nodeType', []))),
}
def build_storage(storage):
""" Filters and formats attributes of a storage depending on the Storage directive """
return {
'name': storage.get('name', ''),
'options': filter_options(directives.Storage, storage),
}
def build_node_type(node_type):
""" Filters and formats attributes of a node type depending on the NodeType directive """
return {
'name': node_type.get('name', ''),
'options': filter_options(directives.NodeType, node_type),
}
def json_mesolist_to_rst(url):
"""
......@@ -82,7 +98,9 @@ def json_mesolist_to_rst(url):
region = meso['location']
meso_list.setdefault(region, []).append(build_meso(meso))
return _json_mesolist_rst_template.render(meso_by_region=meso_list)
result = _json_mesolist_rst_template.render(meso_by_region=meso_list)
print(result)
return result
# Pre-loading Jinja2 template as static variable
......@@ -105,13 +123,45 @@ _json_mesolist_rst_template = _json_mesolist_rst_env.from_string(dedent("""
{{ l }}
{%- endfor %}
{% for cluster in meso["cluster_list"] %}
.. cluster:: {{ cluster['name'] }}
{%- for l in cluster["options"] | rst_options %}
{{ l }}
{%- endfor %}
.. cluster_list::
{% for cluster in meso["cluster_list"] %}
.. cluster:: {{ cluster['name'] }}
{%- for l in cluster["options"] | rst_options %}
{{ l }}
{%- endfor %}
.. node_type_list::
{% for node_type in cluster["node_type_list"] %}
.. node_type:: {{ node_type['name'] }}
{%- for l in node_type["options"] | rst_options %}
{{ l }}
{%- endfor %}
{% endfor %}
.. storage_list::
{% for storage in cluster["storage_list"] %}
.. storage:: {{ storage['name'] }}
{%- for l in storage["options"] | rst_options %}
{{ l }}
{%- endfor %}
{% endfor %}
{% endfor %}
.. storage_list::
{% for storage in meso["storage_list"] %}
.. storage:: {{ storage['name'] }}
{%- for l in storage["options"] | rst_options %}
{{ l }}
{%- endfor %}
{% endfor %}
{% endfor %}
{%- endfor %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment