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