Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | import requests |
| 3 | import zipfile |
| 4 | from io import BytesIO |
| 5 | import os |
| 6 | from collections import defaultdict |
| 7 | from collections import OrderedDict |
| 8 | from distutils.version import StrictVersion |
| 9 | import shutil |
| 10 | import json |
| 11 | import glob |
| 12 | import subprocess |
| 13 | |
| 14 | import xml.etree.ElementTree as ET |
| 15 | |
| 16 | REGISTRY_HEADER = '''/* |
James Feist | e51c710 | 2020-03-17 10:38:18 -0700 | [diff] [blame] | 17 | // Copyright (c) 2020 Intel Corporation |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 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 | |
| 38 | namespace redfish::message_registries::{} |
| 39 | {{ |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 40 | ''' |
| 41 | |
| 42 | SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 43 | |
Jason M. Bills | ac70637 | 2020-02-18 11:36:47 -0800 | [diff] [blame] | 44 | include_path = os.path.realpath( |
| 45 | os.path.join( |
| 46 | SCRIPT_DIR, |
| 47 | "..", |
| 48 | "redfish-core", |
| 49 | "include", |
| 50 | "registries")) |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 51 | |
| 52 | proxies = { |
| 53 | 'https': os.environ.get("https_proxy", None) |
| 54 | } |
| 55 | |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 56 | |
James Feist | e51c710 | 2020-03-17 10:38:18 -0700 | [diff] [blame] | 57 | def 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 | |
| 66 | files = [] |
Gunnar Mills | e7808c9 | 2020-07-08 21:17:44 -0500 | [diff] [blame] | 67 | files.append(make_getter('Base.1.8.1.json', |
James Feist | e51c710 | 2020-03-17 10:38:18 -0700 | [diff] [blame] | 68 | 'base_message_registry.hpp', 'base')) |
Gunnar Mills | e7808c9 | 2020-07-08 21:17:44 -0500 | [diff] [blame] | 69 | files.append(make_getter('TaskEvent.1.0.2.json', |
James Feist | e51c710 | 2020-03-17 10:38:18 -0700 | [diff] [blame] | 70 | 'task_event_message_registry.hpp', 'task_event')) |
Sunitha Harish | 74eec26 | 2020-06-25 10:00:01 -0500 | [diff] [blame] | 71 | files.append(make_getter('ResourceEvent.1.0.3.json', |
| 72 | 'resource_event_message_registry.hpp', 'resource_event')) |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 73 | |
| 74 | # Remove the old files |
James Feist | e51c710 | 2020-03-17 10:38:18 -0700 | [diff] [blame] | 75 | for file, json, namespace, url in files: |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 76 | try: |
| 77 | os.remove(file) |
Jason M. Bills | ac70637 | 2020-02-18 11:36:47 -0800 | [diff] [blame] | 78 | except BaseException: |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 79 | print("{} not found".format(file)) |
| 80 | |
| 81 | with open(file, 'w') as registry: |
| 82 | registry.write(REGISTRY_HEADER.format(namespace)) |
Jason M. Bills | 351d306 | 2019-03-27 12:58:21 -0700 | [diff] [blame] | 83 | # Parse the Registry header info |
| 84 | registry.write("const Header header = {") |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 85 | registry.write("\"{}\",".format(json["@Redfish.Copyright"])) |
| 86 | registry.write("\"{}\",".format(json["@odata.type"])) |
| 87 | registry.write("\"{}\",".format(json["Id"])) |
Jason M. Bills | ac70637 | 2020-02-18 11:36:47 -0800 | [diff] [blame] | 88 | registry.write("\"{}\",".format(json["Name"])) |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 89 | registry.write("\"{}\",".format(json["Language"])) |
| 90 | registry.write("\"{}\",".format(json["Description"])) |
Jason M. Bills | ac70637 | 2020-02-18 11:36:47 -0800 | [diff] [blame] | 91 | registry.write("\"{}\",".format(json["RegistryPrefix"])) |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 92 | registry.write("\"{}\",".format(json["RegistryVersion"])) |
| 93 | registry.write("\"{}\",".format(json["OwningEntity"])) |
Jason M. Bills | 351d306 | 2019-03-27 12:58:21 -0700 | [diff] [blame] | 94 | registry.write("};") |
| 95 | |
James Feist | e51c710 | 2020-03-17 10:38:18 -0700 | [diff] [blame] | 96 | registry.write('constexpr const char * url = "{}";\n\n'.format(url)) |
Jason M. Bills | 351d306 | 2019-03-27 12:58:21 -0700 | [diff] [blame] | 97 | # Parse each Message entry |
Jason M. Bills | ac70637 | 2020-02-18 11:36:47 -0800 | [diff] [blame] | 98 | registry.write("constexpr std::array<MessageEntry, {}> registry = {{".format( |
| 99 | len(json["Messages"]))) |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 100 | for messageId, message in sorted(json["Messages"].items()): |
| 101 | registry.write("MessageEntry{") |
| 102 | registry.write("\"{}\",".format(messageId)) |
| 103 | registry.write("{") |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 104 | registry.write("\"{}\",".format(message["Description"])) |
| 105 | registry.write("\"{}\",".format(message["Message"])) |
| 106 | registry.write("\"{}\",".format(message["Severity"])) |
Gunnar Mills | e7808c9 | 2020-07-08 21:17:44 -0500 | [diff] [blame] | 107 | registry.write("\"{}\",".format(message["MessageSeverity"])) |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 108 | registry.write("{},".format(message["NumberOfArgs"])) |
| 109 | registry.write("{") |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 110 | paramTypes = message.get("ParamTypes") |
| 111 | if paramTypes: |
| 112 | for paramType in paramTypes: |
| 113 | registry.write("\"{}\",".format(paramType)) |
| 114 | registry.write("},") |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 115 | registry.write("\"{}\",".format(message["Resolution"])) |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 116 | registry.write("}},") |
| 117 | registry.write("};}\n") |
Gunnar Mills | c94d374 | 2020-07-08 20:46:53 -0500 | [diff] [blame] | 118 | subprocess.check_call(["clang-format-10", "-i", file]) |