diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am new file mode 100644 index 000000000..70c6cfe92 --- /dev/null +++ b/bindings/python/Makefile.am @@ -0,0 +1,35 @@ +EXTRA_DIST = setup.py.in gphoto2.pyx README INSTALL gptest.py test-gp.py + +BUILT_SOURCES = gphoto2.c + +PYTHON = python + +# CAUTION: The dependencies are still a little broken. +# Better run "make clean" before "make all" and "make check". + +gphoto2.c: gphoto2.pyx + pyrexc \ + -I $(top_srcdir)/libgphoto2_port/libgphoto2_port \ + -I $(top_srcdir)/libgphoto2 \ + -I $(top_builddir)/libgphoto2 \ + -o $@ \ + $< + +clean-local: + rm -rf test-install + rm -f $(BUILT_SOURCES) + +all-local: + CFLAGS="$(AM_CPPFLAGS) $(AM_CFLAGS) $(CPPFLAGS) $(CFLAGS)" $(PYTHON) setup.py build + $(PYTHON) setup.py install -O1 --skip-build --root "$(PWD)/test-install" + +blubb-install-data-local: setup.py + @if test "x$(DESTDIR)" = "x"; then \ + echo "$(PYTHON) setup.py install -O1 --skip-build"; \ + $(PYTHON) setup.py install -O1 --skip-build; \ + else \ + echo "$(PYTHON) setup.py install -O1 --skip-build --root $(DESTDIR)"; \ + $(PYTHON) setup.py install -O1 --skip-build --root "$(DESTDIR)"; \ + fi + +TESTS = test-gp.py diff --git a/bindings/python/gphoto2.pyx b/bindings/python/gphoto2.pyx index f4ab0fff9..27aeb72bf 100644 --- a/bindings/python/gphoto2.pyx +++ b/bindings/python/gphoto2.pyx @@ -30,7 +30,7 @@ cdef extern from "time.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-port-version.h": +cdef extern from "gphoto2/gphoto2-port-version.h": ctypedef enum GPVersionVerbosity: GP_VERSION_SHORT @@ -40,12 +40,12 @@ cdef extern from "gphoto2-port-version.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-version.h": +cdef extern from "gphoto2/gphoto2-version.h": char **gp_library_version(GPVersionVerbosity verbose) #------------------------------------------------------------------------------ -cdef extern from "gphoto2-context.h": +cdef extern from "gphoto2/gphoto2-context.h": ctypedef struct GPContext GPContext *gp_context_new () @@ -91,7 +91,7 @@ cdef extern from "gphoto2-context.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-port-info-list.h": +cdef extern from "gphoto2/gphoto2-port-info-list.h": ctypedef enum GPPortType: GP_PORT_NONE GP_PORT_SERIAL @@ -121,7 +121,7 @@ cdef extern from "gphoto2-port-info-list.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-port.h": +cdef extern from "gphoto2/gphoto2-port.h": ctypedef enum GPPortSerialParity: GP_PORT_SERIAL_PARITY_OFF @@ -213,7 +213,7 @@ cdef extern from "gphoto2-port.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-port-log.h": +cdef extern from "gphoto2/gphoto2-port-log.h": ctypedef enum GPLogLevel: GP_LOG_ERROR GP_LOG_VERBOSE @@ -231,7 +231,7 @@ cdef extern from "gphoto2-port-log.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-port-result.h": +cdef extern from "gphoto2/gphoto2-port-result.h": ctypedef enum port_result: GP_OK GP_ERROR @@ -258,7 +258,7 @@ cdef extern from "gphoto2-port-result.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-port-result.h": +cdef extern from "gphoto2/gphoto2-port-result.h": ctypedef enum gphoto2_result: GP_ERROR_CORRUPTED_DATA GP_ERROR_FILE_EXISTS @@ -274,7 +274,7 @@ cdef extern from "gphoto2-port-result.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-widget.h": +cdef extern from "gphoto2/gphoto2-widget.h": ctypedef struct CameraWidget ctypedef enum CameraWidgetType: @@ -334,7 +334,7 @@ cdef extern from "gphoto2-widget.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-file.h": +cdef extern from "gphoto2/gphoto2-file.h": ctypedef enum defines_file: GP_MIME_WAV GP_MIME_RAW @@ -391,7 +391,7 @@ cdef extern from "gphoto2-file.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-list.h": +cdef extern from "gphoto2/gphoto2-list.h": ctypedef enum defines_list: MAX_ENTRIES @@ -424,7 +424,7 @@ cdef extern from "gphoto2-list.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-filesys.h": +cdef extern from "gphoto2/gphoto2-filesys.h": ctypedef enum CameraFileInfoFields: GP_FILE_INFO_NONE @@ -560,7 +560,7 @@ cdef extern from "gphoto2-filesys.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-abilities-list.h": +cdef extern from "gphoto2/gphoto2-abilities-list.h": ctypedef enum CameraDriverStatus: GP_DRIVER_STATUS_PRODUCTION GP_DRIVER_STATUS_TESTING @@ -625,21 +625,21 @@ cdef extern from "gphoto2-abilities-list.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-camera.h": - # include +cdef extern from "gphoto2/gphoto2-camera.h": + #include ctypedef struct Camera - #include - #include + #include + #include - #include - #include - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include + #include + #include ctypedef struct CameraText: char text [32 * 1024] @@ -753,7 +753,7 @@ cdef extern from "gphoto2-camera.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-library.h": +cdef extern from "gphoto2/gphoto2-library.h": ctypedef int (* CameraLibraryIdFunc) (CameraText *id) ctypedef int (* CameraLibraryAbilitiesFunc) (CameraAbilitiesList *list) ctypedef int (* CameraLibraryInitFunc) (Camera *camera, GPContext *context) @@ -763,19 +763,25 @@ cdef extern from "gphoto2-library.h": #------------------------------------------------------------------------------ -cdef extern from "gphoto2-setting.h": +cdef extern from "gphoto2/gphoto2-setting.h": int gp_setting_set (char *id, char *key, char *value) int gp_setting_get (char *id, char *key, char *value) #------------------------------------------------------------------------------ -def version(verbose=False): - cdef char **cText +def library_version(verbose): + cdef char **arrText + cdef int i + retval = [] if verbose==False: - cText=gp_library_version(GP_VERSION_SHORT) + arrText=gp_library_version(GP_VERSION_SHORT) else: - cText=gp_library_version(GP_VERSION_VERBOSE) - return cText[0] + arrText=gp_library_version(GP_VERSION_VERBOSE) + i = 0 + while arrText[i] != NULL: + retval.append(arrText[i]) + i=i+1 + return retval cdef check(result): if result!=0: @@ -792,7 +798,10 @@ cdef class portInfo: cdef GPPortInfo info def __repr__(self): - return self.info.name + if self.info.path: + return "%s: %s" % (self.info.name, self.info.path) + else: + return self.info.name cdef class ports: cdef GPPortInfoList *portInfoList @@ -841,7 +850,7 @@ cdef class cameraAbilities: pass def __repr__(self): - return "Model : %s\nStatus : %d\nPort : %d\nOperations : %d\nFile Operations : %d\nFolder Operations : %d\nUSB (vendor/product) : %d/%d\nUSB class : %d/%d/%d\nLibrary : %s\nId : %s\n" % (self.abilitie.model, self.abilitie.status, self.abilitie.port, self.abilitie.operations, self.abilitie.file_operations, self.abilitie.folder_operations, self.abilitie.usb_vendor, self.abilitie.usb_product, self.abilitie.usb_class, self.abilitie.usb_subclass, self.abilitie.usb_protocol, self.abilitie.library, self.abilitie.id) + return "Model : %s\nStatus : %d\nPort : %d\nOperations : %d\nFile Operations : %d\nFolder Operations : %d\nUSB (vendor/product) : 0x%x/0x%x\nUSB class : 0x%x/0x%x/0x%x\nLibrary : %s\nId : %s\n" % (self.abilitie.model, self.abilitie.status, self.abilitie.port, self.abilitie.operations, self.abilitie.file_operations, self.abilitie.folder_operations, self.abilitie.usb_vendor, self.abilitie.usb_product, self.abilitie.usb_class, self.abilitie.usb_subclass, self.abilitie.usb_protocol, self.abilitie.library, self.abilitie.id) property model: def __get__(self): diff --git a/bindings/python/setup.py b/bindings/python/setup.py.in similarity index 79% rename from bindings/python/setup.py rename to bindings/python/setup.py.in index d8e2d7e11..5e4cfbd99 100644 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py.in @@ -22,10 +22,19 @@ setup( name = "python-gphoto2", ext_modules=[ Extension( - "gphoto2", ["gphoto2.pyx"], - libraries = ["gphoto2"], - include_dirs = ["/usr/include/gphoto2"] + "gphoto2", + [ "gphoto2.pyx" ], + libraries = [ "gphoto2" ], + include_dirs = [ + "@top_srcdir@/libgphoto2", + "@top_builddir@/libgphoto2", + "@top_srcdir@/libgphoto2_port", + ] ) ], cmdclass = {'build_ext': build_ext} ) + +# Local Variables: +# mode: python +# End: diff --git a/bindings/python/test-gp.py b/bindings/python/test-gp.py new file mode 100755 index 000000000..9ba6efc00 --- /dev/null +++ b/bindings/python/test-gp.py @@ -0,0 +1,49 @@ +#!/usr/bin/python + +import sys +import os +from pprint import pprint +import unittest +import modulefinder + + +class TestRunner(unittest.TestCase): + + def setUp(self): + # FIXME: Find gphoto2.so file + sys.path.append(os.path.abspath('test-install/usr/lib/python2.4/site-packages')) + import gphoto2 + + def test_000_version_short(self): + import gphoto2 + #print "gphoto2 version", gphoto2.version() + + def test_010_ports(self): + import gphoto2 + self.ports = gphoto2.ports() + self.ports.load() + print self.ports.count(), " ports found:" + for port in range(0, self.ports.count()): + print self.ports[port] + + def xtest_020_cameras(self): + import gphoto2 + self.a_l = gphoto2.abilities_list() + self.a_l.load() + print self.a_l.count(), " cameras found:" + for i in range(0, self.a_l.count()): + print self.a_l[i] + + def test_030_camera(self): + import gphoto2 + print("Creating camera...") + self.cam = gphoto2.camera() + + def test_007_long(self): + import gphoto2 + pprint(gphoto2.library_version(False)) + pprint(gphoto2.library_version(True)) + + +if __name__ == '__main__': + unittest.main()