parse_registry: make the script more flexible

Now it supports updating individual registry. Run parse_registries.py to
see all the options. This speeds up development of the script itself:
e.g., when developing privilege related generator, we don't want to
regenerate other headers every time during development.

```
usage: parse_registries.py [-h] [--registries REGISTRIES]

options:
  -h, --help            show this help message and exit
  --registries REGISTRIES
                        Comma delimited list of registries to update
```

```
[hi on] nanzhou@nanzhou:~/Desktop/bmcweb$ time scripts/parse_registries.py

real    0m1.493s
user    0m0.401s
sys     0m0.046s
[hi on] nanzhou@nanzhou:~/Desktop/bmcweb$ time scripts/parse_registries.py --registries privilege

real    0m0.667s
user    0m0.213s
sys     0m0.030s
```

This saves 50% of the time. Though the absolute time to generate a full
list if small.

By default, it generates all the registries.

Tested: tested the script, it can update headers correctly.

Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: If13748a605a462f5dc7d83bad52360942b7dc6b7
diff --git a/scripts/parse_registries.py b/scripts/parse_registries.py
index bc54657..bfe87ef 100755
--- a/scripts/parse_registries.py
+++ b/scripts/parse_registries.py
@@ -3,6 +3,7 @@
 import os
 
 import requests
+import argparse
 
 PRAGMA_ONCE = '''#pragma once
 '''
@@ -53,90 +54,80 @@
     return (path, json_file, type_name, url)
 
 
-files = []
-files.append(make_getter('Base.1.13.0.json',
-                         'base_message_registry.hpp',
-                         'base'))
-files.append(make_getter('TaskEvent.1.0.3.json',
-                         'task_event_message_registry.hpp',
-                         'task_event'))
-files.append(make_getter('ResourceEvent.1.0.3.json',
-                         'resource_event_message_registry.hpp',
-                         'resource_event'))
+def update_registries(files):
+    # Remove the old files
+    for file, json_dict, namespace, url in files:
+        try:
+            os.remove(file)
+        except BaseException:
+            print("{} not found".format(file))
 
