mirror of
https://github.com/haiwen/libsearpc.git
synced 2025-09-12 01:59:33 +00:00
Make searpc-codegen python3-compatible. (#28)
This commit is contained in:
3
debian/control
vendored
3
debian/control
vendored
@@ -30,8 +30,7 @@ Section: libdevel
|
|||||||
Architecture: any
|
Architecture: any
|
||||||
Depends:
|
Depends:
|
||||||
${misc:Depends},
|
${misc:Depends},
|
||||||
python2 (>= 2.7) | python (>= 2.7),
|
python (>= 2.7),
|
||||||
python2 (<< 2.8) | python (<< 2.8),
|
|
||||||
libsearpc1 (= ${binary:Version})
|
libsearpc1 (= ${binary:Version})
|
||||||
Conflicts: seafile
|
Conflicts: seafile
|
||||||
Description: Development files for the libsearpc1 package.
|
Description: Development files for the libsearpc1 package.
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Generate function define macros.
|
Generate function define macros.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
@@ -106,10 +107,14 @@ def generate_marshal(ret_type, arg_types):
|
|||||||
func_call=func_call,
|
func_call=func_call,
|
||||||
convert_ret=convert_ret)
|
convert_ret=convert_ret)
|
||||||
|
|
||||||
|
def write_file(f, s):
|
||||||
|
f.write(s)
|
||||||
|
f.write('\n')
|
||||||
|
|
||||||
def gen_marshal_functions(f):
|
def gen_marshal_functions(f):
|
||||||
from rpc_table import func_table
|
from rpc_table import func_table
|
||||||
for item in func_table:
|
for item in func_table:
|
||||||
print >>f, generate_marshal(item[0], item[1])
|
write_file(f, generate_marshal(item[0], item[1]))
|
||||||
|
|
||||||
|
|
||||||
marshal_register_item = r"""
|
marshal_register_item = r"""
|
||||||
@@ -136,11 +141,11 @@ def generate_marshal_register_item(ret_type, arg_types):
|
|||||||
|
|
||||||
def gen_marshal_register_function(f):
|
def gen_marshal_register_function(f):
|
||||||
from rpc_table import func_table
|
from rpc_table import func_table
|
||||||
print >>f, "static void register_marshals()"""
|
write_file(f, "static void register_marshals()""")
|
||||||
print >>f, "{"
|
write_file(f, "{")
|
||||||
for item in func_table:
|
for item in func_table:
|
||||||
print >>f, generate_marshal_register_item(item[0], item[1]),
|
write_file(f, generate_marshal_register_item(item[0], item[1]))
|
||||||
print >>f, "}"
|
write_file(f, "}")
|
||||||
|
|
||||||
signature_template = r"""
|
signature_template = r"""
|
||||||
inline static gchar *
|
inline static gchar *
|
||||||
@@ -168,11 +173,9 @@ def generate_signature(ret_type, arg_types):
|
|||||||
return template.substitute(signature_name=signature_name, args=args)
|
return template.substitute(signature_name=signature_name, args=args)
|
||||||
|
|
||||||
def gen_signature_list():
|
def gen_signature_list():
|
||||||
f = open('searpc-signature.h', 'w')
|
with open('searpc-signature.h', 'w') as f:
|
||||||
for item in func_table:
|
for item in func_table:
|
||||||
print >>f,generate_signature(item[0], item[1])
|
write_file(f, generate_signature(item[0], item[1]))
|
||||||
f.close()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.path.append(os.getcwd())
|
sys.path.append(os.getcwd())
|
||||||
@@ -180,20 +183,15 @@ if __name__ == "__main__":
|
|||||||
# load function table
|
# load function table
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
abspath = os.path.abspath(sys.argv[1])
|
abspath = os.path.abspath(sys.argv[1])
|
||||||
d = os.path.dirname(abspath)
|
with open(abspath, 'r') as fp:
|
||||||
f = os.path.basename(abspath)
|
exec(fp.read())
|
||||||
mod = f[:f.rfind('.')]
|
print("loaded func_table from %s" % abspath)
|
||||||
sys.path.append(d)
|
|
||||||
rpc_mod = __import__(mod, globals(), locals(), [], -1)
|
|
||||||
print "loaded func_table from %s" % (rpc_mod.__file__)
|
|
||||||
func_table = rpc_mod.func_table
|
|
||||||
else:
|
else:
|
||||||
# load from default rpc_table.py
|
# load from default rpc_table.py
|
||||||
from rpc_table import func_table
|
from rpc_table import func_table
|
||||||
|
|
||||||
# gen code
|
# gen code
|
||||||
marshal = open('searpc-marshal.h', 'w')
|
with open('searpc-marshal.h', 'w') as marshal:
|
||||||
gen_marshal_functions(marshal)
|
gen_marshal_functions(marshal)
|
||||||
gen_marshal_register_function(marshal)
|
gen_marshal_register_function(marshal)
|
||||||
marshal.close()
|
|
||||||
gen_signature_list()
|
gen_signature_list()
|
||||||
|
Reference in New Issue
Block a user