Skip to content

Commit

Permalink
#900 fix with adding new info required for documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeleonard committed Nov 16, 2020
1 parent 35c9526 commit 47ba7c4
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions utils/flavors/check_json_schema.py
Expand Up @@ -15,8 +15,6 @@
import os
import argparse

FLAVOR_FILE="utils/flavors/flavor_schema.json"

def printJson(fjson:dict) -> str:
print(json.dumps(fjson, indent=4))

Expand Down Expand Up @@ -64,8 +62,7 @@ def fixJsonFlavorFile(jsonfile:dict) -> dict:
jsonfile["screenshots"] = screenshots
return jsonfile

def validateFlavorFormat(flavorfile:str, schemafile:str) -> str:
# flavorSchema = openJsonFile(FLAVOR_FILE)
def validateFlavorFormat(flavorfile:str, schemafile:str, fix:bool) -> str:
flavorSchema = openJsonFile(schemafile)
fjson = openJsonFile(flavorfile)

Expand All @@ -76,13 +73,19 @@ def validateFlavorFormat(flavorfile:str, schemafile:str) -> str:
else:
printSuccess(False, flavorfile)
for error in errors:
print("{}: {}".format(error.path,error.message))
# print('------')


print("{}: {}".format(error.path,error.message))
if fix:
print("Fixing {}".format(flavorfile))
j = fixJsonFlavorFile(fjson)
with open(flavorfile, 'w+') as fj:
fj.write(json.dumps(j,indent=4))
fj.close()


def run():
parser = argparse.ArgumentParser()
parser.add_argument("-r", "--report", help="Generate report for all JSON flavors of all Analyzers and responders", action="store_true", default=False)
parser.add_argument("-x", "--fix", help="Adding new information required for documentation", action="store_true", default=False)
parser.add_argument("-f", "--file", help="Validate JSON of the Flavor definition file")
parser.add_argument("-s", "--schema", help="JSON Schema of a flavor", default="utils/flavors/flavor_schema.json")

Expand All @@ -97,18 +100,20 @@ def run():
for file in os.listdir(os.path.join(p,neuron)):
if file.endswith(".json"):
filepath = os.path.join(p,neuron,file)
validateFlavorFormat(filepath, args.schema)
validateFlavorFormat(filepath, args.schema, args.fix)


if args.file:
filepath = args.file
try:
if os.path.isfile(filepath) and filepath.endswith(".json"):
validateFlavorFormat(filepath, args.schema)
validateFlavorFormat(filepath, args.schema, args.fix)
else:
print("Error: Check this is a file, json formatted, and it has .json extention\n {}".format(filepath))
except Exception as e:
print(e)


except Exception as e:
print(e)

Expand Down

0 comments on commit 47ba7c4

Please sign in to comment.