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