Python installer for thrift idl compiler
    


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664760 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/setup.py b/compiler/setup.py
new file mode 100644
index 0000000..d5bbae8
--- /dev/null
+++ b/compiler/setup.py
@@ -0,0 +1,13 @@
+from distutils.core import setup
+
+setup(name='Thrift',
+      version='1.0',
+      description='Thrift IDL compiler',
+      author =['Mark Slee', 'Marc Kwiatkowski'],
+      author_email= ['mcslee@facebook.com', 'marc@facebook.com'],
+      url='http://code.facebook.com/thrift',
+      package_dir={'thrift' : 'src'},
+      py_modules = ['thrift.parser', 'thrift.cpp_generator', 'thrift.generator'],
+      scripts = ['src/thrift']
+      )
+
diff --git a/compiler/src/cpp_generator.py b/compiler/src/cpp_generator.py
index fd25e17..f1bf84c 100644
--- a/compiler/src/cpp_generator.py
+++ b/compiler/src/cpp_generator.py
@@ -2,8 +2,8 @@
 import os
 import os.path
 from string import Template
-from parser import *
-from generator import *
+from thrift.parser import *
+from thrift.generator import *
 
 HEADER_COMMENT = """/**
  * Autogenerated by Thrift
@@ -529,7 +529,7 @@
 	
 	result+= toServerFunctionDefinition(service.name, function, debugp)
     
-    callProcessSwitch = "        if"+string.join(["(name.compare(\""+function.name+"\") == 0) { process_"+function.name+"(seqid, itrans, otrans);\n}" for function in service.functionList], "\n        else if")+" else {throw "+CPP_EXCEPTION+"(\"Unknown function name \\\"\"+name+\"\\\"\");}"
+    callProcessSwitch = "        if"+string.join(["(name.compare(\""+function.name+"\") == 0) {\n            process_"+function.name+"(seqid, itrans, otrans);\n        }" for function in service.functionList], " else if")+" else {\n            throw "+CPP_EXCEPTION+"(\"Unknown function name \\\"\"+name+\"\\\"\");\n        }"
 
     result+= CPP_SERVER_PROCESS_DEFINITION.substitute(service=service.name, callProcessSwitch=callProcessSwitch)
 
diff --git a/compiler/src/thrift.py b/compiler/src/thrift.py
index 9282620..39bdb16 100644
--- a/compiler/src/thrift.py
+++ b/compiler/src/thrift.py
@@ -1,18 +1,41 @@
+#!python
 import sys
-import generator
-import cpp_generator
-import parser
+from thrift import cpp_generator
+from thrift import generator
+from thrift import parser
 
-if __name__ == '__main__':
-
-    args = sys.argv[1:]
+def thrift(source, cpp=False, perl=False, php=False, python=False, java=False, ruby=False, debug=False):
 
     generators = []
 
+    if cpp:
+	generators.append(cpp_generator.CPPGenerator())
+    
+    p = parser.Parser(debug=debug)
+
+    p.parse(source, False)
+
+    for generator in generators:
+	generator(p.program, source)
+
+    if len(p.errors):
+	return -1
+    else:
+	return 0
+
+def main(args):
+
+    cpp = False
+    perl = False
+    php = False
+    python = False
+    java = False
+    ruby = False
+
     debug = False
 
     if "--cpp" in args:
-	generators.append(cpp_generator.CPPGenerator())
+	cpp = True
 	args.remove("--cpp")
     if "--debug" in args:
 	debug = True
@@ -20,12 +43,10 @@
 
     filename = args[-1]
 
-    p = parser.Parser(debug=debug)
+    result = thrift(filename, cpp, java, perl, php, python, ruby, debug)
 
-    p.parse(filename, False)
+    sys.exit(result)
 
-    if len(p.errors):
-	sys.exit(-1)
-
-    [g(p.program, filename) for g in generators]
+if __name__ == '__main__':
+    main(sys.argv)