105 lines
2.6 KiB
Python
105 lines
2.6 KiB
Python
#!/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)
|
|
|
|
|