From c499ef86a2dfd4e7727ce876b6cf18ba79c94fe5 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Mon, 30 Sep 2013 09:05:14 +0200 Subject: gfapi.py: support dynamic loading of versioned libraries Currently gfapi.py only loads libraries by filename ending in ".so". On an installed system without development packages, the .so filenames are not available. ctypes.util.find_library() can be used to detect the files dynamically. In addition to this, also fixing some minor indention errors and package the library into the Python site-packages path. Python applications and libraries can now access libgfapi through 'from glusterfs import gfapi'. Change-Id: I71e38dabd3ade5dcf24813bf2fc25cda91b571c6 BUG: 1005146 Signed-off-by: Niels de Vos Reviewed-on: http://review.gluster.org/5835 Reviewed-by: Kaleb KEITHLEY Tested-by: Gluster Build System --- api/examples/gfapi.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'api/examples/gfapi.py') diff --git a/api/examples/gfapi.py b/api/examples/gfapi.py index 8d9ed7329..3ac67f4d5 100755 --- a/api/examples/gfapi.py +++ b/api/examples/gfapi.py @@ -1,6 +1,7 @@ #!/usr/bin/python from ctypes import * +from ctypes.util import find_library import os import sys import time @@ -8,9 +9,9 @@ import types # Looks like ctypes is having trouble with dependencies, so just force them to # load with RTLD_GLOBAL until I figure that out. -glfs = CDLL("libglusterfs.so",RTLD_GLOBAL) -xdr = CDLL("libgfxdr.so",RTLD_GLOBAL) -api = CDLL("libgfapi.so",RTLD_GLOBAL) +glfs = CDLL(find_library("glusterfs"),RTLD_GLOBAL) +xdr = CDLL(find_library("gfxdr"),RTLD_GLOBAL) +api = CDLL(find_library("gfapi"),RTLD_GLOBAL) # Wow, the Linux kernel folks really play nasty games with this structure. If # you look at the man page for stat(2) and then at this definition you'll note @@ -98,10 +99,12 @@ class File(object): def write (self, data, flags=0): return api.glfs_write(self.fd,data,len(data),flags) - def fallocate (self, mode, offset, len): - return api.glfs_fallocate(self.fd, mode, offset, len) - def discard (self, offset, len): - return api.glfs_discard(self.fd, offset, len) + def fallocate (self, mode, offset, len): + return api.glfs_fallocate(self.fd, mode, offset, len) + + def discard (self, offset, len): + return api.glfs_discard(self.fd, offset, len) + class Dir(object): @@ -381,7 +384,7 @@ if __name__ == "__main__": test_setxattr, test_getxattr, test_listxattr, - test_fallocate, + test_fallocate, ) ok_to_fail = ( -- cgit