-# Remove the old files
-for file, json_dict, namespace, url in files:
-    try:
-        os.remove(file)
-    except BaseException:
-        print("{} not found".format(file))
-
-    with open(file, 'w') as registry:
-        registry.write(REGISTRY_HEADER.format(namespace))
-        # Parse the Registry header info
-        registry.write(
-            "const Header header = {{\n"
-            "    \"{json_dict[@Redfish.Copyright]}\",\n"
-            "    \"{json_dict[@odata.type]}\",\n"
-            "    \"{json_dict[Id]}\",\n"
-            "    \"{json_dict[Name]}\",\n"
-            "    \"{json_dict[Language]}\",\n"
-            "    \"{json_dict[Description]}\",\n"
-            "    \"{json_dict[RegistryPrefix]}\",\n"
-            "    \"{json_dict[RegistryVersion]}\",\n"
-            "    \"{json_dict[OwningEntity]}\",\n"
-            "}};\n"
-            "constexpr const char* url =\n"
-            "    \"{url}\";\n"
-            "\n"
-            "constexpr std::array registry =\n"
-            "{{\n".format(
-                json_dict=json_dict,
-                url=url,
-            ))
-
-        messages_sorted = sorted(json_dict["Messages"].items())
-        for messageId, message in messages_sorted:
+        with open(file, 'w') as registry:
+            registry.write(REGISTRY_HEADER.format(namespace))
+            # Parse the Registry header info
             registry.write(
-                "    MessageEntry{{\n"
-                "        \"{messageId}\",\n"
-                "        {{\n"
-                "            \"{message[Description]}\",\n"
-                "            \"{message[Message]}\",\n"
-                "            \"{message[MessageSeverity]}\",\n"
-                "            {message[NumberOfArgs]},\n"
-                "            {{".format(
-                    messageId=messageId,
-                    message=message
+                "const Header header = {{\n"
+                "    \"{json_dict[@Redfish.Copyright]}\",\n"
+                "    \"{json_dict[@odata.type]}\",\n"
+                "    \"{json_dict[Id]}\",\n"
+                "    \"{json_dict[Name]}\",\n"
+                "    \"{json_dict[Language]}\",\n"
+                "    \"{json_dict[Description]}\",\n"
+                "    \"{json_dict[RegistryPrefix]}\",\n"
+                "    \"{json_dict[RegistryVersion]}\",\n"
+                "    \"{json_dict[OwningEntity]}\",\n"
+                "}};\n"
+                "constexpr const char* url =\n"
+                "    \"{url}\";\n"
+                "\n"
+                "constexpr std::array registry =\n"
+                "{{\n".format(
+                    json_dict=json_dict,
+                    url=url,
                 ))
-            paramTypes = message.get("ParamTypes")
-            if paramTypes:
-                for paramType in paramTypes:
-                    registry.write(
-                        "\n"
-                        "                \"{}\",".format(paramType)
-                    )
-                registry.write("\n            },\n")
-            else:
-                registry.write("},\n")
-            registry.write(
-                "            \"{message[Resolution]}\",\n"
-                "        }}}},\n".format(message=message))
 
-        registry.write(
-            "\n};\n"
-            "\n"
-            "enum class Index\n"
-            "{\n"
-        )
-        for index, (messageId, message) in enumerate(messages_sorted):
-            messageId = messageId[0].lower() + messageId[1:]
+            messages_sorted = sorted(json_dict["Messages"].items())
+            for messageId, message in messages_sorted:
+                registry.write(
+                    "    MessageEntry{{\n"
+                    "        \"{messageId}\",\n"
+                    "        {{\n"
+                    "            \"{message[Description]}\",\n"
+                    "            \"{message[Message]}\",\n"
+                    "            \"{message[MessageSeverity]}\",\n"
+                    "            {message[NumberOfArgs]},\n"
+                    "            {{".format(
+                        messageId=messageId,
+                        message=message
+                    ))
+                paramTypes = message.get("ParamTypes")
+                if paramTypes:
+                    for paramType in paramTypes:
+                        registry.write(
+                            "\n"
+                            "                \"{}\",".format(paramType)
+                        )
+                    registry.write("\n            },\n")
+                else:
+                    registry.write("},\n")
+                registry.write(
+                    "            \"{message[Resolution]}\",\n"
+                    "        }}}},\n".format(message=message))
+
             registry.write(
-                "    {} = {},\n".format(messageId, index))
-        registry.write(
-            "}};\n"
-            "}} // namespace redfish::registries::{}\n"
-            .format(namespace))
+                "\n};\n"
+                "\n"
+                "enum 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(
+                "}};\n"
+                "}} // namespace redfish::registries::{}\n"
+                .format(namespace))
 
 
 def get_privilege_string_from_list(privilege_list):
@@ -221,4 +212,36 @@
             "// clang-format on\n")
 
 
-make_privilege_registry()
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument(
+        '--registries', type=str,
+        default="base,task_event,resource_event,privilege",
+        help="Comma delimited list of registries to update")
+
+    args = parser.parse_args()
+
+    registries = set(args.registries.split(","))
+    files = []
+
+    if "base" in registries:
+        files.append(make_getter('Base.1.13.0.json',
+                                 'base_message_registry.hpp',
+                                 'base'))
+    if "task_event" in registries:
+        files.append(make_getter('TaskEvent.1.0.3.json',
+                                 'task_event_message_registry.hpp',
+                                 'task_event'))
+    if "resource_event" in registries:
+        files.append(make_getter('ResourceEvent.1.0.3.json',
+                                 'resource_event_message_registry.hpp',
+                                 'resource_event'))
+
+    update_registries(files)
+
+    if "privilege" in registries:
+        make_privilege_registry()
+
+
+if __name__ == "__main__":
+    main()