privilege registry: simplify writing headers
This patch reused similar patterns in |REGISTRY_HEADER| so that the
python code is more readable. It also moved the clang-format off macro
and warning a bit in so they are all consistent with each other.
Tested: code compiles.
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: If18de0d9f89088f9b5732613ecf59520650bb11a
diff --git a/redfish-core/include/registries/base_message_registry.hpp b/redfish-core/include/registries/base_message_registry.hpp
index c030530..cf5861e 100644
--- a/redfish-core/include/registries/base_message_registry.hpp
+++ b/redfish-core/include/registries/base_message_registry.hpp
@@ -1,3 +1,4 @@
+#pragma once
/****************************************************************
* READ THIS WARNING FIRST
* This is an auto-generated header which contains definitions
@@ -8,7 +9,6 @@
* should be first pushed to the relevant registry in the DMTF
* github organization.
***************************************************************/
-#pragma once
#include <registries.hpp>
// clang-format off
diff --git a/redfish-core/include/registries/privilege_registry.hpp b/redfish-core/include/registries/privilege_registry.hpp
index 035aee4..d42d530 100644
--- a/redfish-core/include/registries/privilege_registry.hpp
+++ b/redfish-core/include/registries/privilege_registry.hpp
@@ -9,10 +9,10 @@
* should be first pushed to the relevant registry in the DMTF
* github organization.
***************************************************************/
-// clang-format off
-
#include <privileges.hpp>
+// clang-format off
+
namespace redfish::privileges
{
const std::array<Privileges, 1> privilegeSetLogin = {{
diff --git a/redfish-core/include/registries/resource_event_message_registry.hpp b/redfish-core/include/registries/resource_event_message_registry.hpp
index 3b02cde..d161882 100644
--- a/redfish-core/include/registries/resource_event_message_registry.hpp
+++ b/redfish-core/include/registries/resource_event_message_registry.hpp
@@ -1,3 +1,4 @@
+#pragma once
/****************************************************************
* READ THIS WARNING FIRST
* This is an auto-generated header which contains definitions
@@ -8,7 +9,6 @@
* should be first pushed to the relevant registry in the DMTF
* github organization.
***************************************************************/
-#pragma once
#include <registries.hpp>
// clang-format off
diff --git a/redfish-core/include/registries/task_event_message_registry.hpp b/redfish-core/include/registries/task_event_message_registry.hpp
index 5158ff4..94c74d1 100644
--- a/redfish-core/include/registries/task_event_message_registry.hpp
+++ b/redfish-core/include/registries/task_event_message_registry.hpp
@@ -1,3 +1,4 @@
+#pragma once
/****************************************************************
* READ THIS WARNING FIRST
* This is an auto-generated header which contains definitions
@@ -8,7 +9,6 @@
* should be first pushed to the relevant registry in the DMTF
* github organization.
***************************************************************/
-#pragma once
#include <registries.hpp>
// clang-format off
diff --git a/scripts/parse_registries.py b/scripts/parse_registries.py
index de560d8..8c300ed 100755
--- a/scripts/parse_registries.py
+++ b/scripts/parse_registries.py
@@ -4,6 +4,9 @@
import requests
+PRAGMA_ONCE = '''#pragma once
+'''
+
WARNING = '''/****************************************************************
* READ THIS WARNING FIRST
* This is an auto-generated header which contains definitions
@@ -15,8 +18,7 @@
* github organization.
***************************************************************/'''
-REGISTRY_HEADER = WARNING + '''
-#pragma once
+REGISTRY_HEADER = PRAGMA_ONCE + WARNING + '''
#include <registries.hpp>
// clang-format off
@@ -163,23 +165,22 @@
return "Or".join(names)
+PRIVILEGE_HEADER = PRAGMA_ONCE + WARNING + '''
+#include <privileges.hpp>
+
+// clang-format off
+
+namespace redfish::privileges
+{
+'''
+
+
def make_privilege_registry():
path, json_file, type_name, url = \
make_getter('Redfish_1.3.0_PrivilegeRegistry.json',
'privilege_registry.hpp', 'privilege')
with open(path, 'w') as registry:
- registry.write(
- "#pragma once\n"
- "{WARNING}\n"
- "// clang-format off\n"
- "\n"
- "#include <privileges.hpp>\n"
- "\n"
- "namespace redfish::privileges\n"
- "{{\n"
- .format(
- WARNING=WARNING,
- filename=os.path.basename(path)))
+ registry.write(PRIVILEGE_HEADER)
privilege_dict = {}
for mapping in json_file["Mappings"]: