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