mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-08-03 08:21:58 +03:00
Update generator for new code layout
Change the generator.py to - Take XML API file names on command line - Generate data in build/ directory instead of cwd
This commit is contained in:
65
generator.py
65
generator.py
@ -17,17 +17,10 @@ import re
|
|||||||
|
|
||||||
quiet=True
|
quiet=True
|
||||||
|
|
||||||
if __name__ == "__main__":
|
coreapifile = sys.argv[1]
|
||||||
# launched as a script
|
lxcapifile = sys.argv[2]
|
||||||
srcPref = os.path.dirname(sys.argv[0])
|
qemuapifile = sys.argv[3]
|
||||||
if len(sys.argv) > 1:
|
|
||||||
python = sys.argv[1]
|
|
||||||
else:
|
|
||||||
print "Python binary not specified"
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
# imported
|
|
||||||
srcPref = os.path.dirname(__file__)
|
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
@ -777,7 +770,7 @@ def print_function_wrapper(module, name, output, export, include):
|
|||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def buildStubs(module):
|
def buildStubs(module, api_xml):
|
||||||
global py_types
|
global py_types
|
||||||
global py_return_types
|
global py_return_types
|
||||||
global unknown_types
|
global unknown_types
|
||||||
@ -799,18 +792,8 @@ def buildStubs(module):
|
|||||||
funcs_failed = qemu_functions_failed
|
funcs_failed = qemu_functions_failed
|
||||||
funcs_skipped = qemu_functions_skipped
|
funcs_skipped = qemu_functions_skipped
|
||||||
|
|
||||||
api_xml = "%s-api.xml" % module
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = open(os.path.join(srcPref,api_xml))
|
f = open(api_xml)
|
||||||
data = f.read()
|
|
||||||
f.close()
|
|
||||||
(parser, target) = getparser()
|
|
||||||
parser.feed(data)
|
|
||||||
parser.close()
|
|
||||||
except IOError, msg:
|
|
||||||
try:
|
|
||||||
f = open(os.path.join(srcPref,"..","docs",api_xml))
|
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
(parser, target) = getparser()
|
(parser, target) = getparser()
|
||||||
@ -828,7 +811,7 @@ def buildStubs(module):
|
|||||||
py_types['pythonObject'] = ('O', "pythonObject", "pythonObject", "pythonObject")
|
py_types['pythonObject'] = ('O', "pythonObject", "pythonObject", "pythonObject")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = open(os.path.join(srcPref, override_api_xml))
|
f = open(override_api_xml)
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
(parser, target) = getparser()
|
(parser, target) = getparser()
|
||||||
@ -845,9 +828,9 @@ def buildStubs(module):
|
|||||||
failed = 0
|
failed = 0
|
||||||
skipped = 0
|
skipped = 0
|
||||||
|
|
||||||
header_file = "%s.h" % module
|
header_file = "build/%s.h" % module
|
||||||
export_file = "%s-export.c" % module
|
export_file = "build/%s-export.c" % module
|
||||||
wrapper_file = "%s.c" % module
|
wrapper_file = "build/%s.c" % module
|
||||||
|
|
||||||
include = open(header_file, "w")
|
include = open(header_file, "w")
|
||||||
include.write("/* Generated */\n\n")
|
include.write("/* Generated */\n\n")
|
||||||
@ -857,11 +840,10 @@ def buildStubs(module):
|
|||||||
|
|
||||||
wrapper = open(wrapper_file, "w")
|
wrapper = open(wrapper_file, "w")
|
||||||
wrapper.write("/* Generated by generator.py */\n\n")
|
wrapper.write("/* Generated by generator.py */\n\n")
|
||||||
wrapper.write("#include <config.h>\n")
|
|
||||||
wrapper.write("#include <Python.h>\n")
|
wrapper.write("#include <Python.h>\n")
|
||||||
wrapper.write("#include <libvirt/" + module + ".h>\n")
|
wrapper.write("#include <libvirt/" + module + ".h>\n")
|
||||||
wrapper.write("#include \"typewrappers.h\"\n")
|
wrapper.write("#include \"typewrappers.h\"\n")
|
||||||
wrapper.write("#include \"" + module + ".h\"\n\n")
|
wrapper.write("#include \"build/" + module + ".h\"\n\n")
|
||||||
|
|
||||||
for function in funcs.keys():
|
for function in funcs.keys():
|
||||||
# Skip the functions which are not for the module
|
# Skip the functions which are not for the module
|
||||||
@ -1283,15 +1265,14 @@ def buildWrappers(module):
|
|||||||
info = (0, func, name, ret, args, file, mod)
|
info = (0, func, name, ret, args, file, mod)
|
||||||
function_classes['None'].append(info)
|
function_classes['None'].append(info)
|
||||||
|
|
||||||
classes_file = "%s.py" % module
|
classes_file = "build/%s.py" % module
|
||||||
extra_file = os.path.join(srcPref, "%s-override.py" % module)
|
extra_file = "%s-override.py" % module
|
||||||
extra = None
|
extra = None
|
||||||
|
|
||||||
classes = open(classes_file, "w")
|
classes = open(classes_file, "w")
|
||||||
|
|
||||||
if os.path.exists(extra_file):
|
if os.path.exists(extra_file):
|
||||||
extra = open(extra_file, "r")
|
extra = open(extra_file, "r")
|
||||||
classes.write("#! " + python + " -i\n")
|
|
||||||
classes.write("#\n")
|
classes.write("#\n")
|
||||||
classes.write("# WARNING WARNING WARNING WARNING\n")
|
classes.write("# WARNING WARNING WARNING WARNING\n")
|
||||||
classes.write("#\n")
|
classes.write("#\n")
|
||||||
@ -1716,7 +1697,7 @@ def buildWrappers(module):
|
|||||||
classes.write("\n")
|
classes.write("\n")
|
||||||
# Append "<classname>.py" to class def, iff it exists
|
# Append "<classname>.py" to class def, iff it exists
|
||||||
try:
|
try:
|
||||||
extra = open(os.path.join(srcPref,"libvirt-override-" + classname + ".py"), "r")
|
extra = open("libvirt-override-" + classname + ".py", "r")
|
||||||
classes.write (" #\n")
|
classes.write (" #\n")
|
||||||
classes.write (" # %s methods from %s.py (hand coded)\n" % (classname,classname))
|
classes.write (" # %s methods from %s.py (hand coded)\n" % (classname,classname))
|
||||||
classes.write (" #\n")
|
classes.write (" #\n")
|
||||||
@ -1746,14 +1727,13 @@ def qemuBuildWrappers(module):
|
|||||||
print "ERROR: only libvirt-qemu is supported"
|
print "ERROR: only libvirt-qemu is supported"
|
||||||
return None
|
return None
|
||||||
|
|
||||||
extra_file = os.path.join(srcPref, "%s-override.py" % module)
|
extra_file = "%s-override.py" % module
|
||||||
extra = None
|
extra = None
|
||||||
|
|
||||||
fd = open("libvirt_qemu.py", "w")
|
fd = open("build/libvirt_qemu.py", "w")
|
||||||
|
|
||||||
if os.path.exists(extra_file):
|
if os.path.exists(extra_file):
|
||||||
extra = open(extra_file, "r")
|
extra = open(extra_file, "r")
|
||||||
fd.write("#! " + python + " -i\n")
|
|
||||||
fd.write("#\n")
|
fd.write("#\n")
|
||||||
fd.write("# WARNING WARNING WARNING WARNING\n")
|
fd.write("# WARNING WARNING WARNING WARNING\n")
|
||||||
fd.write("#\n")
|
fd.write("#\n")
|
||||||
@ -1858,14 +1838,13 @@ def lxcBuildWrappers(module):
|
|||||||
print "ERROR: only libvirt-lxc is supported"
|
print "ERROR: only libvirt-lxc is supported"
|
||||||
return None
|
return None
|
||||||
|
|
||||||
extra_file = os.path.join(srcPref, "%s-override.py" % module)
|
extra_file = "%s-override.py" % module
|
||||||
extra = None
|
extra = None
|
||||||
|
|
||||||
fd = open("libvirt_lxc.py", "w")
|
fd = open("build/libvirt_lxc.py", "w")
|
||||||
|
|
||||||
if os.path.exists(extra_file):
|
if os.path.exists(extra_file):
|
||||||
extra = open(extra_file, "r")
|
extra = open(extra_file, "r")
|
||||||
fd.write("#! " + python + " -i\n")
|
|
||||||
fd.write("#\n")
|
fd.write("#\n")
|
||||||
fd.write("# WARNING WARNING WARNING WARNING\n")
|
fd.write("# WARNING WARNING WARNING WARNING\n")
|
||||||
fd.write("#\n")
|
fd.write("#\n")
|
||||||
@ -1964,11 +1943,13 @@ def lxcBuildWrappers(module):
|
|||||||
|
|
||||||
|
|
||||||
quiet = 0
|
quiet = 0
|
||||||
if buildStubs("libvirt") < 0:
|
if not os.path.exists("build"):
|
||||||
|
os.mkdir("build")
|
||||||
|
if buildStubs("libvirt", coreapifile) < 0:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if buildStubs("libvirt-lxc") < 0:
|
if buildStubs("libvirt-lxc", lxcapifile) < 0:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if buildStubs("libvirt-qemu") < 0:
|
if buildStubs("libvirt-qemu", qemuapifile) < 0:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
buildWrappers("libvirt")
|
buildWrappers("libvirt")
|
||||||
lxcBuildWrappers("libvirt-lxc")
|
lxcBuildWrappers("libvirt-lxc")
|
||||||
|
Reference in New Issue
Block a user