1#!/usr/bin/python3 2import requests 3import zipfile 4from io import BytesIO 5import os 6from collections import defaultdict 7from collections import OrderedDict 8from distutils.version import StrictVersion 9import shutil 10import json 11import glob 12import subprocess 13 14import xml.etree.ElementTree as ET 15 16REGISTRY_HEADER = '''/* 17// Copyright (c) 2019 Intel Corporation 18// 19// Licensed under the Apache License, Version 2.0 (the "License"); 20// you may not use this file except in compliance with the License. 21// You may obtain a copy of the License at 22// 23// http://www.apache.org/licenses/LICENSE-2.0 24// 25// Unless required by applicable law or agreed to in writing, software 26// distributed under the License is distributed on an "AS IS" BASIS, 27// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 28// See the License for the specific language governing permissions and 29// limitations under the License. 30*/ 31/**************************************************************** 32 * This is an auto-generated header which contains definitions 33 * for Redfish DMTF defined messages. 34 ***************************************************************/ 35#pragma once 36#include <registries.hpp> 37 38namespace redfish::message_registries::{} 39{{ 40''' 41 42SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) 43 44include_path = os.path.realpath(os.path.join(SCRIPT_DIR, "..", "redfish-core", "include", "registries")) 45 46proxies = { 47 'https': os.environ.get("https_proxy", None) 48} 49 50base_file = requests.get('https://redfish.dmtf.org/registries/Base.1.4.0.json', proxies=proxies) 51base_file.raise_for_status() 52base_json = json.loads(base_file.text) 53base_path = os.path.join(include_path, "base_message_registry.hpp") 54 55files = [(base_path, base_json, "base")] 56 57# Remove the old files 58for file, json, namespace in files: 59 try: 60 os.remove(file) 61 except: 62 print("{} not found".format(file)) 63 64 with open(file, 'w') as registry: 65 registry.write(REGISTRY_HEADER.format(namespace)) 66 # Parse the Registry header info 67 registry.write("const Header header = {") 68 registry.write("\"{}\",".format(json["@Redfish.Copyright"])) 69 registry.write("\"{}\",".format(json["@odata.type"])) 70 registry.write("\"{}\",".format(json["Id"])) 71 registry.write(".\"{}\",".format(json["Name"])) 72 registry.write("\"{}\",".format(json["Language"])) 73 registry.write("\"{}\",".format(json["Description"])) 74 registry.write(".\"{}\",".format(json["RegistryPrefix"])) 75 registry.write("\"{}\",".format(json["RegistryVersion"])) 76 registry.write("\"{}\",".format(json["OwningEntity"])) 77 registry.write("};") 78 79 # Parse each Message entry 80 registry.write("const std::array registry = {") 81 for messageId, message in sorted(json["Messages"].items()): 82 registry.write("MessageEntry{") 83 registry.write("\"{}\",".format(messageId)) 84 registry.write("{") 85 registry.write("\"{}\",".format(message["Description"])) 86 registry.write("\"{}\",".format(message["Message"])) 87 registry.write("\"{}\",".format(message["Severity"])) 88 registry.write("{},".format(message["NumberOfArgs"])) 89 registry.write("{") 90 paramTypes = message.get("ParamTypes") 91 if paramTypes: 92 for paramType in paramTypes: 93 registry.write("\"{}\",".format(paramType)) 94 registry.write("},") 95 registry.write("\"{}\",".format(message["Resolution"])) 96 registry.write("}},") 97 registry.write("};}\n") 98 subprocess.check_call(["clang-format-6.0", "-i", file]) 99