Adding python35 support to jsontorst script

To support community goal python35. Make sure script works correctly.
Also fixed a couple of references to defcore cgit repo

Change-Id: Ia75e5e0848813f895952663680630f9e9ca6a5c8
This commit is contained in:
Luz Cazares 2017-06-16 16:35:36 +00:00
parent b397863e9a
commit 7c3be66b7f

View File

@ -14,8 +14,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# This was build for python 2.7, The print statements are failing with
# Python 3.X
import json import json
import sys import sys
@ -23,8 +21,8 @@ import textwrap
def printHelpArrays(input): def printHelpArrays(input):
if(len(input) == 0): if not input:
return 'None' return None
output = "" output = ""
for i in input: for i in input:
output = output + i.capitalize() + ', ' output = output + i.capitalize() + ', '
@ -32,38 +30,40 @@ def printHelpArrays(input):
return output[0:-2] return output[0:-2]
def print_error(msg):
print(msg)
sys.exit(1)
wrapper = textwrap.TextWrapper(width=79, subsequent_indent=' ') wrapper = textwrap.TextWrapper(width=79, subsequent_indent=' ')
inFileName = "NONE" inFileName = None
for potentialFile in sys.argv: for potentialFile in sys.argv:
if ".json" in potentialFile: if ".json" in potentialFile:
inFileName = potentialFile inFileName = potentialFile
if inFileName is "NONE": if not inFileName:
print "Please pass the JSON file" print_error("Please pass the JSON file")
sys.exit(1)
print "reading from", inFileName print("Reading from: " + inFileName)
with open(inFileName) as f: with open(inFileName) as f:
data = json.load(f) data = json.load(f)
if not isinstance(data, dict): if not isinstance(data, dict):
print 'Make sure this is a valid file' print_error('Make sure this is a valid file')
sys.exit(1)
outFileName = 'doc/source/guidelines/' + inFileName.replace("json", "rst") outFileName = 'doc/source/guidelines/' + inFileName.replace("json", "rst")
print "writing to", outFileName print ("Writing to: " + outFileName)
# intro # intro
with open(outFileName, "w") as outFile: with open(outFileName, "w") as outFile:
if data.get('id') is None: if data.get('id') is None:
print 'Make sure there is a valid id' print_error('Make sure there is a valid id')
sys.exit(1)
line01 = "OpenStack Interoperability Guideline %s" % data["id"] line01 = "OpenStack Interoperability Guideline %s" % data["id"]
@ -73,19 +73,18 @@ with open(outFileName, "w") as outFile:
# Nonlooping # Nonlooping
if data.get('platform') is None: if data.get('platform') is None:
print "The platform section is not found" print_error("The platform section is not found")
sys.exit(1)
# Correct Source # Correct Source
if data.get('source') != \ if data.get('source') not in (
'http://git.openstack.org/cgit/openstack/defcore/': 'http://git.openstack.org/cgit/openstack/defcore/',
print "The expected interoperability guideline source not found" 'http://git.openstack.org/cgit/openstack/interop/'):
sys.exit(1) print_error("The expected interoperability guideline source not found")
outFile.write(""" outFile.write("""
:Status: {status} :Status: {status}
:Replaces: {replaces} :Replaces: {replaces}
:JSON Master: http://git.openstack.org/cgit/openstack/defcore/tree/{id}.json :JSON Master: http://git.openstack.org/cgit/openstack/interop/tree/{id}.json
This document outlines the mandatory capabilities and designated This document outlines the mandatory capabilities and designated
sections required to exist in a software installation in order to sections required to exist in a software installation in order to
@ -117,8 +116,7 @@ Platform Components
# looping # looping
if data.get('components') is None: if data.get('components') is None:
print "No components found" print_error("No components found")
sys.exit(1)
components = sorted(data["components"].keys()) components = sorted(data["components"].keys())
order = ["required", "advisory", "deprecated", "removed"] order = ["required", "advisory", "deprecated", "removed"]
@ -150,8 +148,7 @@ Platform Components
# Designated -Sections # Designated -Sections
if 'designated-sections' not in data: if 'designated-sections' not in data:
print "designated-sections not in json file" print_error("designated-sections not in json file")
sys.exit(1)
outFile.write(""" outFile.write("""