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 | {{ |
| 40 | |
| 41 | const std::array registry = {{ |
| 42 | ''' |
| 43 | |
| 44 | SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 45 | |
| 46 | include_path = os.path.realpath(os.path.join(SCRIPT_DIR, "..", "redfish-core", "include")) |
| 47 | |
| 48 | proxies = { |
| 49 | 'https': os.environ.get("https_proxy", None) |
| 50 | } |
| 51 | |
| 52 | base_file = requests.get('https://redfish.dmtf.org/registries/Base.1.4.0.json', proxies=proxies) |
| 53 | base_file.raise_for_status() |
| 54 | base_json = json.loads(base_file.text) |
| 55 | base_path = os.path.join(include_path, "base_message_registry.hpp") |
| 56 | |
| 57 | files = [(base_path, base_json, "base")] |
| 58 | |
| 59 | # Remove the old files |
| 60 | for file, json, namespace in files: |
| 61 | try: |
| 62 | os.remove(file) |
| 63 | except: |
| 64 | print("{} not found".format(file)) |
| 65 | |
| 66 | with open(file, 'w') as registry: |
| 67 | registry.write(REGISTRY_HEADER.format(namespace)) |
| 68 | for messageId, message in sorted(json["Messages"].items()): |
| 69 | registry.write("MessageEntry{") |
| 70 | registry.write("\"{}\",".format(messageId)) |
| 71 | registry.write("{") |
| 72 | registry.write(".description = \"{}\",".format(message["Description"])) |
| 73 | registry.write(".message = \"{}\",".format(message["Message"])) |
| 74 | registry.write(".severity = \"{}\",".format(message["Severity"])) |
| 75 | registry.write(".numberOfArgs = {},".format(message["NumberOfArgs"])) |
| 76 | registry.write(".paramTypes = {") |
| 77 | paramTypes = message.get("ParamTypes") |
| 78 | if paramTypes: |
| 79 | for paramType in paramTypes: |
| 80 | registry.write("\"{}\",".format(paramType)) |
| 81 | registry.write("},") |
| 82 | registry.write(".resolution = \"{}\",".format(message["Resolution"])) |
| 83 | registry.write("}},") |
| 84 | registry.write("};}\n") |
| 85 | subprocess.check_call(["clang-format", "-i", file]) |