blob: df72fd9a068d64e3c527c188afa7ee55240fce35 [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 = []
67files.append(make_getter('Base.1.4.0.json',
68 'base_message_registry.hpp', 'base'))
69files.append(make_getter('TaskEvent.1.0.1.json',
70 'task_event_message_registry.hpp', 'task_event'))
Jason M. Bills70304cb2019-03-27 12:03:59 -070071
72# Remove the old files
James Feiste51c7102020-03-17 10:38:18 -070073for file, json, namespace, url in files:
Jason M. Bills70304cb2019-03-27 12:03:59 -070074 try:
75 os.remove(file)
Jason M. Billsac706372020-02-18 11:36:47 -080076 except BaseException:
Jason M. Bills70304cb2019-03-27 12:03:59 -070077 print("{} not found".format(file))
78
79 with open(file, 'w') as registry:
80 registry.write(REGISTRY_HEADER.format(namespace))
Jason M. Bills351d3062019-03-27 12:58:21 -070081 # Parse the Registry header info
82 registry.write("const Header header = {")
Ed Tanous271584a2019-07-09 16:24:22 -070083 registry.write("\"{}\",".format(json["@Redfish.Copyright"]))
84 registry.write("\"{}\",".format(json["@odata.type"]))
85 registry.write("\"{}\",".format(json["Id"]))
Jason M. Billsac706372020-02-18 11:36:47 -080086 registry.write("\"{}\",".format(json["Name"]))
Ed Tanous271584a2019-07-09 16:24:22 -070087 registry.write("\"{}\",".format(json["Language"]))
88 registry.write("\"{}\",".format(json["Description"]))
Jason M. Billsac706372020-02-18 11:36:47 -080089 registry.write("\"{}\",".format(json["RegistryPrefix"]))
Ed Tanous271584a2019-07-09 16:24:22 -070090 registry.write("\"{}\",".format(json["RegistryVersion"]))
91 registry.write("\"{}\",".format(json["OwningEntity"]))
Jason M. Bills351d3062019-03-27 12:58:21 -070092 registry.write("};")
93
James Feiste51c7102020-03-17 10:38:18 -070094 registry.write('constexpr const char * url = "{}";\n\n'.format(url))
Jason M. Bills351d3062019-03-27 12:58:21 -070095 # Parse each Message entry
Jason M. Billsac706372020-02-18 11:36:47 -080096 registry.write("constexpr std::array<MessageEntry, {}> registry = {{".format(
97 len(json["Messages"])))
Jason M. Bills70304cb2019-03-27 12:03:59 -070098 for messageId, message in sorted(json["Messages"].items()):
99 registry.write("MessageEntry{")
100 registry.write("\"{}\",".format(messageId))
101 registry.write("{")
Ed Tanous271584a2019-07-09 16:24:22 -0700102 registry.write("\"{}\",".format(message["Description"]))
103 registry.write("\"{}\",".format(message["Message"]))
104 registry.write("\"{}\",".format(message["Severity"]))
105 registry.write("{},".format(message["NumberOfArgs"]))
106 registry.write("{")
Jason M. Bills70304cb2019-03-27 12:03:59 -0700107 paramTypes = message.get("ParamTypes")
108 if paramTypes:
109 for paramType in paramTypes:
110 registry.write("\"{}\",".format(paramType))
111 registry.write("},")
Ed Tanous271584a2019-07-09 16:24:22 -0700112 registry.write("\"{}\",".format(message["Resolution"]))
Jason M. Bills70304cb2019-03-27 12:03:59 -0700113 registry.write("}},")
114 registry.write("};}\n")
Ed Tanous271584a2019-07-09 16:24:22 -0700115 subprocess.check_call(["clang-format-6.0", "-i", file])