Add conversion utility for yaml to rst format
tox should now be able to build the html documentation to completion. Change-Id: I384971732166fbeb123d572d3ccbcde6bad39dfc
This commit is contained in:
parent
ea154bc92d
commit
8bc57cc555
|
@ -8,7 +8,7 @@ These pages contain published OpenStack Security Advisories.
|
|||
:maxdepth: 2
|
||||
:glob:
|
||||
|
||||
ossa/index
|
||||
./ossa/*
|
||||
|
||||
.. seealso::
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# needed for doc build
|
||||
rstcloth==0.2.2
|
||||
PyYAML==3.11
|
||||
sphinx>=1.1.2,!=1.2.0,<1.3
|
||||
oslosphinx>=2.2.0 # Apache-2.0
|
||||
|
|
5
tox.ini
5
tox.ini
|
@ -13,4 +13,7 @@ deps = -r{toxinidir}/test-requirements.txt
|
|||
commands = {posargs}
|
||||
|
||||
[testenv:docs]
|
||||
commands = python setup.py build_sphinx
|
||||
deps = -r{toxinidir}/test-requirements.txt
|
||||
commands =
|
||||
python yaml2rst.py
|
||||
python setup.py build_sphinx
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
#!/usr/bin/env python
|
||||
import glob
|
||||
import os
|
||||
from rstcloth import rstcloth
|
||||
import sys
|
||||
import yaml
|
||||
reload(sys)
|
||||
sys.setdefaultencoding("utf-8")
|
||||
|
||||
TW=3
|
||||
|
||||
def format_affected(affected):
|
||||
content = ""
|
||||
seen = False
|
||||
for product in affected:
|
||||
if seen:
|
||||
content += " "*TW
|
||||
content +="- {product}: {version}\n".format(**product)
|
||||
seen = True
|
||||
|
||||
content += "\n"
|
||||
return content
|
||||
|
||||
def format_reporters(reporters):
|
||||
content =""
|
||||
seen = False
|
||||
for reporter in reporters:
|
||||
if seen:
|
||||
content += " "*TW
|
||||
|
||||
cves = ", ".join(reporter['reported'])
|
||||
data = dict(reporter)
|
||||
data["cves"] = cves
|
||||
if not 'affiliation' in data or data['affiliation'] == 'UNKNOWN':
|
||||
content += "- {name} ({cves})\n".format(**data)
|
||||
else:
|
||||
content += "- {name} from {affiliation} ({cves})\n".format(**data)
|
||||
seen = True
|
||||
|
||||
content += "\n"
|
||||
return content
|
||||
|
||||
def format_reviews(reviews):
|
||||
content = "\n"
|
||||
for review in [ x for x in reviews if x != 'type' ]:
|
||||
seen = False
|
||||
for link in reviews[review]:
|
||||
content += " "*TW
|
||||
content += "- `{url} ({review}) <{url}>`_\n".format(review=review, url=link)
|
||||
seen = True
|
||||
|
||||
content += "\n"
|
||||
return content
|
||||
|
||||
def format_urls(links):
|
||||
content =""
|
||||
seen = False
|
||||
for link in links:
|
||||
if seen:
|
||||
content += " "*TW
|
||||
content += "- `{url} <{url}>`_\n".format(url=link)
|
||||
seen = True
|
||||
content += "\n"
|
||||
return content
|
||||
|
||||
def convert(old, new):
|
||||
data = yaml.safe_load(open(old).read())
|
||||
doc = rstcloth.RstCloth()
|
||||
doc.title("{id}".format(**data))
|
||||
doc.newline()
|
||||
doc.h2(data['title'])
|
||||
|
||||
doc.field('Date', "{:%B %d, %Y}".format(data['date']))
|
||||
doc.newline()
|
||||
|
||||
doc.field('Description', data['description'])
|
||||
doc.newline()
|
||||
|
||||
doc.field('Announcement', doc.inline_link(data['reference'],data['reference']), wrap=False)
|
||||
doc.newline()
|
||||
|
||||
doc.field("Affects", format_affected(data['affected-products']), wrap=False)
|
||||
doc.newline()
|
||||
|
||||
doc.field("Credits", format_reporters(data['reporters']), wrap=False)
|
||||
doc.newline()
|
||||
|
||||
doc.field("Bug reports", format_urls(data['issues']['links']), wrap=False)
|
||||
doc.newline()
|
||||
|
||||
doc.field("Reviews", format_reviews(data['reviews']), wrap=False)
|
||||
doc.newline()
|
||||
|
||||
doc.write(new)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
input_files = glob.glob(os.path.join(".", "ossa", "*.yaml"))
|
||||
output_files = [ x.replace(".yaml", ".rst") for x in input_files ]
|
||||
for old, new in zip(input_files, output_files):
|
||||
convert(old, new)
|
||||
|
||||
|
Loading…
Reference in New Issue