clean up ctypes python bindings sufficiently to let them rest

git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@9510 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Hans Ulrich Niedermann
2006-12-06 00:46:20 +00:00
parent f34497ee0e
commit 44ae87a01d
2 changed files with 43 additions and 28 deletions

View File

@@ -21,15 +21,38 @@
########################################################################
import ctypes
import ctypes.util
import ctypes as __ctypes
########################################################################
# Note on exported python symbols:
# As long as we can make all non-exported symbols in this module start
# with "__" (even the imported modules!), we can keep the exported
# namespace clean even without maintaining __all__ explicityl.
#
# __all__ contains all python symbols to be automatically imported from
# this module via
#
# from this_module import *
#
# You may append more symbols later in this file.
#
# An automatic test case may compare this __all__ to the
# libgphoto2.sym and libgphoto2_port.sym files.
#__all__ = [
# "gp_library_version",
# "gp_port_library_version",
# "GPVersionVerbosity",
# "GP_VERSION_SHORT",
# "GP_VERSION_VERBOSE",
# ]
########################################################################
def __char_p_p_to_string_list(value):
"""Turn char** into ["foo", "bar", "bla"]"""
array_of_c_char_p = ctypes.c_char_p * 200 # FIXME: OUCH!
array_of_c_char_p = __ctypes.c_char_p * 200 # FIXME: OUCH!
blubb = array_of_c_char_p.from_address(value)
retval = []
for x in blubb:
@@ -37,37 +60,20 @@ def __char_p_p_to_string_list(value):
break
retval.append(x)
return retval
########################################################################
__gpp = ctypes.cdll.LoadLibrary("libgphoto2_port.so")
assert(__gpp)
__gp = ctypes.cdll.LoadLibrary("libgphoto2.so")
assert(__gp)
########################################################################
# __all__ contains all python symbols to be exported.
#
# You may append more symbols later in this file.
#
# An automatic test case may compare this __all__ to the
# libgphoto2.sym and libgphoto2_port.sym files.
__all__ = [
"gp_library_version",
"gp_port_library_version",
"GPVersionVerbosity",
"GP_VERSION_SHORT",
"GP_VERSION_VERBOSE",
]
__gpp = __ctypes.cdll.LoadLibrary("libgphoto2_port.so")
assert __gpp, "Error loading libgphoto2_port"
__gp = __ctypes.cdll.LoadLibrary("libgphoto2.so")
assert __gp, "Error loading libgphoto2"
########################################################################
# enum GPVersionVerbosity { GP_VERSION_SHORT, GP_VERSION_VERBOSE }
class GPVersionVerbosity(ctypes.c_int):
# typedef enum { GP_VERSION_SHORT, GP_VERSION_VERBOSE } GPVersionVerbosity;
class GPVersionVerbosity(__ctypes.c_int):
pass
GP_VERSION_SHORT = GPVersionVerbosity(0)
GP_VERSION_VERBOSE = GPVersionVerbosity(1)
@@ -79,7 +85,7 @@ gp_library_version.restype = __char_p_p_to_string_list
# char **gp_port_library_version(GPVersionVerbosity verbose);
gp_port_library_version = __gpp.gp_port_library_version
gp_port_library_version.argtypes = ( ctypes.c_int, )
gp_port_library_version.argtypes = ( GPVersionVerbosity, )
gp_port_library_version.restype = __char_p_p_to_string_list

View File

@@ -20,15 +20,24 @@
import sys
symbols_before = dir()
from ctypes_gphoto2 import *
symbols_after = dir()
########################################################################
from ctypes_gphoto2 import *
import pprint
########################################################################
def main(args, progname=None):
for x in symbols_before + ["symbols_before"]:
symbols_after.remove(x)
symbols_after.sort()
pprint.pprint(symbols_after)
for f in [
gp_library_version(GP_VERSION_SHORT),
gp_port_library_version(GP_VERSION_SHORT),