blob: d5e83bcb49f7b04e1c66f5846fde7104cff98f45 [file] [log] [blame]
Jason M. Bills70304cb2019-03-27 12:03:59 -07001#!/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{{
Jason M. Bills70304cb2019-03-27 12:03:59 -070040'''
41
42SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
43
Jason M. Billsac706372020-02-18 11:36:47 -080044include_path = os.path.realpath(
45 os.path.join(
46 SCRIPT_DIR,
47 "..",
48 "redfish-core",
49 "include",
50 "registries"))
Jason M. Bills70304cb2019-03-27 12:03:59 -070051
52proxies = {
53 'https': os.environ.get("https_proxy", None)
54}
55
Jason M. Billsac706372020-02-18 11:36:47 -080056base_file = requests.get(
57 'https://redfish.dmtf.org/registries/Base.1.4.0.json',
58 proxies=proxies)
Jason M. Bills70304cb2019-03-27 12:03:59 -070059base_file.raise_for_status()
60base_json = json.loads(base_file.text)
61base_path = os.path.join(include_path, "base_message_registry.hpp")
62
63files = [(base_path, base_json, "base")]
64
65# Remove the old files
66for file, json, namespace in files:
67 try:
68 os.remove(file)
Jason M. Billsac706372020-02-18 11:36:47 -080069 except BaseException:
Jason M. Bills70304cb2019-03-27 12:03:59 -070070 print("{} not found".format(file))
71
72 with open(file, 'w') as registry:
73 registry.write(REGISTRY_HEADER.format(namespace))
Jason M. Bills351d3062019-03-27 12:58:21 -070074 # Parse the Registry header info
75 registry.write("const Header header = {")
Ed Tanous271584a2019-07-09 16:24:22 -070076 registry.write("\"{}\",".format(json["@Redfish.Copyright"]))
77 registry.write("\"{}\",".format(json["@odata.type"]))
78 registry.write("\"{}\",".format(json["Id"]))
Jason M. Billsac706372020-02-18 11:36:47 -080079 registry.write("\"{}\",".format(json["Name"]))
Ed Tanous271584a2019-07-09 16:24:22 -070080 registry.write("\"{}\",".format(json["Language"]))
81 registry.write("\"{}\",".format(json["Description"]))
Jason M. Billsac706372020-02-18 11:36:47 -080082 registry.write("\"{}\",".format(json["RegistryPrefix"]))
Ed Tanous271584a2019-07-09 16:24:22 -070083 registry.write("\"{}\",".format(json["RegistryVersion"]))
84 registry.write("\"{}\",".format(json["OwningEntity"]))
Jason M. Bills351d3062019-03-27 12:58:21 -070085 registry.write("};")
86
87 # Parse each Message entry
Jason M. Billsac706372020-02-18 11:36:47 -080088 registry.write("constexpr std::array<MessageEntry, {}> registry = {{".format(
89 len(json["Messages"])))
Jason M. Bills70304cb2019-03-27 12:03:59 -070090 for messageId, message in sorted(json["Messages"].items()):
91 registry.write("MessageEntry{")
92 registry.write("\"{}\",".format(messageId))
93 registry.write("{")
Ed Tanous271584a2019-07-09 16:24:22 -070094 registry.write("\"{}\",".format(message["Description"]))
95 registry.write("\"{}\",".format(message["Message"]))
96 registry.write("\"{}\",".format(message["Severity"]))
97 registry.write("{},".format(message["NumberOfArgs"]))
98 registry.write("{")
Jason M. Bills70304cb2019-03-27 12:03:59 -070099 paramTypes = message.get("ParamTypes")
100 if paramTypes:
101 for paramType in paramTypes:
102 registry.write("\"{}\",".format(paramType))
103 registry.write("},")
Ed Tanous271584a2019-07-09 16:24:22 -0700104 registry.write("\"{}\",".format(message["Resolution"]))
Jason M. Bills70304cb2019-03-27 12:03:59 -0700105 registry.write("}},")
106 registry.write("};}\n")
Ed Tanous271584a2019-07-09 16:24:22 -0700107 subprocess.check_call(["clang-format-6.0", "-i", file])