The method getVersion() retrieves the version of the libvirt library
that the binaries are linked against but there is no way to retrieve the
version of the bindings you are using. In the future if we support new
APIs in Python that don't rely on features in the library there needs to
be a way for programmers to detect the version.
---
I would expect there's a cleaner way to implement this than I've done
but I opted for what I saw as the smallest implementation. If anyone
has a suggestion for a better way to do this I'm ok with redoing this
patch.
---
 libvirt-override.py |  3 +++
 setup.py            | 16 ++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/libvirt-override.py b/libvirt-override.py
index 63f8ecb..ed8f73a 100644
--- a/libvirt-override.py
+++ b/libvirt-override.py
@@ -2,6 +2,9 @@
 # Manually written part of python bindings for libvirt
 #
 
+__version__ = '@VERSION@'
+version = @VER_TUPLE@
+
 # On cygwin, the DLL is called cygvirtmod.dll
 import sys
 
diff --git a/setup.py b/setup.py
index 24d4cf2..ad4f406 100755
--- a/setup.py
+++ b/setup.py
@@ -119,6 +119,21 @@ if have_libvirt_lxc:
 
 class my_build(build):
 
+    def gen_version(self, filename):
+        os.rename(filename, filename + '.tmp')
+
+        version = self.distribution.get_version()
+        ver_tuple = tuple(int(x) for x in version.split('.'))
+
+        f1 = open(filename + '.tmp', 'r')
+        f2 = open(filename, 'w')
+        for line in f1:
+            f2.write(line
+                    .replace('@VER_TUPLE@', str(ver_tuple))
+                    .replace('@VERSION@', version))
+        f1.close()
+        f2.close()
+
     def run(self):
         apis = get_api_xml_files()
 
@@ -127,6 +142,7 @@ class my_build(build):
         if have_libvirt_lxc:
             self.spawn([sys.executable, "generator.py", "libvirt-lxc", 
apis[2]])
 
+        self.gen_version('build/libvirt.py')
         build.run(self)
 
 class my_sdist(sdist):
-- 
1.8.3.2

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

Reply via email to