Make schemas selectable

Which schemas are installed should be selectable in both a meson config,
and trivially by forks.  This commit gets us closer to that idea.

It does it in several ways, first, the code for generating
JsonSchemaFile resources has been changed to be generated at runtime,
based on files on disk.  This is slightly slower, but allows installing
schemas from anywhere, and matches the CSDL handling.

Next, the schema folders are separated into two sets
csdl -> This includes the complete schema pack from dmtf
installed -> this includes only the schemas the bmc includes

Similar folders exist for json-schema and json-schema-installed.

This allows any additional schemas to be a single symlink addition.
Note, this also checks in all of the dmtf json schemas, not just the
versions we use.  This allows us to update the schema pack without
needing to break our versions we ship.

Because the static files are now selectable, all files need to be in a
folder.  This forces the css and image for the redfish built-in gui to
be moved.

Tested:
/redfish/v1/JsonSchemas returns the correct result
/redfish/v1/JsonSchemas/UpdateService returns a JsonSchemaFile instance
/redfish/v1/JsonSchemas/UpdateService/UpdateService<version>json returns
the JsonSchemaFile contents.

Redfish service validator passes.

Change-Id: Ie96b2e4b623788dc2ec94eb40fcfd80325f0d826
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/scripts/update_schemas.py b/scripts/update_schemas.py
index febaf39..4207c53 100755
--- a/scripts/update_schemas.py
+++ b/scripts/update_schemas.py
@@ -11,17 +11,6 @@
 
 VERSION = "DSP8010_2024.1"
 
-WARNING = """/****************************************************************
- *                 READ THIS WARNING FIRST
- * This is an auto-generated header which contains definitions
- * for Redfish DMTF defined schemas.
- * DO NOT modify this registry outside of running the
- * update_schemas.py script.  The definitions contained within
- * this file are owned by DMTF.  Any modifications to these files
- * should be first pushed to the relevant registry in the DMTF
- * github organization.
- ***************************************************************/"""
-
 SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
 
 proxies = {"https": os.environ.get("https_proxy", None)}
@@ -35,22 +24,13 @@
 
 r.raise_for_status()
 
+redfish_core_path = os.path.join(SCRIPT_DIR, "..", "redfish-core")
 
-static_path = os.path.realpath(
-    os.path.join(SCRIPT_DIR, "..", "static", "redfish", "v1")
-)
+cpp_path = os.path.realpath(os.path.join(redfish_core_path, "include"))
 
-
-cpp_path = os.path.realpath(
-    os.path.join(SCRIPT_DIR, "..", "redfish-core", "include")
-)
-
-
-schema_path = os.path.join(
-    SCRIPT_DIR, "..", "redfish-core", "schema", "dmtf", "csdl"
-)
+schema_path = os.path.join(redfish_core_path, "schema", "dmtf", "csdl")
 json_schema_path = os.path.join(
-    SCRIPT_DIR, "..", "redfish-core", "schema", "dmtf", "json-schema"
+    redfish_core_path, "schema", "dmtf", "json-schema"
 )
 
 zipBytesIO = BytesIO(r.content)
@@ -83,36 +63,16 @@
         return self.version_pieces < other.version_pieces
 
 
-# Remove the old files
-skip_prefixes = ["Oem", "OpenBMC"]
-if os.path.exists(schema_path):
-    files = [
-        os.path.join(schema_path, f)
-        for f in os.listdir(schema_path)
-        if not any([f.startswith(prefix) for prefix in skip_prefixes])
-    ]
-    for f in files:
-        os.remove(f)
-if os.path.exists(json_schema_path):
-    files = [
-        os.path.join(json_schema_path, f)
-        for f in os.listdir(json_schema_path)
-        if not any([f.startswith(prefix) for prefix in skip_prefixes])
-    ]
-    for f in files:
-        if os.path.isfile(f):
-            os.remove(f)
-        else:
-            shutil.rmtree(f)
+shutil.rmtree(schema_path)
+os.makedirs(schema_path)
 
-if not os.path.exists(schema_path):
-    os.makedirs(schema_path)
-if not os.path.exists(json_schema_path):
-    os.makedirs(json_schema_path)
+shutil.rmtree(json_schema_path)
+os.makedirs(json_schema_path)
 
 csdl_filenames = []
 json_schema_files = defaultdict(list)
 
+
 for zip_file in zip_ref.infolist():
     if zip_file.is_dir():
         continue
@@ -135,44 +95,23 @@
 json_schema_files = OrderedDict(
     sorted(json_schema_files.items(), key=lambda x: SchemaVersion(x[0]))
 )
+
+
 for csdl_file in csdl_filenames:
     with open(os.path.join(schema_path, csdl_file), "wb") as schema_out:
         content = zip_ref.read(os.path.join("csdl", csdl_file))
         content = content.replace(b"\r\n", b"\n")
         schema_out.write(content)
 
-for schema, version in json_schema_files.items():
-    zip_filepath = os.path.join("json-schema", version[0])
+for schema_filename, versions in json_schema_files.items():
+    zip_filepath = os.path.join("json-schema", versions[0])
 
-    with open(os.path.join(json_schema_path, version[0]), "wb") as schema_file:
-        schema_file.write(zip_ref.read(zip_filepath).replace(b"\r\n", b"\n"))
-
-with open(os.path.join(cpp_path, "schemas.hpp"), "w") as hpp_file:
-    schemas = []
-    for root, dirs, files in os.walk(
-        os.path.join(SCRIPT_DIR, "..", "static", "redfish", "v1", "schema")
-    ):
-        for csdl_file in sorted(files, key=SchemaVersion):
-            if csdl_file.endswith(".xml"):
-                schemas.append(csdl_file.replace("_v1.xml", ""))
-    hpp_file.write(
-        "#pragma once\n"
-        "{WARNING}\n"
-        "// clang-format off\n"
-        "#include <array>\n"
-        "#include <string_view>\n"
-        "\n"
-        "namespace redfish\n"
-        "{{\n"
-        "    constexpr std::array<std::string_view,{SIZE}> schemas {{\n".format(
-            WARNING=WARNING,
-            SIZE=len(schemas),
-        )
-    )
-    for schema in schemas:
-        hpp_file.write('        "{}",\n'.format(schema))
-
-    hpp_file.write("    };\n}\n")
+    with open(
+        os.path.join(json_schema_path, versions[0]), "wb"
+    ) as schema_file:
+        content = zip_ref.read(zip_filepath)
+        content = content.replace(b"\r\n", b"\n")
+        schema_file.write(content)
 
 zip_ref.close()