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 = '''/* |
| 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 | |
| 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 | |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame^] | 44 | include_path = os.path.realpath(os.path.join(SCRIPT_DIR, "..", "redfish-core", "include", "registries")) |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 45 | |
| 46 | proxies = { |
| 47 | 'https': os.environ.get("https_proxy", None) |
| 48 | } |
| 49 | |
| 50 | base_file = requests.get('https://redfish.dmtf.org/registries/Base.1.4.0.json', proxies=proxies) |
| 51 | base_file.raise_for_status() |
| 52 | base_json = json.loads(base_file.text) |
| 53 | base_path = os.path.join(include_path, "base_message_registry.hpp") |
| 54 | |
| 55 | files = [(base_path, base_json, "base")] |
| 56 | |
| 57 | # Remove the old files |
| 58 | for 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)) |
Jason M. Bills | 351d306 | 2019-03-27 12:58:21 -0700 | [diff] [blame] | 66 | # Parse the Registry header info |
| 67 | registry.write("const Header header = {") |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame^] | 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"])) |
Jason M. Bills | 351d306 | 2019-03-27 12:58:21 -0700 | [diff] [blame] | 77 | registry.write("};") |
| 78 | |
| 79 | # Parse each Message entry |
| 80 | registry.write("const std::array registry = {") |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 81 | for messageId, message in sorted(json["Messages"].items()): |
| 82 | registry.write("MessageEntry{") |
| 83 | registry.write("\"{}\",".format(messageId)) |
| 84 | registry.write("{") |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame^] | 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("{") |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 90 | paramTypes = message.get("ParamTypes") |
| 91 | if paramTypes: |
| 92 | for paramType in paramTypes: |
| 93 | registry.write("\"{}\",".format(paramType)) |
| 94 | registry.write("},") |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame^] | 95 | registry.write("\"{}\",".format(message["Resolution"])) |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 96 | registry.write("}},") |
| 97 | registry.write("};}\n") |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame^] | 98 | subprocess.check_call(["clang-format-6.0", "-i", file]) |