Python installer for thrift idl compiler
authorMarc Slemko <marc@apache.org>
Thu, 17 Aug 2006 01:12:11 +0000 (01:12 +0000)
committerMarc Slemko <marc@apache.org>
Thu, 17 Aug 2006 01:12:11 +0000 (01:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664760 13f79535-47bb-0310-9956-ffa450edef68

compiler/setup.py [new file with mode: 0644]
compiler/src/cpp_generator.py
compiler/src/thrift.py

diff --git a/compiler/setup.py b/compiler/setup.py
new file mode 100644 (file)
index 0000000..d5bbae8
--- /dev/null
@@ -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']
+      )
+
index fd25e17..f1bf84c 100644 (file)
@@ -2,8 +2,8 @@ import time
 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 @@ def toServerServiceDefinition(service, debugp=None):
        
        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)
 
index 9282620..39bdb16 100644 (file)
@@ -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 @@ if __name__ == '__main__':
 
     filename = args[-1]
 
-    p = parser.Parser(debug=debug)
-
-    p.parse(filename, False)
+    result = thrift(filename, cpp, java, perl, php, python, ruby, debug)
 
-    if len(p.errors):
-       sys.exit(-1)
+    sys.exit(result)
 
-    [g(p.program, filename) for g in generators]
+if __name__ == '__main__':
+    main(sys.argv)