[PATCH python] Skip copying manually written python for C APIs which don't exist

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

If the libvirt-override-virXXXX.py file has methods which call
C APIs that don't exist in the version of libvirt built against
we need to skip copying their code.

eg for 0.9.13 libvirt we should not copy the 'listAllDomains'
method.

The way this works is that it breaks the override file into
individual methods by looking for ' def '. It then collects
the contents until the next method start, whereupon it looks
for a libvirtmod.XXXXXX API call. It checks if the XXXXX part
is present in the XML description we have, and if not, it
discards the entire method.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 generator.py | 42 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/generator.py b/generator.py
index e8d8ea9..a9f98ab 100755
--- a/generator.py
+++ b/generator.py
@@ -1719,11 +1719,51 @@ def buildWrappers(module):
                 classes.write("\n")
             # Append "<classname>.py" to class def, iff it exists
             try:
+                wantfuncs = []
                 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")
-                classes.writelines(extra.readlines())
+                cached = None
+
+
+                # Since we compile with older libvirt, we don't want to pull
+                # in manually written python methods which call C methods
+                # that don't exist. This code attempts to detect which
+                # methods to skip by looking at the libvirtmod.XXXX calls
+
+                def shouldSkip(lines):
+                    for line in lines:
+                        offset = line.find("libvirtmod.")
+                        if offset != -1:
+                            func = line[offset + 11:]
+                            offset = func.find("(")
+                            func = func[0:offset]
+                            if func not in functions_skipped:
+                                return True
+                    return False
+
+                for line in extra.readlines():
+                    offset = line.find(" def ")
+                    if offset != -1:
+                        name = line[offset+5:]
+                        offset = name.find("(")
+                        name = name[0:offset]
+                        if cached is not None:
+                            if not shouldSkip(cached):
+                                classes.writelines(cached)
+                        if name == "__del__":
+                            cached = None
+                            classes.write(line)
+                        else:
+                            cached = [line]
+                    else:
+                        if cached is not None:
+                            cached.append(line)
+                        else:
+                            classes.write(line)
+                if not shouldSkip(cached):
+                    classes.writelines(cached)
                 classes.write("\n")
                 extra.close()
             except:
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]