a3470f
From a7570af0bc6dc53044dce2cace9a65e96c571da6 Mon Sep 17 00:00:00 2001
a3470f
From: Aravinda VK <avishwan@redhat.com>
a3470f
Date: Mon, 19 Sep 2016 16:59:30 +0530
a3470f
Subject: [PATCH 20/74] eventsapi: Fix eventtypes.h header generation with
a3470f
 Python 2.4
a3470f
a3470f
eventskeygen.py file generates eventtypes.h and eventtypes.py files
a3470f
during build. If Python version is old(Version 2.4), then Gluster
a3470f
Client build will fail. eventskeygen.py uses "with" statement to
a3470f
open file, which is introduced in Python 2.5
a3470f
a3470f
Label: DOWNSTREAM ONLY
a3470f
a3470f
Change-Id: I995e102fad0c7bc66e840b1ab9d53ed564266253
a3470f
Signed-off-by: Aravinda VK <avishwan@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/85060
a3470f
Reviewed-by: Milind Changire <mchangir@redhat.com>
a3470f
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
a3470f
---
a3470f
 events/eventskeygen.py | 47 +++++++++++++++++++++++++----------------------
a3470f
 1 file changed, 25 insertions(+), 22 deletions(-)
a3470f
a3470f
diff --git a/events/eventskeygen.py b/events/eventskeygen.py
a3470f
index 23dfb47..a9c5573 100644
a3470f
--- a/events/eventskeygen.py
a3470f
+++ b/events/eventskeygen.py
a3470f
@@ -207,33 +207,36 @@ ERRORS = (
a3470f
 
a3470f
 if gen_header_type == "C_HEADER":
a3470f
     # Generate eventtypes.h
a3470f
-    with open(eventtypes_h, "w") as f:
a3470f
-        f.write("#ifndef __EVENTTYPES_H__\n")
a3470f
-        f.write("#define __EVENTTYPES_H__\n\n")
a3470f
-        f.write("typedef enum {\n")
a3470f
-        for k in ERRORS:
a3470f
-            f.write("    {0},\n".format(k))
a3470f
-        f.write("} event_errors_t;\n")
a3470f
+    f = open(eventtypes_h, "w")
a3470f
+    f.write("#ifndef __EVENTTYPES_H__\n")
a3470f
+    f.write("#define __EVENTTYPES_H__\n\n")
a3470f
+    f.write("typedef enum {\n")
a3470f
+    for k in ERRORS:
a3470f
+        f.write("    %s,\n" % k)
a3470f
+    f.write("} event_errors_t;\n")
a3470f
 
a3470f
-        f.write("\n")
a3470f
+    f.write("\n")
a3470f
 
a3470f
-        f.write("typedef enum {\n")
a3470f
-        for k in keys:
a3470f
-            f.write("    {0},\n".format(k))
a3470f
+    f.write("typedef enum {\n")
a3470f
+    for k in keys:
a3470f
+        f.write("    %s,\n" % k)
a3470f
 
a3470f
-        f.write("    {0}\n".format(LAST_EVENT))
a3470f
-        f.write("} eventtypes_t;\n")
a3470f
-        f.write("\n#endif /* __EVENTTYPES_H__ */\n")
a3470f
+    f.write("    %s\n" % LAST_EVENT)
a3470f
+    f.write("} eventtypes_t;\n")
a3470f
+    f.write("\n#endif /* __EVENTTYPES_H__ */\n")
a3470f
+    f.close()
a3470f
 
a3470f
 if gen_header_type == "PY_HEADER":
a3470f
     # Generate eventtypes.py
a3470f
-    with open(eventtypes_py, "w") as f:
a3470f
-        f.write("# -*- coding: utf-8 -*-\n")
a3470f
-        f.write("all_events = [\n")
a3470f
-        for ev in keys:
a3470f
-            f.write('    "{0}",\n'.format(ev))
a3470f
+    f = open(eventtypes_py, "w")
a3470f
+    f.write("# -*- coding: utf-8 -*-\n")
a3470f
+    f.write("all_events = [\n")
a3470f
+    for ev in keys:
a3470f
+        f.write('    "%s",\n' % ev)
a3470f
 
a3470f
-        f.write("]\n\n")
a3470f
+    f.write("]\n\n")
a3470f
 
a3470f
-        for idx, ev in enumerate(keys):
a3470f
-            f.write("{0} = {1}\n".format(ev.replace("EVENT_", ""), idx))
a3470f
+    for idx, ev in enumerate(keys):
a3470f
+        f.write("%s = %s\n" % (ev.replace("EVENT_", ""), idx))
a3470f
+
a3470f
+    f.close()
a3470f
-- 
a3470f
1.8.3.1
a3470f