Thrift and Python: Made to be together

Summary: Python client code generation for Thrift... HOTNESS!

Notes: Servers and asynchronous clients are coming soon...


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664779 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/Makefile b/compiler/cpp/Makefile
index b857e8c..b20ec3b 100644
--- a/compiler/cpp/Makefile
+++ b/compiler/cpp/Makefile
@@ -35,6 +35,7 @@
 # Source files
 SRC_FILES = main.cc \
             generate/t_generator.cc \
+            generate/t_py_generator.cc \
             generate/t_java_generator.cc \
             generate/t_php_generator.cc \
             generate/t_cpp_generator.cc
diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc
index 74b73b9..5b575b4 100644
--- a/compiler/cpp/src/generate/t_php_generator.cc
+++ b/compiler/cpp/src/generate/t_php_generator.cc
@@ -341,7 +341,7 @@
     php_includes();
 
   f_service_ <<
-    "require_once dirname(__FILE__).'/" << service_name_ << "_types.php';" << endl << endl;
+    "require_once dirname(__FILE__).'/" << program_name_ << "_types.php';" << endl << endl;
 
   // Generate the three main parts of the service (well, two for now in PHP)
   generate_service_interface(tservice);
@@ -1287,7 +1287,7 @@
       result += " = 0";
     } else if (type->is_container()) {
       result += " = array()";
-    } else if (type->is_struct()) {
+    } else if (type->is_struct() || type->is_xception()) {
       if (obj) {
         result += " = new " + type->get_name() + "()";
       } else {
diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc
index 944cd66..f75bd53 100644
--- a/compiler/cpp/src/main.cc
+++ b/compiler/cpp/src/main.cc
@@ -21,6 +21,7 @@
 #include "generate/t_cpp_generator.h"
 #include "generate/t_java_generator.h"
 #include "generate/t_php_generator.h"
+#include "generate/t_py_generator.h"
 
 using namespace std;
 
@@ -99,8 +100,8 @@
   fprintf(stderr, "  --java   Generate Java output files\n");
   fprintf(stderr, "  --php    Generate PHP output files\n");
   fprintf(stderr, "  --phpi   Generate PHP inlined files\n");
-  //fprintf(stderr, "  -python Generate Python output files\n");
-  fprintf(stderr, "  --debug      Print parse debugging to standard output\n");
+  fprintf(stderr, "  --py     Generate Python output files\n");
+  fprintf(stderr, "  --debug  Print parse debugging to standard output\n");
   exit(1);
 }
 
@@ -111,6 +112,7 @@
   int i;
   bool gen_cpp = false;
   bool gen_java = false;
+  bool gen_py = false;
   bool gen_php = false;
   bool php_inline = false;
 
@@ -136,13 +138,15 @@
     } else if (strcmp(argv[i], "--phpi") == 0) {
       gen_php = true;
       php_inline = true;
+    } else if (strcmp(argv[i], "--py") == 0) {
+      gen_py = true;
     } else {
       fprintf(stderr, "!!! Unrecognized option: %s\n", argv[i]);
       usage();
     }
   }
   
-  if (!gen_cpp && !gen_java && !gen_php) {
+  if (!gen_cpp && !gen_java && !gen_php && !gen_py) {
     fprintf(stderr, "!!! No output language(s) specified\n\n");
     usage();
   }
@@ -191,6 +195,12 @@
       php->generate_program(g_program);
       delete php;
     }
+
+    if (gen_py) {
+      t_py_generator* py = new t_py_generator();
+      py->generate_program(g_program);
+      delete py;
+    }
   } catch (string s) {
     printf("Error: %s\n", s.c_str());
   } catch (const char* exc) {