Nan Zhou | 313c1b7 | 2022-03-25 11:47:55 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 2 | import os |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 3 | import shutil |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 4 | import xml.etree.ElementTree as ET |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 5 | import zipfile |
| 6 | from collections import OrderedDict, defaultdict |
| 7 | from io import BytesIO |
| 8 | |
Ed Tanous | 0ec8b83 | 2022-03-14 14:56:47 -0700 | [diff] [blame] | 9 | import generate_schema_enums |
Patrick Williams | fd06b30 | 2022-12-12 10:39:42 -0600 | [diff] [blame] | 10 | import requests |
Carson Labrado | 9e03140 | 2022-07-08 20:56:52 +0000 | [diff] [blame] | 11 | from generate_schema_collections import generate_top_collections |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 12 | |
Ed Tanous | e9cc1bc | 2023-09-21 11:15:30 -0700 | [diff] [blame] | 13 | VERSION = "DSP8010_2023.2" |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 14 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 15 | WARNING = """/**************************************************************** |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 16 | * READ THIS WARNING FIRST |
| 17 | * This is an auto-generated header which contains definitions |
| 18 | * for Redfish DMTF defined schemas. |
| 19 | * DO NOT modify this registry outside of running the |
| 20 | * update_schemas.py script. The definitions contained within |
| 21 | * this file are owned by DMTF. Any modifications to these files |
| 22 | * should be first pushed to the relevant registry in the DMTF |
| 23 | * github organization. |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 24 | ***************************************************************/""" |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 25 | |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 26 | # To use a new schema, add to list and rerun tool |
| 27 | include_list = [ |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 28 | "AccountService", |
| 29 | "ActionInfo", |
Ed Tanous | 6c06898 | 2023-02-07 15:44:38 -0800 | [diff] [blame] | 30 | "AggregationService", |
Carson Labrado | 8b2521a | 2023-02-18 02:33:14 +0000 | [diff] [blame] | 31 | "AggregationSource", |
Carson Labrado | 5315c1b | 2023-02-18 01:02:18 +0000 | [diff] [blame] | 32 | "AggregationSourceCollection", |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 33 | "Assembly", |
| 34 | "AttributeRegistry", |
| 35 | "Bios", |
| 36 | "Cable", |
| 37 | "CableCollection", |
| 38 | "Certificate", |
| 39 | "CertificateCollection", |
| 40 | "CertificateLocations", |
| 41 | "CertificateService", |
| 42 | "Chassis", |
| 43 | "ChassisCollection", |
| 44 | "ComputerSystem", |
| 45 | "ComputerSystemCollection", |
Ed Tanous | 23203b4 | 2023-03-16 16:58:46 -0700 | [diff] [blame] | 46 | "ComponentIntegrity", |
| 47 | "ComponentIntegrityCollection", |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 48 | "Drive", |
| 49 | "DriveCollection", |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 50 | "EnvironmentMetrics", |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 51 | "EthernetInterface", |
| 52 | "EthernetInterfaceCollection", |
| 53 | "Event", |
| 54 | "EventDestination", |
| 55 | "EventDestinationCollection", |
| 56 | "EventService", |
Lakshmi Yadlapati | 71abefe | 2023-01-10 22:22:09 -0600 | [diff] [blame] | 57 | "FabricAdapter", |
| 58 | "FabricAdapterCollection", |
George Liu | 1a7b377 | 2022-09-29 09:29:18 +0800 | [diff] [blame] | 59 | "Fan", |
| 60 | "FanCollection", |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 61 | "IPAddresses", |
| 62 | "JsonSchemaFile", |
| 63 | "JsonSchemaFileCollection", # redfish/v1/JsonSchemas |
| 64 | "LogEntry", |
| 65 | "LogEntryCollection", |
| 66 | "LogService", |
| 67 | "LogServiceCollection", |
| 68 | "Manager", |
| 69 | "ManagerAccount", |
| 70 | "ManagerAccountCollection", |
| 71 | "ManagerCollection", |
| 72 | "ManagerDiagnosticData", |
| 73 | "ManagerNetworkProtocol", |
| 74 | "Memory", |
| 75 | "MemoryCollection", |
| 76 | "Message", |
| 77 | "MessageRegistry", |
| 78 | "MessageRegistryCollection", |
| 79 | "MessageRegistryFile", |
| 80 | "MessageRegistryFileCollection", |
| 81 | "MetricDefinition", |
| 82 | "MetricDefinitionCollection", |
| 83 | "MetricReport", |
| 84 | "MetricReportCollection", |
| 85 | "MetricReportDefinition", |
| 86 | "MetricReportDefinitionCollection", |
| 87 | "OperatingConfig", |
| 88 | "OperatingConfigCollection", |
| 89 | "PCIeDevice", |
| 90 | "PCIeDeviceCollection", |
| 91 | "PCIeFunction", |
| 92 | "PCIeFunctionCollection", |
| 93 | "PhysicalContext", |
| 94 | "PCIeSlots", |
George Liu | 7da1c58 | 2023-02-21 14:38:49 +0800 | [diff] [blame] | 95 | "Port", |
| 96 | "PortCollection", |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 97 | "Power", |
Chicago Duan | fe9bd2d | 2022-09-30 18:03:05 +0800 | [diff] [blame] | 98 | "PowerSubsystem", |
| 99 | "PowerSupply", |
| 100 | "PowerSupplyCollection", |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 101 | "Privileges", # Used in Role |
| 102 | "Processor", |
| 103 | "ProcessorCollection", |
| 104 | "RedfishError", |
| 105 | "RedfishExtensions", |
| 106 | "Redundancy", |
| 107 | "Resource", |
| 108 | "Role", |
| 109 | "RoleCollection", |
| 110 | "Sensor", |
| 111 | "SensorCollection", |
| 112 | "ServiceRoot", |
| 113 | "Session", |
| 114 | "SessionCollection", |
| 115 | "SessionService", |
| 116 | "Settings", |
| 117 | "SoftwareInventory", |
| 118 | "SoftwareInventoryCollection", |
| 119 | "Storage", |
| 120 | "StorageCollection", |
| 121 | "StorageController", |
| 122 | "StorageControllerCollection", |
| 123 | "Task", |
| 124 | "TaskCollection", |
| 125 | "TaskService", |
| 126 | "TelemetryService", |
| 127 | "Thermal", |
George Liu | f1240b4 | 2022-10-28 17:26:15 +0800 | [diff] [blame] | 128 | "ThermalMetrics", |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 129 | "ThermalSubsystem", |
| 130 | "Triggers", |
| 131 | "TriggersCollection", |
| 132 | "UpdateService", |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 133 | "VirtualMedia", |
| 134 | "VirtualMediaCollection", |
| 135 | "odata", |
| 136 | "odata-v4", |
| 137 | "redfish-error", |
| 138 | "redfish-payload-annotations", |
| 139 | "redfish-schema", |
| 140 | "redfish-schema-v1", |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 141 | ] |
| 142 | |
Myung Bae | 480662d | 2023-10-04 07:19:38 -0700 | [diff] [blame] | 143 | # OEM schemas |
| 144 | oem_schema_names = [ |
| 145 | "OemManager", |
| 146 | "OemComputerSystem", |
| 147 | "OemVirtualMedia", |
| 148 | "OpenBMCAccountService", |
| 149 | ] |
| 150 | |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 151 | SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 152 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 153 | proxies = {"https": os.environ.get("https_proxy", None)} |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 154 | |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 155 | r = requests.get( |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 156 | "https://www.dmtf.org/sites/default/files/standards/documents/" |
| 157 | + VERSION |
| 158 | + ".zip", |
| 159 | proxies=proxies, |
| 160 | ) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 161 | |
| 162 | r.raise_for_status() |
| 163 | |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 164 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 165 | static_path = os.path.realpath( |
| 166 | os.path.join(SCRIPT_DIR, "..", "static", "redfish", "v1") |
| 167 | ) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 168 | |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 169 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 170 | cpp_path = os.path.realpath( |
| 171 | os.path.join(SCRIPT_DIR, "..", "redfish-core", "include") |
| 172 | ) |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 173 | |
| 174 | |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 175 | schema_path = os.path.join(static_path, "schema") |
| 176 | json_schema_path = os.path.join(static_path, "JsonSchemas") |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 177 | metadata_index_path = os.path.join(static_path, "$metadata", "index.xml") |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 178 | |
| 179 | zipBytesIO = BytesIO(r.content) |
| 180 | zip_ref = zipfile.ZipFile(zipBytesIO) |
| 181 | |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 182 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 183 | class SchemaVersion: |
Patrick Williams | fd06b30 | 2022-12-12 10:39:42 -0600 | [diff] [blame] | 184 | """ |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 185 | A Python class for sorting Redfish schema versions. Allows sorting Redfish |
| 186 | versions in the way humans expect, by comparing version strings as lists |
| 187 | (ie 0_2_0 comes before 0_10_0) in the way humans expect. It does case |
| 188 | insensitive schema name comparisons |
Patrick Williams | fd06b30 | 2022-12-12 10:39:42 -0600 | [diff] [blame] | 189 | """ |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 190 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 191 | def __init__(self, key): |
| 192 | key = str.casefold(key) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 193 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 194 | split_tup = key.split(".") |
| 195 | self.version_pieces = [split_tup[0]] |
| 196 | if len(split_tup) < 2: |
| 197 | return |
| 198 | version = split_tup[1] |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 199 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 200 | if version.startswith("v"): |
| 201 | version = version[1:] |
| 202 | if any(char.isdigit() for char in version): |
Patrick Williams | fd06b30 | 2022-12-12 10:39:42 -0600 | [diff] [blame] | 203 | self.version_pieces.extend([int(x) for x in version.split("_")]) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 204 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 205 | def __lt__(self, other): |
| 206 | return self.version_pieces < other.version_pieces |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 207 | |
| 208 | |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 209 | # Remove the old files |
Ed Tanous | 5b5574a | 2022-09-26 19:53:36 -0700 | [diff] [blame] | 210 | skip_prefixes = ["Oem", "OpenBMC"] |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 211 | if os.path.exists(schema_path): |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 212 | files = [ |
| 213 | os.path.join(schema_path, f) |
| 214 | for f in os.listdir(schema_path) |
Ed Tanous | 5b5574a | 2022-09-26 19:53:36 -0700 | [diff] [blame] | 215 | if not any([f.startswith(prefix) for prefix in skip_prefixes]) |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 216 | ] |
James Feist | aee8d84 | 2018-09-10 16:07:40 -0700 | [diff] [blame] | 217 | for f in files: |
| 218 | os.remove(f) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 219 | if os.path.exists(json_schema_path): |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 220 | files = [ |
| 221 | os.path.join(json_schema_path, f) |
| 222 | for f in os.listdir(json_schema_path) |
Ed Tanous | 5b5574a | 2022-09-26 19:53:36 -0700 | [diff] [blame] | 223 | if not any([f.startswith(prefix) for prefix in skip_prefixes]) |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 224 | ] |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 225 | for f in files: |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 226 | if os.path.isfile(f): |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 227 | os.remove(f) |
| 228 | else: |
| 229 | shutil.rmtree(f) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 230 | try: |
| 231 | os.remove(metadata_index_path) |
| 232 | except FileNotFoundError: |
| 233 | pass |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 234 | |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 235 | if not os.path.exists(schema_path): |
| 236 | os.makedirs(schema_path) |
| 237 | if not os.path.exists(json_schema_path): |
| 238 | os.makedirs(json_schema_path) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 239 | |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 240 | csdl_filenames = [] |
| 241 | json_schema_files = defaultdict(list) |
| 242 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 243 | for zip_file in zip_ref.infolist(): |
| 244 | if zip_file.is_dir(): |
| 245 | continue |
| 246 | if zip_file.filename.startswith("csdl/"): |
| 247 | csdl_filenames.append(os.path.basename(zip_file.filename)) |
| 248 | elif zip_file.filename.startswith("json-schema/"): |
| 249 | filename = os.path.basename(zip_file.filename) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 250 | filenamesplit = filename.split(".") |
| 251 | # exclude schemas again to save flash space |
| 252 | if filenamesplit[0] not in include_list: |
| 253 | continue |
| 254 | json_schema_files[filenamesplit[0]].append(filename) |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 255 | elif zip_file.filename.startswith("openapi/"): |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 256 | pass |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 257 | elif zip_file.filename.startswith("dictionaries/"): |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 258 | pass |
| 259 | |
| 260 | # sort the json files by version |
| 261 | for key, value in json_schema_files.items(): |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 262 | value.sort(key=SchemaVersion, reverse=True) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 263 | |
| 264 | # Create a dictionary ordered by schema name |
| 265 | json_schema_files = OrderedDict( |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 266 | sorted(json_schema_files.items(), key=lambda x: SchemaVersion(x[0])) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 267 | ) |
| 268 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 269 | csdl_filenames.sort(key=SchemaVersion) |
Myung Bae | 480662d | 2023-10-04 07:19:38 -0700 | [diff] [blame] | 270 | |
| 271 | # Create oem filenames - from oem json names |
| 272 | oem_csdl_filenames = [] |
| 273 | for filename in oem_schema_names: |
| 274 | oem_csdl_filenames.append(filename + "_v1.xml") |
| 275 | |
| 276 | # Append Oem csdl files |
| 277 | csdl_filenames += oem_csdl_filenames |
| 278 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 279 | with open(metadata_index_path, "w") as metadata_index: |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 280 | metadata_index.write('<?xml version="1.0" encoding="UTF-8"?>\n') |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 281 | metadata_index.write( |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 282 | "<edmx:Edmx xmlns:edmx=" |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 283 | '"http://docs.oasis-open.org/odata/ns/edmx"' |
| 284 | ' Version="4.0">\n' |
| 285 | ) |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 286 | |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 287 | for filename in csdl_filenames: |
| 288 | # filename looks like Zone_v1.xml |
Myung Bae | 480662d | 2023-10-04 07:19:38 -0700 | [diff] [blame] | 289 | if filename in oem_csdl_filenames: |
| 290 | with open( |
| 291 | os.path.join(schema_path, filename), "rb" |
| 292 | ) as oem_csdl_in: |
| 293 | content = oem_csdl_in.read() |
| 294 | content = content.replace(b"\r\n", b"\n") |
| 295 | else: |
| 296 | with open(os.path.join(schema_path, filename), "wb") as schema_out: |
| 297 | content = zip_ref.read(os.path.join("csdl", filename)) |
| 298 | content = content.replace(b"\r\n", b"\n") |
| 299 | schema_out.write(content) |
| 300 | filenamesplit = filename.split("_") |
| 301 | if filenamesplit[0] not in include_list: |
| 302 | continue |
Ed Tanous | 853c0dc | 2022-12-21 13:21:52 -0800 | [diff] [blame] | 303 | |
Myung Bae | 480662d | 2023-10-04 07:19:38 -0700 | [diff] [blame] | 304 | metadata_index.write( |
| 305 | ' <edmx:Reference Uri="/redfish/v1/schema/' + filename + '">\n' |
| 306 | ) |
Ed Tanous | 853c0dc | 2022-12-21 13:21:52 -0800 | [diff] [blame] | 307 | |
Myung Bae | 480662d | 2023-10-04 07:19:38 -0700 | [diff] [blame] | 308 | xml_root = ET.fromstring(content) |
| 309 | edmx = "{http://docs.oasis-open.org/odata/ns/edmx}" |
| 310 | edm = "{http://docs.oasis-open.org/odata/ns/edm}" |
| 311 | for edmx_child in xml_root: |
| 312 | if edmx_child.tag == edmx + "DataServices": |
| 313 | for data_child in edmx_child: |
| 314 | if data_child.tag == edm + "Schema": |
| 315 | namespace = data_child.attrib["Namespace"] |
| 316 | if namespace.startswith("RedfishExtensions"): |
| 317 | metadata_index.write( |
| 318 | ' <edmx:Include Namespace="' |
| 319 | + namespace |
| 320 | + '" Alias="Redfish"/>\n' |
| 321 | ) |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 322 | |
Myung Bae | 480662d | 2023-10-04 07:19:38 -0700 | [diff] [blame] | 323 | else: |
| 324 | metadata_index.write( |
| 325 | ' <edmx:Include Namespace="' |
| 326 | + namespace |
| 327 | + '"/>\n' |
| 328 | ) |
| 329 | metadata_index.write(" </edmx:Reference>\n") |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 330 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 331 | metadata_index.write( |
| 332 | " <edmx:DataServices>\n" |
| 333 | " <Schema " |
| 334 | 'xmlns="http://docs.oasis-open.org/odata/ns/edm" ' |
| 335 | 'Namespace="Service">\n' |
| 336 | ' <EntityContainer Name="Service" ' |
| 337 | 'Extends="ServiceRoot.v1_0_0.ServiceContainer"/>\n' |
| 338 | " </Schema>\n" |
| 339 | " </edmx:DataServices>\n" |
| 340 | ) |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 341 | metadata_index.write("</edmx:Edmx>\n") |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 342 | |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 343 | |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 344 | for schema, version in json_schema_files.items(): |
| 345 | zip_filepath = os.path.join("json-schema", version[0]) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 346 | schemadir = os.path.join(json_schema_path, schema) |
| 347 | os.makedirs(schemadir) |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 348 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 349 | with open(os.path.join(schemadir, schema + ".json"), "wb") as schema_file: |
| 350 | schema_file.write(zip_ref.read(zip_filepath).replace(b"\r\n", b"\n")) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 351 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 352 | with open(os.path.join(cpp_path, "schemas.hpp"), "w") as hpp_file: |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 353 | hpp_file.write( |
| 354 | "#pragma once\n" |
| 355 | "{WARNING}\n" |
| 356 | "// clang-format off\n" |
Ed Tanous | 3d69fed | 2022-09-26 20:10:42 -0700 | [diff] [blame] | 357 | "#include <array>\n" |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 358 | "\n" |
| 359 | "namespace redfish\n" |
| 360 | "{{\n" |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 361 | " constexpr std::array schemas {{\n".format(WARNING=WARNING) |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 362 | ) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 363 | for schema_file in json_schema_files: |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 364 | hpp_file.write(' "{}",\n'.format(schema_file)) |
| 365 | |
Myung Bae | 480662d | 2023-10-04 07:19:38 -0700 | [diff] [blame] | 366 | for schema_file in oem_schema_names: |
| 367 | hpp_file.write(' "{}",\n'.format(schema_file)) |
| 368 | |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 369 | hpp_file.write(" };\n}\n") |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 370 | |
| 371 | zip_ref.close() |
Ed Tanous | 0ec8b83 | 2022-03-14 14:56:47 -0700 | [diff] [blame] | 372 | |
| 373 | generate_schema_enums.main() |
Carson Labrado | 9e03140 | 2022-07-08 20:56:52 +0000 | [diff] [blame] | 374 | generate_top_collections() |
Ed Tanous | 853c0dc | 2022-12-21 13:21:52 -0800 | [diff] [blame] | 375 | |
| 376 | # Now delete the xml schema files we aren't supporting |
| 377 | if os.path.exists(schema_path): |
| 378 | files = [ |
| 379 | os.path.join(schema_path, f) |
| 380 | for f in os.listdir(schema_path) |
Ed Tanous | 5b5574a | 2022-09-26 19:53:36 -0700 | [diff] [blame] | 381 | if not any([f.startswith(prefix) for prefix in skip_prefixes]) |
Ed Tanous | 853c0dc | 2022-12-21 13:21:52 -0800 | [diff] [blame] | 382 | ] |
| 383 | for filename in files: |
| 384 | # filename will include the absolute path |
| 385 | filenamesplit = filename.split("/") |
| 386 | name = filenamesplit.pop() |
| 387 | namesplit = name.split("_") |
| 388 | if namesplit[0] not in include_list: |
| 389 | print("excluding schema: " + filename) |
| 390 | os.remove(filename) |