def Process(contents, filename): ''' Processes the contents of a file and returns an equivalent Python dictionary in a format that the JSON schema compiler expects to see. (Separate from Load primarily for testing purposes.) ''' idl = idl_parser.IDLParser().ParseData(contents, filename) idl_schema = IDLSchema(idl) return idl_schema.process()
def Load(filename): ''' Given the filename of an IDL file, parses it and returns an equivalent Python dictionary in a format that the JSON schema compiler expects to see. ''' f = open(filename, 'r') contents = f.read() f.close() idl = idl_parser.IDLParser().ParseData(contents, filename) idl_schema = IDLSchema(idl) return idl_schema.process()
def generate(self, root, infile, outFilename): self._idl_parser = idl_parser.IDLParser() self._idl_parser.Parse(infile) children = root.getChildren() self._BuildDataModel(children) if self._genCategory == 'ifmap-backend': self._GenerateBackendClassDefinitions() self._GenerateBackendClassImpl() self._GenerateBackendParsers() elif self._genCategory == 'ifmap-frontend': self._GenerateFrontendClassDefinitions(root) elif self._genCategory == 'java-api': self._GenerateJavaApi(root)
def Main(): ''' Dump a json serialization of parse result for the IDL files whose names were passed in on the command line. ''' if len(sys.argv) > 1: for filename in sys.argv[1:]: schema = Load(filename) print(json.dumps(schema, indent=2)) else: contents = sys.stdin.read() idl = idl_parser.IDLParser().ParseData(contents, '<stdin>') schema = IDLSchema(idl).process() print(json.dumps(schema, indent=2))
def generate(self, root, infile, outFilename): self._idl_parser = idl_parser.IDLParser() self._idl_parser.Parse(infile) children = root.getChildren() self._BuildDataModel(children) if self._genCategory == 'ifmap-backend': self._GenerateBackendClassDefinitions() self._GenerateBackendClassImpl() self._GenerateBackendParsers() elif self._genCategory == 'ifmap-frontend': self._GenerateFrontendClassDefinitions(root) elif self._genCategory == 'java-api': self._GenerateJavaApi(root) elif self._genCategory == 'device-api': self._GenerateDeviceApi(root) elif self._genCategory == 'golang-api': self._GenerateGoLangApi(root) elif self._genCategory == 'contrail-json-schema': self._GenerateContrailJsonSchema(root) elif self._genCategory == 'json-schema': self._GenerateJsonSchema(root)