From: "Daniel P. Berrange" <berrange@xxxxxxxxxx> Change the generator.py to - Take XML API file names on command line - Generate data in build/ directory instead of cwd --- generator.py | 69 ++++++++++++++++++++++-------------------------------------- 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/generator.py b/generator.py index fb321c6..8e0bb4c 100755 --- a/generator.py +++ b/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] + ####################################################################### # @@ -787,7 +780,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 @@ -809,26 +802,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: @@ -838,7 +821,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() @@ -855,9 +838,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") @@ -867,11 +850,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 @@ -1293,15 +1275,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") @@ -1726,7 +1707,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") @@ -1756,14 +1737,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") @@ -1868,14 +1848,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") @@ -1974,11 +1953,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") -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list