blob: 155d77c070ca97437988c7131b816dbe52f4396f [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 = '''/*
James Feiste51c7102020-03-17 10:38:18 -070017// Copyright (c) 2020 Intel Corporation
Jason M. Bills70304cb2019-03-27 12:03:59 -070018//
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. Bills70304cb2019-03-27 12:03:59 -070056
James Feiste51c7102020-03-17 10:38:18 -070057def make_getter(dmtf_name, header_name, type_name):
58 url = 'https://redfish.dmtf.org/registries/{}'.format(dmtf_name)
59 dmtf = requests.get(url, proxies=proxies)
60 dmtf.raise_for_status()
61 json_file = json.loads(dmtf.text)
62 path = os.path.join(include_path, header_name)
63 return (path, json_file, type_name, url)
64
65
66files = []
Gunnar Millse7808c92020-07-08 21:17:44 -050067files.append(make_getter('Base.1.8.1.json',
James Feiste51c7102020-03-17 10:38:18 -070068 'base_message_registry.hpp', 'base'))
Gunnar Millse7808c92020-07-08 21:17:44 -050069files.append(make_getter('TaskEvent.1.0.2.json',
James Feiste51c7102020-03-17 10:38:18 -070070 'task_event_message_registry.hpp', 'task_event'))
Sunitha Harish74eec262020-06-25 10:00:01 -050071files.append(make_getter('ResourceEvent.1.0.3.json',
72 'resource_event_message_registry.hpp', 'resource_event'))
Jason M. Bills70304cb2019-03-27 12:03:59 -070073
74# Remove the old files
James Feiste51c7102020-03-17 10:38:18 -070075for file, json, namespace, url in files:
Jason M. Bills70304cb2019-03-27 12:03:59 -070076 try:
77 os.remove(file)
Jason M. Billsac706372020-02-18 11:36:47 -080078 except BaseException:
Jason M. Bills70304cb2019-03-27 12:03:59 -070079 print("{} not found".format(file))
80
81 with open(file, 'w') as registry:
82 registry.write(REGISTRY_HEADER.format(namespace))
Jason M. Bills351d3062019-03-27 12:58:21 -070083 # Parse the Registry header info
84 registry.write("const Header header = {")
Ed Tanous271584a2019-07-09 16:24:22 -070085 registry.write("\"{}\",".format(json["@Redfish.Copyright"]))
86 registry.write("\"{}\",".format(json["@odata.type"]))
87 registry.write("\"{}\",".format(json["Id"]))
Jason M. Billsac706372020-02-18 11:36:47 -080088 registry.write("\"{}\",".format(json["Name"]))
Ed Tanous271584a2019-07-09 16:24:22 -070089 registry.write("\"{}\",".format(json["Language"]))
90 registry.write("\"{}\",".format(json["Description"]))
Jason M. Billsac706372020-02-18 11:36:47 -080091 registry.write("\"{}\",".format(json["RegistryPrefix"]))
Ed Tanous271584a2019-07-09 16:24:22 -070092 registry.write("\"{}\",".format(json["RegistryVersion"]))
93 registry.write("\"{}\",".format(json["OwningEntity"]))
Jason M. Bills351d3062019-03-27 12:58:21 -070094 registry.write("};")
95
James Feiste51c7102020-03-17 10:38:18 -070096 registry.write('constexpr const char * url = "{}";\n\n'.format(url))
Jason M. Bills351d3062019-03-27 12:58:21 -070097 # Parse each Message entry
Jason M. Billsac706372020-02-18 11:36:47 -080098 registry.write("constexpr std::array<MessageEntry, {}> registry = {{".format(
99 len(json["Messages"])))
Jason M. Bills70304cb2019-03-27 12:03:59 -0700100 for messageId, message in sorted(json["Messages"].items()):
101 registry.write("MessageEntry{")
102 registry.write("\"{}\",".format(messageId))
103 registry.write("{")
Ed Tanous271584a2019-07-09 16:24:22 -0700104 registry.write("\"{}\",".format(message["Description"]))
105 registry.write("\"{}\",".format(message["Message"]))
106 registry.write("\"{}\",".format(message["Severity"]))
Gunnar Millse7808c92020-07-08 21:17:44 -0500107 registry.write("\"{}\",".format(message["MessageSeverity"]))
Ed Tanous271584a2019-07-09 16:24:22 -0700108 registry.write("{},".format(message["NumberOfArgs"]))
109 registry.write("{")
Jason M. Bills70304cb2019-03-27 12:03:59 -0700110 paramTypes = message.get("ParamTypes")
111 if paramTypes:
112 for paramType in paramTypes:
113 registry.write("\"{}\",".format(paramType))
114 registry.write("},")
Ed Tanous271584a2019-07-09 16:24:22 -0700115 registry.write("\"{}\",".format(message["Resolution"]))
Jason M. Bills70304cb2019-03-27 12:03:59 -0700116 registry.write("}},")
117 registry.write("};}\n")
Gunnar Millsc94d3742020-07-08 20:46:53 -0500118 subprocess.check_call(["clang-format-10", "-i", file])