Make parse_registries do whitespace properly

Previously, parse_registries was not very careful about generating
readable files, and relied on clang-format to "fix" them after the fact.
Given they're generated, this is unforunate, and leads to some
inconsistencies in reading the generated code.

This commit changes the script to no longer rely on clang-format, and
wrap the whole file in a clang-format off bracket.  This means that our
message registry generation will be consistent.

As an added bonus, different versions of clang-format like to format
these structures differently, so this removes one possible barrier to
people updating these.

This was initiated by the next patch in the series, which made a
seemingly minor change to a comment, which caused a significant change
in this file because of clang-format versioning.

Tested: ran parse_registries.py and saw build passing.  Whitespace
changes only.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Id48bb43dd9d8ecc83de1840f2f1045a87e2ff796
diff --git a/scripts/parse_registries.py b/scripts/parse_registries.py
index 8334eae..4973633 100755
--- a/scripts/parse_registries.py
+++ b/scripts/parse_registries.py
@@ -21,6 +21,8 @@
 #pragma once
 #include <registries.hpp>
 
+// clang-format off
+
 namespace redfish::message_registries::{}
 {{
 '''
@@ -49,10 +51,6 @@
     return (path, json_file, type_name, url)
 
 
-def clang_format(filename):
-    subprocess.check_call(["clang-format", "-i", filename])
-
-
 files = []
 files.append(make_getter('Base.1.11.0.json',
                          'base_message_registry.hpp',
@@ -74,54 +72,59 @@
     with open(file, 'w') as registry:
         registry.write(REGISTRY_HEADER.format(namespace))
         # Parse the Registry header info
-        registry.write("const Header header = {")
-        registry.write("\"{}\",".format(json_dict["@Redfish.Copyright"]))
-        registry.write("\"{}\",".format(json_dict["@odata.type"]))
-        registry.write("\"{}\",".format(json_dict["Id"]))
-        registry.write("\"{}\",".format(json_dict["Name"]))
-        registry.write("\"{}\",".format(json_dict["Language"]))
-        registry.write("\"{}\",".format(json_dict["Description"]))
-        registry.write("\"{}\",".format(json_dict["RegistryPrefix"]))
-        registry.write("\"{}\",".format(json_dict["RegistryVersion"]))
-        registry.write("\"{}\",".format(json_dict["OwningEntity"]))
-        registry.write("};")
+        registry.write("const Header header = {\n")
+        registry.write("    \"{}\",\n".format(json_dict["@Redfish.Copyright"]))
+        registry.write("    \"{}\",\n".format(json_dict["@odata.type"]))
+        registry.write("    \"{}\",\n".format(json_dict["Id"]))
+        registry.write("    \"{}\",\n".format(json_dict["Name"]))
+        registry.write("    \"{}\",\n".format(json_dict["Language"]))
+        registry.write("    \"{}\",\n".format(json_dict["Description"]))
+        registry.write("    \"{}\",\n".format(json_dict["RegistryPrefix"]))
+        registry.write("    \"{}\",\n".format(json_dict["RegistryVersion"]))
+        registry.write("    \"{}\",\n".format(json_dict["OwningEntity"]))
+        registry.write("};\n")
 
-        registry.write('constexpr const char * url = "{}";\n\n'.format(url))
+        registry.write(
+            'constexpr const char* url =\n    "{}";\n\n'.format(url))
         # Parse each Message entry
         registry.write(
-            "constexpr std::array<MessageEntry, {}> registry = {{".format(
+            "constexpr std::array<MessageEntry, {}> registry =\n".format(
                 len(json_dict["Messages"])))
-
+        registry.write("{\n")
         messages_sorted = sorted(json_dict["Messages"].items())
         for messageId, message in messages_sorted:
-            registry.write("MessageEntry{")
-            registry.write("\"{}\",".format(messageId))
-            registry.write("{")
-            registry.write("\"{}\",".format(message["Description"]))
-            registry.write("\"{}\",".format(message["Message"]))
-            registry.write("\"{}\",".format(message["Severity"]))
-            registry.write("\"{}\",".format(message["MessageSeverity"]))
-            registry.write("{},".format(message["NumberOfArgs"]))
-            registry.write("{")
+            registry.write("    MessageEntry{\n")
+            registry.write("        \"{}\",\n".format(messageId))
+            registry.write("        {\n")
+            registry.write("            \"{}\",\n".format(
+                message["Description"]))
+            registry.write("            \"{}\",\n".format(message["Message"]))
+            registry.write("            \"{}\",\n".format(message["Severity"]))
+            registry.write("            \"{}\",\n".format(
+                message["MessageSeverity"]))
+            registry.write("            {},\n".format(message["NumberOfArgs"]))
+            registry.write("            {")
             paramTypes = message.get("ParamTypes")
             if paramTypes:
                 for paramType in paramTypes:
-                    registry.write("\"{}\",".format(paramType))
-            registry.write("},")
-            registry.write("\"{}\",".format(message["Resolution"]))
-            registry.write("}},")
-
+                    registry.write(
+                        "\n                \"{}\",".format(paramType))
+                registry.write("\n            ")
+            registry.write("},\n")
+            registry.write("            \"{}\",\n".format(
+                message["Resolution"]))
+            registry.write("        }},\n")
         registry.write("\n};")
 
-        registry.write("\n\nenum class Index {\n")
+        registry.write("\n\nenum class Index\n{\n")
         for index, (messageId, message) in enumerate(messages_sorted):
             messageId = messageId[0].lower() + messageId[1:]
             registry.write(
-                "{} = {},\n".format(messageId, index))
-        registry.write("};")
-        registry.write("}")
-
-    clang_format(file)
+                "    {} = {},\n".format(messageId, index))
+        registry.write("};\n")
+        registry.write(
+            "} // namespace redfish::message_registries::")
+        registry.write("{}\n".format(namespace))
 
 
 def get_privilege_string_from_list(privilege_list):
@@ -159,11 +162,13 @@
     with open(path, 'w') as registry:
         registry.write("#pragma once\n")
         registry.write(
-            "//{} is generated.  Do not edit directly\n".format(
+            "// {} is generated.  Do not edit directly\n".format(
                 os.path.basename(path)))
 
-        registry.write("#include <privileges.hpp>\n\n")
-        registry.write("namespace redfish::privileges{\n")
+        registry.write("// clang-format off\n")
+        registry.write("\n#include <privileges.hpp>\n\n")
+        registry.write("namespace redfish::privileges\n")
+        registry.write("{\n")
 
         privilege_dict = {}
         for mapping in json_file["Mappings"]:
@@ -171,7 +176,6 @@
             for operation, privilege_list in mapping["OperationMap"].items():
                 privilege_dict[get_privilege_string_from_list(
                     privilege_list)] = (privilege_list, )
-        registry.write("// clang-format off\n")
         for index, key in enumerate(privilege_dict):
             (privilege_list, ) = privilege_dict[key]
             name = get_variable_name_for_privilege_set(privilege_list)
@@ -181,11 +185,10 @@
             registry.write(
                 "privilegeSet{} = {};\n".format(name, key))
             privilege_dict[key] = (privilege_list, name)
-        registry.write("// clang-format on\n\n")
 
         for mapping in json_file["Mappings"]:
             entity = mapping["Entity"]
-            registry.write("//{}\n".format(entity))
+            registry.write("// {}\n".format(entity))
             for operation, privilege_list in mapping["OperationMap"].items():
                 privilege_string = get_privilege_string_from_list(
                     privilege_list)
@@ -198,7 +201,7 @@
                         privilege_dict[privilege_string][1]))
             registry.write("\n")
         registry.write("} // namespace redfish::privileges\n")
-    clang_format(path)
+        registry.write("// clang-format on\n")
 
 
 make_privilege_registry()