From 93362e28c4044253382bcc91a0c60c1da8157ed8 Mon Sep 17 00:00:00 2001 From: Alexander Hirschfeld Date: Thu, 9 Apr 2015 22:14:16 -0500 Subject: [PATCH] Added Designated-Sections to translator Change-Id: Ia38af05bf57c018ea0d34e56e75bf4065ba9c9db --- tools/jsonToRst.py | 62 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/tools/jsonToRst.py b/tools/jsonToRst.py index cd91e353..c7ca85e8 100755 --- a/tools/jsonToRst.py +++ b/tools/jsonToRst.py @@ -13,6 +13,9 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +# +# This was build for python 2.7, The print statements are failing with +# Python 3.X import json import sys @@ -38,9 +41,14 @@ if inFileName is "NONE": print "reading from", inFileName + with open(inFileName) as f: data = json.load(f) +if not isinstance(data, dict): + print 'Make sure this is a valid file' + sys.exit(1) + outFileName = inFileName.replace("json", "rst") @@ -49,9 +57,8 @@ print "writing to", outFileName # intro with open(outFileName, "w") as outFile: - if not isinstance(data,dict) or data.get('id') is None: + if data.get('id') is None: print 'Make sure there is a valid id' - print 'Make sure this is a valid file' sys.exit(1) line01 = "OpenStack DefCore %s" % data["id"] @@ -69,9 +76,9 @@ with open(outFileName, "w") as outFile: :Status: {status} :Replaces: {replaces} -This document outlines the mandatory and advisory capabilities -required to exist in a software installation in order to be -eligible to use marks controlled by the OpenStack Foundation. +This document outlines the mandatory capabilities and designated +sections required to exist in a software installation in order to +be eligible to use marks controlled by the OpenStack Foundation. This document was generated from the master JSON version. @@ -104,26 +111,65 @@ Platform Components components = sorted(data["components"].keys()) order = ["required", "advisory", "deprecated", "removed"] for component in components: + outFile.write(""" {component} Component Capabilities -==================================== - """.format(component=component.capitalize())) +""".format(component=component.capitalize())) + outFile.write('='*(len(component) + 23)) # footer + for event in order: + outFile.write("\n{event} Capabilities \n".format( event=event.capitalize())) - outFile.write("----------------------- \n") + outFile.write("-" * (len(event) + 15) + "\n") + if(len(data['components'][component][event]) == 0): outFile.write("None \n") + for req in data['components'][component][event]: if not data["capabilities"][req].get('name') is None: + outFile.write("* {name} ({project})\n".format( name=data["capabilities"][req]["name"].capitalize(), project=data["capabilities"][req].get("project"))) else: print "{ capabilities /", req, "/ name } does not exist" + outFile.write("* {name} ({project})\n".format( name=req.capitalize(), project=data["capabilities"][req].get("project"))) + + # Designated -Sections + + if 'designated-sections' not in data: + print "designated-sections not in json file" + sys.exit(1) + + outFile.write(""" + +Designated Sections +===================================== + +The following designated sections apply to the same releases as +this specification.""") + order = ['required', 'advisory', 'deprecated', 'removed'] + desig = data.get("designated-sections") + for event in order: + + outFile.write('\n\n{event} Designated Sections\n'.format( + event=event.capitalize())) + outFile.write('-'*(len(event) + 20)) # +20 is for length of header + + names = sorted(desig[event].keys()) + if len(names) is 0: + outFile.write('\nNone') + + for name in names: + outFile.write("\n* {name} : {guide}".format( + name=name.capitalize(), + guide=desig[event][name].get('guidance'))) + + outFile.write('\n')